From 6f2639fffbd72e726f904bfcaf391f1996d7324d Mon Sep 17 00:00:00 2001 From: karim hamidou Date: Fri, 13 Jul 2012 10:12:28 +0200 Subject: [PATCH] working in progress on getting the upstream changes --- cagibi/cagibi.py | 32 ++++++++++++++++++++++++++++++-- cagibi/server.py | 3 ++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/cagibi/cagibi.py b/cagibi/cagibi.py index e0de030..f143cf5 100644 --- a/cagibi/cagibi.py +++ b/cagibi/cagibi.py @@ -2,7 +2,7 @@ from watch import FileWatcher from rsync import * -from config import load_config +from config import load_config, save_config import urllib, urllib2 import json import os @@ -35,10 +35,38 @@ def checkout_upstream_changes(): url = "%s/files/%s/data" % (server_url, file) urllib.urlretrieve(url, os.path.join(cagibi_folder, file)) print "Retrieved %s" % file + modified = True + else: if server_files[file]["rev"] > local_files[file]["rev"]: # Get it too, but using the rsync algo - pass + + unpatched = open(os.path.join(cagibi_folder, file).encode('ascii', 'ignore'), "rb") + hashes = blockchecksums(unpatched) + json_hashes = json.dumps(hashes) + post_data = {} + post_data["hashes"] = json_hashes + post_string = urllib.urlencode(post_data) + + url = "%s/files/%s/deltas" % (server_url, file) + fd = urllib2.urlopen(url, post_string) + json_response = json.load(fd) + + unpatched.seek(0) + save_to = os.tmpfile() + patchstream(unpatched, save_to, json_response) + unpatched.close() + os.unlink(os.path.join(cagibi_folder, file)) + save_to.seek(0) + file_copy = open(os.path.join(cagibi_folder, file).encode('ascii', 'ignore'), "w+b") + file_copy.write(save_to.read()) + file_copy.close() + save_to.close() + + local_files[file]["rev"] = server_files[file]["rev"] + + if modified == True: + save_config(local_files, filename="files.json") if __name__ == "__main__": client_config = load_config("cagibi.json") diff --git a/cagibi/server.py b/cagibi/server.py index 3701889..57ea3eb 100644 --- a/cagibi/server.py +++ b/cagibi/server.py @@ -2,6 +2,7 @@ from bottle import Bottle, route, run, post, get, put, delete, request, abort, s import os, time import json from config import load_config, save_config +from rsync import rsyncdelta, blockchecksums, patchstream cagibi_folder = "." server_config = {} @@ -65,7 +66,7 @@ def file_data(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""" - hashes = json.load(request.forms.get("hashes")) + hashes = json.loads(request.forms.get("hashes")) patchedfile = open(os.path.join(cagibi_folder, filename), "rb") deltas = rsyncdelta(patchedfile, hashes) patchedfile.close() -- 2.43.0