From: karim hamidou Date: Sat, 28 Jul 2012 18:52:24 +0000 (+0200) Subject: trying to find a complex bug X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=3c6a61239618348ef8bd563567c53bae2495eb40;p=cagibi.git trying to find a complex bug --- diff --git a/cagibi/cagibi.py b/cagibi/cagibi.py index 1c4652a..d19c40c 100644 --- a/cagibi/cagibi.py +++ b/cagibi/cagibi.py @@ -36,7 +36,6 @@ def setup_filewatcher_thread(): fw = FileWatcher(path=cagibi_folder) fw.addHandler(push_filewatcher_changes) fw.watch() - print "ended" def push_filewatcher_changes(modified, added, removed): for file in added: @@ -54,27 +53,30 @@ def upload_local_changes(): while not mqueue["modified"].empty(): file = mqueue["modified"].get() print "Detect %s modified" % file - + url = "%s/files/%s/hashes" % (server_url, file) try: fd = urllib2.urlopen(url) except HTTPError: # The server may return us an error if things have gone south during # the file creation process. + # If so, mark the file as added instead of modified. + print "mark as added instead" mqueue["added"].put(file) continue hashes = json.load(fd) try: + print "%f" % os.path.getmtime(secure_path(cagibi_folder, file)) patchedfile = open(secure_path(cagibi_folder, file), "rb") deltas = encode_deltas(rsyncdelta(patchedfile, hashes)) patchedfile.close() + print "%f" % os.path.getmtime(secure_path(cagibi_folder, file)) except IOError: "IOError - continuing" continue # Send the deltas to the server. - print "deltas: %s" % deltas post_data = {} post_data["deltas"] = json.dumps(deltas) post_string = urllib.urlencode(post_data) @@ -84,6 +86,7 @@ def upload_local_changes(): local_files = load_config("files.json") local_files[file]["rev"] = results["rev"] save_config("files.json") + print "%f" % os.path.getmtime(secure_path(cagibi_folder, file)) opener = urllib2.build_opener(urllib2.HTTPHandler) @@ -139,6 +142,7 @@ def checkout_upstream_changes(): else: if server_files[file]["rev"] > local_files[file]["rev"]: # Get it too, but using the rsync algo + print "Retrieving file, using the rsync algorithm" try: unpatched = open(secure_path(cagibi_folder, file), "rb") @@ -168,6 +172,7 @@ def checkout_upstream_changes(): file_copy.write(save_to.read()) file_copy.close() local_files[file]["rev"] = server_files[file]["rev"] + modified = True except IOError: continue diff --git a/cagibi/watch.py b/cagibi/watch.py index f9a3243..a80dfdb 100644 --- a/cagibi/watch.py +++ b/cagibi/watch.py @@ -17,12 +17,12 @@ class FileWatcher: while not self.paused: elapsed_time = time.time() - time.sleep (10) + time.sleep(10) after = dict ([(f, None) for f in os.listdir (self.path)]) added = [f for f in after if not f in before] removed = [f for f in before if not f in after] modified = [f for f in after if os.path.getmtime(os.path.join(self.path, f)) > elapsed_time and f not in added] - + for handler in self.handlers: handler(modified, added, removed)