cc-4105: added command line option parsing

This commit is contained in:
Rudi Grinberg 2012-08-10 16:23:18 -04:00
parent ee1491a487
commit 745221f77c
4 changed files with 46 additions and 23 deletions

View File

@ -79,8 +79,8 @@ class BaseEvent(Loggable):
# nothing to see here, please move along
def morph_into(self, evt):
"""
'Morphing' should preserve the self.cookie invariant. I.e. either
None -> None or int -> int
'Morphing' should preserve the self.cookie invariant. I.e.
either should either stay an integer or stay none.
"""
self.logger.info("Morphing '%s' into '%s'" % (self.__class__.__name__,
evt.__class__.__name__))

View File

@ -10,23 +10,25 @@ from media.monitor.events import OrganizeFile, NewFile, MoveFile, DeleteFile, \
from media.monitor.log import Loggable, get_logger
# We attempt to document a list of all special cases and hacks that the
# following classes should be able to handle. TODO : implement all of the
# following special cases
# following classes should be able to handle. TODO : implement all of
# the following special cases
#
# properly as they only send a request for the dir and not for every file. Also
# more hacks are needed to check that the directory finished moving/copying?
# properly as they only send a request for the dir and not for every
# file. Also more hacks are needed to check that the directory finished
# moving/copying?
#
# - In the case when a 'watched' directory's subdirectory is delete we should
# send a special request telling ApiController to delete a whole dir. This is
# done becasue pyinotify will not send an individual file delete event for
# every file in that directory
# - In the case when a 'watched' directory's subdirectory is delete we
# should send a special request telling ApiController to delete a whole
# dir. This is done becasue pyinotify will not send an individual file
# delete event for every file in that directory
#
# - Special move events are required whenever a file is moved from a 'watched'
# directory into another 'watched' directory (or subdirectory). In this case we
# must identify the file by its md5 signature instead of it's filepath like we
# usually do. Maybe it's best to always identify a file based on its md5
# signature?. Of course that's not possible for some modification events
# because the md5 signature will change...
# - Special move events are required whenever a file is moved
# from a 'watched' directory into another 'watched' directory (or
# subdirectory). In this case we must identify the file by its md5
# signature instead of it's filepath like we usually do. Maybe it's
# best to always identify a file based on its md5 signature?. Of course
# that's not possible for some modification events because the md5
# signature will change...
# Note: Because of the way classes that inherit from pyinotify.ProcessEvent
# interact with constructors. you should only instantiate objects from them

View File

@ -0,0 +1,4 @@
#export PYTHONPATH="/home/rudi/Airtime/python_apps/:/home/rudi/Airtime/python_apps/media-monitor2/"
PYTHONPATH='/home/rudi/Airtime/python_apps/:/home/rudi/Airtime/python_apps/media-monitor2/'
export PYTHONPATH
python ./mm2.py --config="/home/rudi/Airtime/python_apps/media-monitor2/tests/live_client.cfg" --apiclient="/home/rudi/Airtime/python_apps/media-monitor2/tests/live_client.cfg" --log="/home/rudi/throwaway/mm2.log"

View File

@ -36,7 +36,6 @@ def main(global_config, api_client_config):
print(str(e))
logfile = unicode( config['logpath'] )
setup_logging(logfile)
log = get_logger()
log.info("Attempting to set the locale...")
@ -96,10 +95,28 @@ def main(global_config, api_client_config):
pyi = manager.pyinotify()
pyi.loop()
__doc__ = """
Usage:
mm2.py --config=<path> --apiclient=<path> --log=<path>
Options:
-h --help Show this screen
--config=<path> path to mm2 config
--apiclient=<path> path to apiclient config
--log=<path> log at <path>
"""
#base_path = u'/home/rudi/Airtime/python_apps/media-monitor2/tests'
#global_config = os.path.join(base_path, u'live_client.cfg')
#api_client_config = global_config
if __name__ == '__main__':
# TODO : parse these from command line arguments
# TODO : add log config stuff
base_path = u'/home/rudi/Airtime/python_apps/media-monitor2/tests'
global_config = os.path.join(base_path, u'live_client.cfg')
api_client_config = global_config
main(global_config, api_client_config)
from docopt import docopt
args = docopt(__doc__,version="mm1.99")
for k in ['--apiclient','--config']:
if not os.path.exists(args[k]):
print("'%s' must exist" % args[k])
sys.exit(0)
print("Running mm1.99")
setup_logging(args['--log'])
main(args['--config'],args['--apiclient'])