Updates to File API
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,10 +1,13 @@
|
||||
*.pyc
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
|
||||
webservice/venv/
|
||||
docs/venv/
|
||||
docs/build/
|
||||
client/venv/
|
||||
|
||||
|
||||
client/client/config.json
|
||||
|
||||
webservice/bam/config.py
|
||||
|
||||
|
||||
|
20
client/client/__init__.py
Normal file → Executable file
20
client/client/__init__.py
Normal file → Executable file
@@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
|
||||
with open('config.json', 'r') as config:
|
||||
@@ -12,13 +14,17 @@ def request_url(path):
|
||||
#r = requests.get(request_url('/files'), params=payload, auth=('bam', 'bam'))
|
||||
#print (r.json())
|
||||
|
||||
payload = {'filepath': 'video.mp4'}
|
||||
payload = {
|
||||
'filepath': 'pro',
|
||||
'command' : 'info'}
|
||||
|
||||
r = requests.get(request_url('/file'), params=payload, auth=('bam', 'bam'), stream=True)
|
||||
local_filename = payload['filepath'].split('/')[-1]
|
||||
|
||||
with open(local_filename, 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
if chunk: # filter out keep-alive new chunks
|
||||
f.write(chunk)
|
||||
f.flush()
|
||||
print(local_filename)
|
||||
print (r.json())
|
||||
# with open(local_filename, 'wb') as f:
|
||||
# for chunk in r.iter_content(chunk_size=1024):
|
||||
# if chunk: # filter out keep-alive new chunks
|
||||
# f.write(chunk)
|
||||
# f.flush()
|
||||
# print(local_filename)
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
@@ -17,6 +18,8 @@
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import os
|
||||
import svn.local
|
||||
import pprint
|
||||
|
||||
from flask import Flask, jsonify, abort, request, make_response, url_for, Response
|
||||
from flask.views import MethodView
|
||||
@@ -96,7 +99,7 @@ class FilesListAPI(Resource):
|
||||
|
||||
|
||||
class FileAPI(Resource):
|
||||
"""Downloads a file."""
|
||||
"""Gives acces to a file."""
|
||||
|
||||
decorators = [auth.login_required]
|
||||
|
||||
@@ -104,15 +107,34 @@ class FileAPI(Resource):
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('filepath', type=str, required=True,
|
||||
help="Filepath cannot be blank!")
|
||||
parser.add_argument('command', type=str, required=True,
|
||||
help="Command cannot be blank!")
|
||||
args = parser.parse_args()
|
||||
|
||||
super(FileAPI, self).__init__()
|
||||
|
||||
def get(self):
|
||||
filepath = request.args['filepath']
|
||||
command = request.args['command']
|
||||
|
||||
if command == 'info':
|
||||
r = svn.local.LocalClient(app.config['STORAGE_PATH'])
|
||||
|
||||
log = r.log_default(None, None, 5, filepath)
|
||||
log = [l for l in log]
|
||||
|
||||
return jsonify(
|
||||
filepath=filepath,
|
||||
log=log)
|
||||
|
||||
elif command == 'checkout':
|
||||
filepath = os.path.join(app.config['STORAGE_PATH'], request.args['filepath'])
|
||||
f = open(filepath, 'rb')
|
||||
return Response(f, direct_passthrough=True)
|
||||
|
||||
else:
|
||||
return jsonify(message='Command unknown')
|
||||
|
||||
|
||||
class FileDepsAPI(Resource):
|
||||
"""Downloads a file and its deps."""
|
||||
|
@@ -5,6 +5,10 @@ Jinja2==2.7.3
|
||||
MarkupSafe==0.23
|
||||
Werkzeug==0.9.6
|
||||
aniso8601==0.83
|
||||
gnureadline==6.3.3
|
||||
ipython==2.3.0
|
||||
itsdangerous==0.24
|
||||
python-dateutil==2.2
|
||||
pytz==2014.7
|
||||
six==1.8.0
|
||||
six==1.7.2
|
||||
svn==0.3.24
|
||||
|
Reference in New Issue
Block a user