summaryrefslogtreecommitdiffstats
path: root/combox/events.py
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-03-26 16:21:14 -0400
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-03-26 16:21:14 -0400
commitb4e67e3131f1b0854f7c35ef30bccb744b5c6a9b (patch)
tree810940ee5d092afd98fc443d562b2f37d6c881e2 /combox/events.py
parent53cae94179540292c9711ded5135d4f85e67ecac (diff)
fleshed out combox.events.NodDirMonitor.housekeep method.
wrote tests for it too :~( modified: combox/events.py modified: tests/events_test.py
Diffstat (limited to 'combox/events.py')
-rw-r--r--combox/events.py50
1 files changed, 49 insertions, 1 deletions
diff --git a/combox/events.py b/combox/events.py
index 12d0cbe..4b91ed5 100644
--- a/combox/events.py
+++ b/combox/events.py
@@ -23,10 +23,12 @@ from os import path
from watchdog.events import LoggingEventHandler
+from combox.config import get_nodedirs
from combox.crypto import split_and_encrypt, decrypt_and_glue
from combox.file import (mk_nodedir, rm_nodedir, rm_shards,
relative_path, move_shards, move_nodedir,
- cb_path, node_path, hash_file, rm_path)
+ cb_path, node_path, hash_file, rm_path,
+ node_paths)
from combox.silo import ComboxSilo
@@ -230,6 +232,52 @@ class NodeDirMonitor(LoggingEventHandler):
"""
self.silo_update()
+ print "combox node monitor is housekeeping."
+ print "Please don't make any changes to combox directory now."
+ print "Thanks for your patience."
+
+ # Remove files from the combox directory whose shards were
+ # deleted.
+ for fpath in self.silo.keys():
+ fshards = node_paths(fpath, self.config, True)
+
+ for fshard in fshards:
+ if not path.exists(fshard):
+ # remove the file from combox directory.
+ rm_path(fpath)
+ print fpath, "was deleted on another computer. Removing it."
+ # update silo.
+ self.silo.remove(fpath)
+ break
+
+ for root, dirs, files in os.walk(get_nodedirs(self.config)[0]):
+ for f in files:
+ shard = path.join(root, f)
+
+ if not self.shardp(shard):
+ continue
+
+ file_cb_path = cb_path(shard, self.config)
+ if not self.silo.exists(file_cb_path):
+ print file_cb_path, "was created remotely. Creating it locally now..."
+ decrypt_and_glue(file_cb_path, self.config)
+ self.silo.update(file_cb_path)
+ elif self.silo.exists(file_cb_path):
+ file_content = decrypt_and_glue(file_cb_path,
+ self.config,
+ write=False)
+ file_content_hash = hash_file(file_cb_path, file_content)
+
+ if self.silo.stale(file_cb_path, file_content_hash):
+ # file modified
+ print file_cb_path, "modified remotely. Updating local copy."
+ decrypt_and_glue(file_cb_path, self.config)
+ self.silo.update(file_cb_path)
+
+
+ print "combox node monitor is done with the drudgery."
+ print "Do what you want to the combox directory."
+
def on_moved(self, event):
super(NodeDirMonitor, self).on_moved(event)