docstring formatting

This commit is contained in:
Rudi Grinberg 2012-11-05 13:29:10 -05:00
parent 78e731f717
commit ce313a5b22
1 changed files with 34 additions and 64 deletions

View File

@ -13,11 +13,10 @@ import media.monitor.pure as mmp
class ManagerTimeout(threading.Thread,Loggable): class ManagerTimeout(threading.Thread,Loggable):
""" """ The purpose of this class is to flush the organize directory
The purpose of this class is to flush the organize directory every 3 every 3 secnods. This used to be just a work around for cc-4235
secnods. This used to be just a work around for cc-4235 but recently but recently became a permanent solution because it's "cheap" and
became a permanent solution because it's "cheap" and reliable reliable """
"""
def __init__(self, manager, interval=1.5): def __init__(self, manager, interval=1.5):
# TODO : interval should be read from config and passed here instead # TODO : interval should be read from config and passed here instead
# of just using the hard coded value # of just using the hard coded value
@ -30,11 +29,9 @@ class ManagerTimeout(threading.Thread,Loggable):
self.manager.flush_organize() self.manager.flush_organize()
class Manager(Loggable): class Manager(Loggable):
""" """ An abstraction over media monitors core pyinotify functions.
An abstraction over media monitors core pyinotify functions. These These include adding watched,store, organize directories, etc.
include adding watched,store, organize directories, etc. Basically Basically composes over WatchManager from pyinotify """
composes over WatchManager from pyinotify
"""
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
@ -76,23 +73,19 @@ 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 """
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 the signal string our watch_listener is reading
Return the signal string our watch_listener is reading events from events from """
"""
return self.watch_listener.signal return self.watch_listener.signal
def __remove_watch(self,path): def __remove_watch(self,path):
""" """ Remove path from being watched (first will check if 'path'
Remove path from being watched (first will check if 'path' is watched) is watched) """
"""
# only delete if dir is actually being watched # only delete if dir is actually being watched
if path in self.__wd_path: if path in self.__wd_path:
wd = self.__wd_path[path] wd = self.__wd_path[path]
@ -100,10 +93,8 @@ class Manager(Loggable):
del(self.__wd_path[path]) del(self.__wd_path[path])
def __add_watch(self,path,listener): def __add_watch(self,path,listener):
""" """ Start watching 'path' using 'listener'. First will check if
Start watching 'path' using 'listener'. First will check if directory directory is being watched before adding another watch """
is being watched before adding another watch
"""
self.logger.info("Attempting to add listener to path '%s'" % path) self.logger.info("Attempting to add listener to path '%s'" % path)
self.logger.info( 'Listener: %s' % str(listener) ) self.logger.info( 'Listener: %s' % str(listener) )
@ -114,9 +105,8 @@ class Manager(Loggable):
if wd: self.__wd_path[path] = wd.values()[0] if wd: self.__wd_path[path] = wd.values()[0]
def __create_organizer(self, target_path, recorded_path): def __create_organizer(self, target_path, recorded_path):
""" """ creates an organizer at new destination path or modifies the
creates an organizer at new destination path or modifies the old one old one """
"""
# TODO : find a proper fix for the following hack # TODO : find a proper fix for the following hack
# We avoid creating new instances of organize because of the way # We avoid creating new instances of organize because of the way
# it interacts with pydispatch. We must be careful to never have # it interacts with pydispatch. We must be careful to never have
@ -134,23 +124,17 @@ class Manager(Loggable):
recorded_path=recorded_path) recorded_path=recorded_path)
def get_problem_files_path(self): def get_problem_files_path(self):
""" """ returns the path where problem files should go """
returns the path where problem files should go
"""
return self.organize['problem_files_path'] return self.organize['problem_files_path']
def set_problem_files_path(self, new_path): def set_problem_files_path(self, new_path):
""" """ Set the path where problem files should go """
Set the path where problem files should go
"""
self.organize['problem_files_path'] = new_path self.organize['problem_files_path'] = new_path
self.organize['problem_handler'] = \ self.organize['problem_handler'] = \
ProblemFileHandler( PathChannel(signal='badfile',path=new_path) ) ProblemFileHandler( PathChannel(signal='badfile',path=new_path) )
def get_recorded_path(self): def get_recorded_path(self):
""" """ returns the path of the recorded directory """
returns the path of the recorded directory
"""
return self.organize['recorded_path'] return self.organize['recorded_path']
def set_recorded_path(self, new_path): def set_recorded_path(self, new_path):
@ -160,17 +144,14 @@ class Manager(Loggable):
self.__add_watch(new_path, self.watch_listener) self.__add_watch(new_path, self.watch_listener)
def get_organize_path(self): def get_organize_path(self):
""" """ returns the current path that is being watched for
returns the current path that is being watched for organization organization """
"""
return self.organize['organize_path'] return self.organize['organize_path']
def set_organize_path(self, new_path): def set_organize_path(self, new_path):
""" """ sets the organize path to be new_path. Under the current
sets the organize path to be new_path. Under the current scheme there scheme there is only one organize path but there is no reason
is only one organize path but there is no reason why more cannot be why more cannot be supported """
supported
"""
# if we are already organizing a particular directory we remove the # if we are already organizing a particular directory we remove the
# watch from it first before organizing another directory # watch from it first before organizing another directory
self.__remove_watch(self.organize['organize_path']) self.__remove_watch(self.organize['organize_path'])
@ -188,19 +169,15 @@ class Manager(Loggable):
return self.organize['imported_path'] return self.organize['imported_path']
def set_imported_path(self,new_path): def set_imported_path(self,new_path):
""" """ set the directory where organized files go to. """
set the directory where organized files go to.
"""
self.__remove_watch(self.organize['imported_path']) self.__remove_watch(self.organize['imported_path'])
self.organize['imported_path'] = new_path self.organize['imported_path'] = new_path
self.__create_organizer( new_path, self.organize['recorded_path']) self.__create_organizer( new_path, self.organize['recorded_path'])
self.__add_watch(new_path, self.watch_listener) self.__add_watch(new_path, self.watch_listener)
def change_storage_root(self, store): def change_storage_root(self, store):
""" """ hooks up all the directories for you. Problem, recorded,
hooks up all the directories for you. Problem, recorded, imported, imported, organize. """
organize.
"""
store_paths = mmp.expand_storage(store) store_paths = mmp.expand_storage(store)
# First attempt to make sure that all paths exist before adding any # First attempt to make sure that all paths exist before adding any
# watches # watches
@ -217,18 +194,14 @@ class Manager(Loggable):
mmp.create_dir(p) mmp.create_dir(p)
def has_watch(self, path): def has_watch(self, path):
""" """ returns true if the path is being watched or not. Any kind
returns true if the path is being watched or not. Any kind of watch: of watch: organize, store, watched. """
organize, store, watched.
"""
return path in self.__wd_path return path in self.__wd_path
def add_watch_directory(self, new_dir): def add_watch_directory(self, new_dir):
""" """ adds a directory to be "watched". "watched" directories are
adds a directory to be "watched". "watched" directories are
those that are being monitored by media monitor for airtime in those that are being monitored by media monitor for airtime in
this context and not directories pyinotify calls watched this context and not directories pyinotify calls watched """
"""
if self.has_watch(new_dir): if self.has_watch(new_dir):
self.logger.info("Cannot add '%s' to watched directories. It's \ self.logger.info("Cannot add '%s' to watched directories. It's \
already being watched" % new_dir) already being watched" % new_dir)
@ -237,9 +210,8 @@ class Manager(Loggable):
self.__add_watch(new_dir, self.watch_listener) self.__add_watch(new_dir, self.watch_listener)
def remove_watch_directory(self, watch_dir): def remove_watch_directory(self, watch_dir):
""" """ removes a directory from being "watched". Undoes
removes a directory from being "watched". Undoes add_watch_directory add_watch_directory """
"""
if self.has_watch(watch_dir): if self.has_watch(watch_dir):
self.logger.info("Removing watched directory: '%s'", watch_dir) self.logger.info("Removing watched directory: '%s'", watch_dir)
self.__remove_watch(watch_dir) self.__remove_watch(watch_dir)
@ -250,9 +222,7 @@ class Manager(Loggable):
self.logger.info( self.__wd_path ) self.logger.info( self.__wd_path )
def loop(self): def loop(self):
""" """ block until we receive pyinotify events """
block until we receive pyinotify events
"""
notifier = pyinotify.Notifier(self.wm) notifier = pyinotify.Notifier(self.wm)
notifier.coalesce_events() notifier.coalesce_events()
notifier.loop() notifier.loop()