Updates to File API

This commit is contained in:
2014-10-29 19:11:29 +01:00
parent ce288d397d
commit 6e9b421af4
5 changed files with 49 additions and 14 deletions

7
.gitignore vendored
View File

@@ -1,10 +1,13 @@
*.pyc *.pyc
*.sublime-project
*.sublime-workspace
webservice/venv/ webservice/venv/
docs/venv/ docs/venv/
docs/build/ docs/build/
client/venv/ client/venv/
client/client/config.json client/client/config.json
webservice/bam/config.py webservice/bam/config.py

20
client/client/__init__.py Normal file → Executable file
View File

@@ -1,3 +1,5 @@
#!/usr/bin/env python3
import requests import requests
with open('config.json', 'r') as config: 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')) #r = requests.get(request_url('/files'), params=payload, auth=('bam', 'bam'))
#print (r.json()) #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) r = requests.get(request_url('/file'), params=payload, auth=('bam', 'bam'), stream=True)
local_filename = payload['filepath'].split('/')[-1] local_filename = payload['filepath'].split('/')[-1]
with open(local_filename, 'wb') as f: print (r.json())
for chunk in r.iter_content(chunk_size=1024): # with open(local_filename, 'wb') as f:
if chunk: # filter out keep-alive new chunks # for chunk in r.iter_content(chunk_size=1024):
f.write(chunk) # if chunk: # filter out keep-alive new chunks
f.flush() # f.write(chunk)
print(local_filename) # f.flush()
# print(local_filename)

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# ***** BEGIN GPL LICENSE BLOCK ***** # ***** BEGIN GPL LICENSE BLOCK *****
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
@@ -17,6 +18,8 @@
# ***** END GPL LICENCE BLOCK ***** # ***** END GPL LICENCE BLOCK *****
import os import os
import svn.local
import pprint
from flask import Flask, jsonify, abort, request, make_response, url_for, Response from flask import Flask, jsonify, abort, request, make_response, url_for, Response
from flask.views import MethodView from flask.views import MethodView
@@ -96,7 +99,7 @@ class FilesListAPI(Resource):
class FileAPI(Resource): class FileAPI(Resource):
"""Downloads a file.""" """Gives acces to a file."""
decorators = [auth.login_required] decorators = [auth.login_required]
@@ -104,14 +107,33 @@ class FileAPI(Resource):
parser = reqparse.RequestParser() parser = reqparse.RequestParser()
parser.add_argument('filepath', type=str, required=True, parser.add_argument('filepath', type=str, required=True,
help="Filepath cannot be blank!") help="Filepath cannot be blank!")
parser.add_argument('command', type=str, required=True,
help="Command cannot be blank!")
args = parser.parse_args() args = parser.parse_args()
super(FileAPI, self).__init__() super(FileAPI, self).__init__()
def get(self): def get(self):
filepath = os.path.join(app.config['STORAGE_PATH'], request.args['filepath']) filepath = request.args['filepath']
f = open(filepath, 'rb') command = request.args['command']
return Response(f, direct_passthrough=True)
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): class FileDepsAPI(Resource):

View File

@@ -5,6 +5,10 @@ Jinja2==2.7.3
MarkupSafe==0.23 MarkupSafe==0.23
Werkzeug==0.9.6 Werkzeug==0.9.6
aniso8601==0.83 aniso8601==0.83
gnureadline==6.3.3
ipython==2.3.0
itsdangerous==0.24 itsdangerous==0.24
python-dateutil==2.2
pytz==2014.7 pytz==2014.7
six==1.8.0 six==1.7.2
svn==0.3.24