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 # nothing to see here, please move along
def morph_into(self, evt): def morph_into(self, evt):
""" """
'Morphing' should preserve the self.cookie invariant. I.e. either 'Morphing' should preserve the self.cookie invariant. I.e.
None -> None or int -> int either should either stay an integer or stay none.
""" """
self.logger.info("Morphing '%s' into '%s'" % (self.__class__.__name__, self.logger.info("Morphing '%s' into '%s'" % (self.__class__.__name__,
evt.__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 from media.monitor.log import Loggable, get_logger
# We attempt to document a list of all special cases and hacks that the # 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 classes should be able to handle. TODO : implement all of
# following special cases # the following special cases
# #
# properly as they only send a request for the dir and not for every file. Also # properly as they only send a request for the dir and not for every
# more hacks are needed to check that the directory finished moving/copying? # 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 # - In the case when a 'watched' directory's subdirectory is delete we
# send a special request telling ApiController to delete a whole dir. This is # should send a special request telling ApiController to delete a whole
# done becasue pyinotify will not send an individual file delete event for # dir. This is done becasue pyinotify will not send an individual file
# every file in that directory # delete event for every file in that directory
# #
# - Special move events are required whenever a file is moved from a 'watched' # - Special move events are required whenever a file is moved
# directory into another 'watched' directory (or subdirectory). In this case we # from a 'watched' directory into another 'watched' directory (or
# must identify the file by its md5 signature instead of it's filepath like we # subdirectory). In this case we must identify the file by its md5
# usually do. Maybe it's best to always identify a file based on its md5 # signature instead of it's filepath like we usually do. Maybe it's
# signature?. Of course that's not possible for some modification events # best to always identify a file based on its md5 signature?. Of course
# because the md5 signature will change... # 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 # Note: Because of the way classes that inherit from pyinotify.ProcessEvent
# interact with constructors. you should only instantiate objects from them # 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)) print(str(e))
logfile = unicode( config['logpath'] ) logfile = unicode( config['logpath'] )
setup_logging(logfile)
log = get_logger() log = get_logger()
log.info("Attempting to set the locale...") log.info("Attempting to set the locale...")
@ -96,10 +95,28 @@ def main(global_config, api_client_config):
pyi = manager.pyinotify() pyi = manager.pyinotify()
pyi.loop() 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__': if __name__ == '__main__':
# TODO : parse these from command line arguments from docopt import docopt
# TODO : add log config stuff args = docopt(__doc__,version="mm1.99")
base_path = u'/home/rudi/Airtime/python_apps/media-monitor2/tests' for k in ['--apiclient','--config']:
global_config = os.path.join(base_path, u'live_client.cfg') if not os.path.exists(args[k]):
api_client_config = global_config print("'%s' must exist" % args[k])
main(global_config, api_client_config) sys.exit(0)
print("Running mm1.99")
setup_logging(args['--log'])
main(args['--config'],args['--apiclient'])