]> khamidou — GitHub mirrors - cagibi.git/commitdiff
working in progress on getting the upstream changes
authorkarim hamidou <khamidou@gmail.com>
Fri, 13 Jul 2012 08:12:28 +0000 (10:12 +0200)
committerkarim hamidou <khamidou@gmail.com>
Fri, 13 Jul 2012 08:12:28 +0000 (10:12 +0200)
cagibi/cagibi.py
cagibi/server.py

index e0de030f5d7ee338aa2e506acc03e89035eea05d..f143cf519d808737cf781fdd75268183b65a2612 100644 (file)
@@ -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")
index 37018893cf4460868e02de589e1da74920f510b8..57ea3ebca5d02fcfc2777689e213d7c78f655195 100644 (file)
@@ -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/<filename>/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()