From: karim hamidou Date: Thu, 12 Jul 2012 08:44:58 +0000 (+0200) Subject: added revision info to the api X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=fd28eb0ccd22043fec593648680ba3502e21c567;p=cagibi.git added revision info to the api --- diff --git a/cagibi/server.py b/cagibi/server.py index c115bb1..6c67201 100644 --- a/cagibi/server.py +++ b/cagibi/server.py @@ -1,4 +1,4 @@ -from bottle import Bottle, route, run, post, put, delete, request, abort +from bottle import Bottle, route, run, post, get, put, delete, request, abort import os, time import json from config import load_config, save_config @@ -14,6 +14,8 @@ def filelist(): for file in os.listdir(cagibi_folder): dir[file] = {} dir[file]["mtime"] = os.path.getmtime(os.path.join(cagibi_folder, file)) + if file in files_info: + dir[file]["rev"] = files_info[file]["rev"] return json.dumps(dir) @@ -51,11 +53,19 @@ def delete_file(filename): else: abort(501, "File doesn't exist or is not in database.") +@get('/files/') +def file_info(filename): + return json.dumps(files_info[filename]) -@post('/files/') -def update_filename(filename): +@post('/files//deltas') +def return_deltas(filename): """return the deltas corresponding to the file. The client must send in its request the hashes of the file""" - return filename + hashes = json.load(request.forms.get("hashes")) + patchedfile = open(filename, "rb") + deltas = rsyncdelta(patchedfile, hashes) + patchedfile.close() + + return json.dumps(deltas) if __name__ == "__main__": files_info = load_config(filename="files.json")