From a3eb5b05a35557b79668777a47e93ea5e12513d7 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Thu, 30 Oct 2014 19:23:57 +0100 Subject: [PATCH] Server side commit workflow --- client/client/__init__.py | 8 ++++++- webservice/bam/application/__init__.py | 31 +++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/client/client/__init__.py b/client/client/__init__.py index ebf9f1a..bcb3551 100755 --- a/client/client/__init__.py +++ b/client/client/__init__.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import requests +import json import os MODULE_DIR = os.path.dirname(__file__) @@ -43,8 +44,13 @@ def request_url(path): # params={'file': filepath} # ) +args = { + 'message' : 'Adding test file.' +} + payload = { - 'command' : 'checkin', + 'command' : 'commit', + 'arguments' : json.dumps(args) } files = {'file': open('buck.mp4', 'rb')} diff --git a/webservice/bam/application/__init__.py b/webservice/bam/application/__init__.py index 6abc652..458b3a9 100644 --- a/webservice/bam/application/__init__.py +++ b/webservice/bam/application/__init__.py @@ -18,6 +18,7 @@ # ***** END GPL LICENCE BLOCK ***** import os +import json import svn.local import pprint import werkzeug @@ -119,6 +120,7 @@ class FileAPI(Resource): help="Filepath cannot be blank!") parser.add_argument('command', type=str, required=True, help="Command cannot be blank!") + parser.add_argument('arguments', type=str) parser.add_argument('files', type=werkzeug.datastructures.FileStorage, location='files') args = parser.parse_args() @@ -155,16 +157,39 @@ class FileAPI(Resource): else: return jsonify(message='Command unknown') - + def put(self): command = request.args['command'] + arguments = '' + if 'arguments' in request.args: + arguments = json.loads(request.args['arguments']) file = request.files['file'] if file and self.allowed_file(file.filename): + local_client = svn.local.LocalClient(app.config['STORAGE_PATH']) + # TODO, add the merge operation to a queue. Later on, the request could stop here + # and all the next steps could be done in another loop, or triggered again via + # another request filename = werkzeug.secure_filename(file.filename) - file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + #file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) - return jsonify(message='Done') + # TODO, once all files are uploaded, unpack and run the tasklist (copy, add, remove + # files on a filesystem level and subsequently as svn commands) + + # TODO, dry run commit (using committ message) + # Seems not easily possible with SVN + result = local_client.run_command('status', + [local_client.info()['entry_path'], '--xml'], + combine=True) + + # Commit command + result = local_client.run_command('commit', + [local_client.info()['entry_path'], '--message', arguments['message']], + combine=True) + + print(result) + + return jsonify(message=result) else: return jsonify(message='File not allowed')