summaryrefslogtreecommitdiffstats
path: root/combox/events.py
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-01-15 17:30:51 -0500
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-01-15 17:30:51 -0500
commita26ab4f90b89119863f7eeafc0655323281a0448 (patch)
tree212775883fdf7513fc4a179a338080decc6d8dda /combox/events.py
parentd15e4f7cbf9b3eb6b7b350a45b336eb5a327f6d0 (diff)
combox/events.py: fleshed out on_moved, on_deleted functions.
The functions are not yet fully complete (See TODO in each function).
Diffstat (limited to 'combox/events.py')
-rw-r--r--combox/events.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/combox/events.py b/combox/events.py
index 3d25041..16ec409 100644
--- a/combox/events.py
+++ b/combox/events.py
@@ -24,7 +24,9 @@ from os import path
from watchdog.events import FileSystemEventHandler
from combox.crypto import split_and_encrypt
-from combox.file import mk_nodedir, relative_path
+from combox.file import (mk_nodedir, rm_nodedir, rm_shards,
+ relative_path, move_shards, move_nodedir)
+
class ComboxEventHandler(FileSystemEventHandler):
"""Monitors Combox directory for changes and does its crypto thing.
@@ -45,6 +47,16 @@ class ComboxEventHandler(FileSystemEventHandler):
def on_moved(self, event):
super(ComboxEventHandler, self).on_moved(event)
+ if event.is_directory:
+ # creates a corresponding directory at the node dirs.
+ move_nodedir(event.src_path, event.dest_path, self.config)
+ # TODO: code for updating files under the renamed
+ # directory in YAML silo.
+ else:
+ # file moved
+ move_shards(event.src_path, event.dest_path, self.config)
+ # TODO: code for updating file info in YAML silo.
+
type_ = 'directory' if event.is_directory else 'file'
logging.info("Moved %s: from %s to %s", type_, event.src_path,
event.dest_path)
@@ -59,7 +71,7 @@ class ComboxEventHandler(FileSystemEventHandler):
else:
# file was created
split_and_encrypt(event.src_path, self.config)
- # TODO: code for storing file info in YAML.
+ # TODO: code for storing file info in YAML silo.
type_ = 'directory' if event.is_directory else 'file'
logging.info("Created %s: %s", type_, event.src_path)
@@ -68,9 +80,19 @@ class ComboxEventHandler(FileSystemEventHandler):
def on_deleted(self, event):
super(ComboxEventHandler, self).on_deleted(event)
+ if event.is_directory:
+ # Delete corresponding directory in the nodes.
+ rm_nodedir(event.src_path, self.config)
+ else:
+ # remove the corresponding file shards in the node
+ # directories.
+ rm_shards(event.src_path, self.config)
+ # TODO: code for removing file info from YAML silo.
+
type_ = 'directory' if event.is_directory else 'file'
logging.info("Deleted %s: %s", type_, event.src_path)
+
def on_modified(self, event):
super(ComboxEventHandler, self).on_modified(event)