summaryrefslogtreecommitdiffstats
path: root/combox/events.py
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-01-27 22:01:14 -0500
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-01-27 22:01:14 -0500
commit27e46c36acb6a8465af4c20812c8a8ed7c61d5ba (patch)
tree251e1208cf06b528e2efab0d185beeaed6d9a66b /combox/events.py
parentba9d681cde57eb053042153ff6a3855ffb57d698 (diff)
combox/events.py - Wrote first version of housingkeep() method for ComboxDirMonitor class.
The test for this method at tests/events_test.py only tests a part of it.
Diffstat (limited to 'combox/events.py')
-rw-r--r--combox/events.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/combox/events.py b/combox/events.py
index 00fba84..f4bbcc0 100644
--- a/combox/events.py
+++ b/combox/events.py
@@ -46,6 +46,58 @@ class ComboxDirMonitor(FileSystemEventHandler):
datefmt='%Y-%m-%d %H:%M:%S')
+ def housekeep(self):
+ """Recursively traverses combox directory, discovers changes and updates silo and node directories.
+
+ Information about files that have been removed from combox
+ directory is purged from the silo. Also the corresponding
+ shards are removed from the node directories.
+
+ The untracked files are encrypted and split between the node
+ directories and information about these files are stashed in
+ the silo.
+
+ Information about modified files in the combox directory are
+ updated and the file's shards are updated.
+
+ """
+ print "combox is housekeeping."
+ print "Please don't make any changes to combox directory now."
+ print "Thanks for your patience."
+
+ # Remove information about files that were deleted.
+ for fpath in self.silo.keys():
+ if not path.exists(fpath):
+ # remove this file's info from silo.
+ print fpath, "was deleted. Removing it from DB."
+ self.silo.remove(fpath)
+ # also purge the file's shards in node directories.
+ rm_shards(fpath, self.config)
+
+ # Add/update information about files that were created/modded.
+ # Also do split_and_encrypt on files that were created/modded.
+ for root, dirs, files in os.walk(self.config['combox_dir']):
+
+ for f in files:
+ fpath = path.join(root, f)
+
+ if (self.silo.exists(fpath) and
+ self.silo.stale(fpath)):
+ # file was modified
+ print fpath, "was modified. Updating DB and shards..."
+ split_and_encrypt(fpath, self.config)
+ self.silo.update(fpath)
+ elif not self.silo.exists(fpath):
+ # new file
+ print 'Adding new file', fpath, '...'
+ split_and_encrypt(fpath, self.config)
+ self.silo.update(fpath)
+
+
+ print "combox is done with the drudgery."
+ print "Do what you want to the combox directory."
+
+
def on_moved(self, event):
super(ComboxDirMonitor, self).on_moved(event)