Server side commit workflow

This commit is contained in:
2014-10-30 19:23:57 +01:00
parent 4d16028d31
commit a3eb5b05a3
2 changed files with 35 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import requests import requests
import json
import os import os
MODULE_DIR = os.path.dirname(__file__) MODULE_DIR = os.path.dirname(__file__)
@@ -43,8 +44,13 @@ def request_url(path):
# params={'file': filepath} # params={'file': filepath}
# ) # )
args = {
'message' : 'Adding test file.'
}
payload = { payload = {
'command' : 'checkin', 'command' : 'commit',
'arguments' : json.dumps(args)
} }
files = {'file': open('buck.mp4', 'rb')} files = {'file': open('buck.mp4', 'rb')}

View File

@@ -18,6 +18,7 @@
# ***** END GPL LICENCE BLOCK ***** # ***** END GPL LICENCE BLOCK *****
import os import os
import json
import svn.local import svn.local
import pprint import pprint
import werkzeug import werkzeug
@@ -119,6 +120,7 @@ class FileAPI(Resource):
help="Filepath cannot be blank!") help="Filepath cannot be blank!")
parser.add_argument('command', type=str, required=True, parser.add_argument('command', type=str, required=True,
help="Command cannot be blank!") help="Command cannot be blank!")
parser.add_argument('arguments', type=str)
parser.add_argument('files', type=werkzeug.datastructures.FileStorage, parser.add_argument('files', type=werkzeug.datastructures.FileStorage,
location='files') location='files')
args = parser.parse_args() args = parser.parse_args()
@@ -158,13 +160,36 @@ class FileAPI(Resource):
def put(self): def put(self):
command = request.args['command'] command = request.args['command']
arguments = ''
if 'arguments' in request.args:
arguments = json.loads(request.args['arguments'])
file = request.files['file'] file = request.files['file']
if file and self.allowed_file(file.filename): 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) 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: else:
return jsonify(message='File not allowed') return jsonify(message='File not allowed')