From d1bc4fd097194471b7a8349b9d88e8b50deb8a65 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 14 Aug 2012 14:00:44 -0400 Subject: [PATCH] cc-4105: code formatting --- .../media/monitor/eventcontractor.py | 3 +- .../media-monitor2/media/monitor/log.py | 7 ++++ .../media-monitor2/media/monitor/manager.py | 32 +++++++++---------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/eventcontractor.py b/python_apps/media-monitor2/media/monitor/eventcontractor.py index 0de3d224c..639a4fbf1 100644 --- a/python_apps/media-monitor2/media/monitor/eventcontractor.py +++ b/python_apps/media-monitor2/media/monitor/eventcontractor.py @@ -40,5 +40,4 @@ class EventContractor(Loggable): return True # We actually added something, hence we return true. # events are unregistered automatically no need to screw around with them - def __unregister(self, evt): - del self.store[evt.path] + def __unregister(self, evt): del self.store[evt.path] diff --git a/python_apps/media-monitor2/media/monitor/log.py b/python_apps/media-monitor2/media/monitor/log.py index 322a6c2f4..5d632bbf4 100644 --- a/python_apps/media-monitor2/media/monitor/log.py +++ b/python_apps/media-monitor2/media/monitor/log.py @@ -6,6 +6,9 @@ from media.monitor.pure import LazyProperty appname = 'root' def setup_logging(log_path): + """ + Setup logging by writing log to 'log_path' + """ #logger = logging.getLogger(appname) logging.basicConfig(filename=log_path, level=logging.DEBUG) @@ -16,6 +19,10 @@ def get_logger(): return logging.getLogger() class Loggable(object): + """ + Any class that wants to log can inherit from this class and automatically + get a logger attribute that can be used like: self.logger.info(...) etc. + """ __metaclass__ = abc.ABCMeta @LazyProperty def logger(self): return get_logger() diff --git a/python_apps/media-monitor2/media/monitor/manager.py b/python_apps/media-monitor2/media/monitor/manager.py index 612e9983a..1988568bb 100644 --- a/python_apps/media-monitor2/media/monitor/manager.py +++ b/python_apps/media-monitor2/media/monitor/manager.py @@ -20,22 +20,18 @@ class Manager(Loggable): def __init__(self): self.wm = pyinotify.WatchManager() # These two instance variables are assumed to be constant - self.watch_channel = 'watch' + self.watch_channel = 'watch' self.organize_channel = 'organize' - self.watch_listener = StoreWatchListener(signal=self.watch_channel) + self.watch_listener = StoreWatchListener(signal = self.watch_channel) self.organize = { - 'organize_path' : None, - 'imported_path' : None, - 'recorded_path' : None, + 'organize_path' : None, + 'imported_path' : None, + 'recorded_path' : None, 'problem_files_path' : None, - # This guy doesn't need to be changed, always the same. - # Gets hooked by wm to different directories - 'organize_listener' : OrganizeListener(signal= + 'organizer' : None, + 'problem_handler' : None, + 'organize_listener' : OrganizeListener(signal= self.organize_channel), - # Also stays the same as long as its target, the directory - # which the "organized" files go to, isn't changed. - 'organizer' : None, - 'problem_handler' : None, } def dummy(sender, event): self.watch_move( event.path, sender=sender ) dispatcher.connect(dummy, signal='watch_move', sender=dispatcher.Any, @@ -54,12 +50,14 @@ class Manager(Loggable): # through dedicated handler objects. Because we must have access to a # manager instance. Hence we must slightly break encapsulation. def watch_move(self, watch_dir, sender=None): + """ + handle 'watch move' events directly sent from listener + """ self.logger.info("Watch dir '%s' has been renamed (hence removed)" % watch_dir) self.remove_watch_directory(normpath(watch_dir)) - def watch_signal(self): - return self.watch_listener.signal + def watch_signal(self): return self.watch_listener.signal def __remove_watch(self,path): # only delete if dir is actually being watched @@ -84,9 +82,9 @@ class Manager(Loggable): # easy. (The singleton hack in Organizer) doesn't work. This is # the only thing that seems to work. if self.organize['organizer']: - o = self.organize['organizer'] - o.channel = self.organize_channel - o.target_path = target_path + o = self.organize['organizer'] + o.channel = self.organize_channel + o.target_path = target_path o.recorded_path = recorded_path else: self.organize['organizer'] = Organizer(channel=