From 6e9b421af431943fe90f0acf9a77992f1f8e68c7 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Wed, 29 Oct 2014 19:11:29 +0100 Subject: [PATCH] Updates to File API --- .gitignore | 7 ++++-- client/client/__init__.py | 20 +++++++++++------ {gui => client/gui}/browser.py | 0 webservice/bam/application/__init__.py | 30 ++++++++++++++++++++++---- webservice/requirements.txt | 6 +++++- 5 files changed, 49 insertions(+), 14 deletions(-) mode change 100644 => 100755 client/client/__init__.py rename {gui => client/gui}/browser.py (100%) diff --git a/.gitignore b/.gitignore index 5af9a44..20fa823 100644 --- a/.gitignore +++ b/.gitignore @@ -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 + + diff --git a/client/client/__init__.py b/client/client/__init__.py old mode 100644 new mode 100755 index 2770ebb..f2e5350 --- a/client/client/__init__.py +++ b/client/client/__init__.py @@ -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) diff --git a/gui/browser.py b/client/gui/browser.py similarity index 100% rename from gui/browser.py rename to client/gui/browser.py diff --git a/webservice/bam/application/__init__.py b/webservice/bam/application/__init__.py index 848f627..2365675 100644 --- a/webservice/bam/application/__init__.py +++ b/webservice/bam/application/__init__.py @@ -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): diff --git a/webservice/requirements.txt b/webservice/requirements.txt index b85fb9b..c2d541e 100644 --- a/webservice/requirements.txt +++ b/webservice/requirements.txt @@ -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