diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-01-27 22:01:14 -0500 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-01-27 22:01:14 -0500 |
commit | 27e46c36acb6a8465af4c20812c8a8ed7c61d5ba (patch) | |
tree | 251e1208cf06b528e2efab0d185beeaed6d9a66b /combox | |
parent | ba9d681cde57eb053042153ff6a3855ffb57d698 (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')
-rw-r--r-- | combox/events.py | 52 |
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) |