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
*.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
View 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)

View File

@@ -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,14 +107,33 @@ 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 = os.path.join(app.config['STORAGE_PATH'], request.args['filepath'])
f = open(filepath, 'rb')
return Response(f, direct_passthrough=True)
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):

View File

@@ -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