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

@ -28,14 +28,10 @@ class Manager(Loggable):
'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.
# Gets hooked by wm to different directories
'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, 'organizer' : None,
'problem_handler' : None, 'problem_handler' : None,
'organize_listener' : OrganizeListener(signal=
self.organize_channel),
} }
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