cc-4105: code formatting

This commit is contained in:
Rudi Grinberg 2012-08-14 14:00:44 -04:00
parent a2333309a7
commit d1bc4fd097
3 changed files with 23 additions and 19 deletions

View file

@ -40,5 +40,4 @@ class EventContractor(Loggable):
return True # We actually added something, hence we return true. return True # We actually added something, hence we return true.
# events are unregistered automatically no need to screw around with them # events are unregistered automatically no need to screw around with them
def __unregister(self, evt): def __unregister(self, evt): del self.store[evt.path]
del self.store[evt.path]

View file

@ -6,6 +6,9 @@ from media.monitor.pure import LazyProperty
appname = 'root' appname = 'root'
def setup_logging(log_path): def setup_logging(log_path):
"""
Setup logging by writing log to 'log_path'
"""
#logger = logging.getLogger(appname) #logger = logging.getLogger(appname)
logging.basicConfig(filename=log_path, level=logging.DEBUG) logging.basicConfig(filename=log_path, level=logging.DEBUG)
@ -16,6 +19,10 @@ def get_logger():
return logging.getLogger() return logging.getLogger()
class Loggable(object): 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 __metaclass__ = abc.ABCMeta
@LazyProperty @LazyProperty
def logger(self): return get_logger() def logger(self): return get_logger()

View file

@ -20,22 +20,18 @@ class Manager(Loggable):
def __init__(self): def __init__(self):
self.wm = pyinotify.WatchManager() self.wm = pyinotify.WatchManager()
# These two instance variables are assumed to be constant # These two instance variables are assumed to be constant
self.watch_channel = 'watch' self.watch_channel = 'watch'
self.organize_channel = 'organize' self.organize_channel = 'organize'
self.watch_listener = StoreWatchListener(signal=self.watch_channel) self.watch_listener = StoreWatchListener(signal = self.watch_channel)
self.organize = { self.organize = {
'organize_path' : None, 'organize_path' : None,
'imported_path' : None, 'imported_path' : None,
'recorded_path' : None, 'recorded_path' : None,
'problem_files_path' : None, 'problem_files_path' : None,
# This guy doesn't need to be changed, always the same. 'organizer' : None,
# Gets hooked by wm to different directories 'problem_handler' : None,
'organize_listener' : OrganizeListener(signal= 'organize_listener' : OrganizeListener(signal=
self.organize_channel), 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 ) def dummy(sender, event): self.watch_move( event.path, sender=sender )
dispatcher.connect(dummy, signal='watch_move', sender=dispatcher.Any, 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 # through dedicated handler objects. Because we must have access to a
# manager instance. Hence we must slightly break encapsulation. # manager instance. Hence we must slightly break encapsulation.
def watch_move(self, watch_dir, sender=None): 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)" % self.logger.info("Watch dir '%s' has been renamed (hence removed)" %
watch_dir) watch_dir)
self.remove_watch_directory(normpath(watch_dir)) self.remove_watch_directory(normpath(watch_dir))
def watch_signal(self): def watch_signal(self): return self.watch_listener.signal
return self.watch_listener.signal
def __remove_watch(self,path): def __remove_watch(self,path):
# only delete if dir is actually being watched # 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 # easy. (The singleton hack in Organizer) doesn't work. This is
# the only thing that seems to work. # the only thing that seems to work.
if self.organize['organizer']: if self.organize['organizer']:
o = self.organize['organizer'] o = self.organize['organizer']
o.channel = self.organize_channel o.channel = self.organize_channel
o.target_path = target_path o.target_path = target_path
o.recorded_path = recorded_path o.recorded_path = recorded_path
else: else:
self.organize['organizer'] = Organizer(channel= self.organize['organizer'] = Organizer(channel=