]> khamidou — GitHub mirrors - cagibi.git/commitdiff
config file changes
authorkarim hamidou <khamidou@gmail.com>
Thu, 12 Jul 2012 10:41:50 +0000 (12:41 +0200)
committerkarim hamidou <khamidou@gmail.com>
Thu, 12 Jul 2012 10:41:50 +0000 (12:41 +0200)
cagibi/cagibi.py
cagibi/server.py

index 54078d47e0e7562511404e66aa5e2b14f1f36c72..c8826478b5ed1a7314a54984baabc098bc4c9765 100644 (file)
@@ -2,6 +2,9 @@
 
 from watch import FileWatcher
 from rsync import *
+from config import load_config
+
+client_config = {}
 
 def changesHandler(modified, added, removed):
     for file in modified:
@@ -10,6 +13,7 @@ def changesHandler(modified, added, removed):
         print hashes
 
 if __name__ == "__main__":
+    client_config = load_config("cagibi.json")
     fw = FileWatcher()
     fw.addHandler(changesHandler)
     fw.watch()
index 6c6720157dd08b290a3c1092af9706e4ec471344..d2c48a0f964ac9667494159cd4ce414792357554 100644 (file)
@@ -4,6 +4,7 @@ import json
 from config import load_config, save_config
 
 cagibi_folder = "."
+server_config = {}
 files_info = {}
 
 @route('/folder')
@@ -30,7 +31,7 @@ def create_file(filename):
     
     # FIXME: possible race condition
     if not os.path.exists(filename) and filename not in files_info:
-        fd = open(filename, "wb")
+        fd = open(os.path.join(cagibi_folder, filename), "wb")
         fd.write(contents)
         fd.close()
         files_info[filename] = {"rev": 1}
@@ -46,7 +47,7 @@ def delete_file(filename):
     
     # FIXME: possible race condition
     if os.path.exists(filename) and filename in files_info:
-        os.remove(filename)
+        os.remove(os.path.join(cagibi_folder, filename))
         del files_info[filename]
         save_config(files_info, filename="files.json")
         return "Ok."
@@ -61,12 +62,16 @@ def file_info(filename):
 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"))
-    patchedfile = open(filename, "rb")
+    patchedfile = open(os.path.join(cagibi_folder, filename), "rb")
     deltas = rsyncdelta(patchedfile, hashes)
     patchedfile.close()
 
     return json.dumps(deltas)
 
 if __name__ == "__main__":
+    server_config = load_config("cagibi_server.json")
+    if "folder" in server_config:
+        cagibi_folder = server_config["folder"]
+
     files_info = load_config(filename="files.json")
     run(host='localhost', port=8080)