def main(): """ Entry point - Performs command line processing -- start: verifies required configuration -- stop: finds process, sends TERM -- restart: performs stop, performs start """ msgs = mmdMessages() ui = mmdUI() # == Config UI == # =============== ui.setParams( msgs ) try: daemon = mmdDaemon() cmd = mmdCmd(daemon, msgs) usage_template = """%prog [options] command version $Id: mmd.py 729 2008-12-11 18:30:12Z jeanlou.dupont $ by Jean-Lou Dupont *** Interface to MindMeister (http://www.mindmeister.com/) *** Commands: ^^{commands}""" commands_help = cmd.genCommandsHelp() tpl = ExTemplate( usage_template ) usage = tpl.substitute( {'commands' : commands_help} ) _options =[ #{'o1':'-s', 'var':'secret', 'action':'store', 'help':'config_secret', 'reg': True, 'default': None}, #{'o1':'-k', 'var':'api_key','action':'store', 'help':'config_key', 'reg': True, 'default': None}, #{'o1':'-f', 'var':'file', 'action':'store', 'help':'config_file', 'reg': True, 'default': None}, {'o1':'-q', 'var':'quiet', 'action':'store_true', 'help':'quiet', 'reg': False, 'default': False }, ] ui.handleArguments(usage, _options) # == command validation == # ======================== try: command = ui.args[0] except: command = None cmd.validateCommand(command) # get rid of command from the arg list ui.popArg() # Configuration cmd cmd.quiet = getattr( ui.options, 'quiet' ) # == DISPATCHER == # ================ getattr( cmd, "cmd_%s" % command )(ui.args) except Exception,e: ui.handleError(e)
def main(): msgs = Ymsg(__file__) defaults = Yattr(__file__) # == Config UI == # =============== ui = BaseCmdUI(msgs) # all the exceptions are handled by 'ui' try: cmd = TransmissionCmd() cmd.msgs = msgs usage_template = """%prog [options] command version $Id: trns.py 894 2009-03-25 00:56:18Z JeanLou.Dupont $ by Jean-Lou Dupont *** Interface to Transmission (Bittorent client) *** Provides the capability to verify the status of each active torrent, export its status upon completion (useful for post-processing) and automatically stopping a torrent after completion. Commands: ^^{commands}""" tpl = ExTemplate(usage_template) usage = tpl.substitute({"commands": cmd.commands_help}) # Use OptParse to process arguments ui.handleArguments(usage, _options) # Configure ourselves a logger _syslog = ui.options.config_syslog logger = _logger.logger("trns", include_console=False, include_syslog=_syslog) cmd.logger = logger ui.logger = logger # == configuration == # # Process options from the command line: # If an option is missing from the command line, look for it # in the registry.Use conditional 'setKey' if we have valid # overriding values (i.e. not None) to update the registry. # Finally, for missing parameters, look for defaults. # # PRECEDENCE: # 1) Command Line # 2) Registry # 3) Defaults # =================== r = reg.Registry("trns") ui.updateRegistry(r, _options, ui.options) params = {} # integrate options which aren't subjected to the registry ui.integrateOptions(ui.options, params, _options) # integrate default config ui.integrateDefaults(defaults, r, _options, params) # Verify parameter type ui.verifyType(params, _options) # Configure Backup cmd object ui.copyOptions(params, cmd, _options) # == command validation == # ======================== if ui.command is None: sys.exit(0) cmd.validateCommand(ui.command) # get rid of command from the arg list ui.popArg() # == DISPATCHER == # ================ getattr(cmd, "cmd_%s" % ui.command)(ui.args) except Exception, e: ui.handleError(e) return 1
def main(): try: msgs = Ymsg(__file__) except: print "default 'messages.yaml' file corrupted" sys.exit(1) # == defaults == # ============== defaults = {'default_configfile':config.path} # == Config UI == # =============== ui = BaseCmdUI(msgs) # all the exceptions are handled by 'ui' try: cmd = HomeMonCmd() cmd.msgs = msgs usage_template = """%prog [options] command version $Id: homemon.py 894 2009-03-25 00:56:18Z JeanLou.Dupont $ by Jean-Lou Dupont *** Home Monitoring *** Commands: ^^{commands}""" tpl = ExTemplate( usage_template ) usage = tpl.substitute( {'commands' : cmd.commands_help} ) # Use OptParse to process arguments ui.handleArguments(usage, _options, help_params=defaults) # Configure ourselves a logger logger = _logger.logger('homemon', include_console = True, include_syslog = False ) cmd.logger = logger ui.logger = logger # == configuration == cmd.config_configfile = ui.getOption('config_configfile') # == command validation == # ======================== if ui.command is None: sys.exit(0) cmd.validateCommand(ui.command) # inject a daemon instance cmd.daemon = HomeMonDaemon() # get rid of command from the arg list ui.popArg() # == DISPATCHER == # ================ getattr( cmd, "cmd_%s" % ui.command )(ui.args) except Exception,e: ui.handleError( e ) sys.exit(1)
def main(): msgs = msg.Gliffy_Messages() ui = dui.Gliffy_UI() # == Config UI == # =============== ui.setParams( msgs ) # all the exceptions are handled by 'ui' try: backup = Backup() usage_template = """%prog [options] command version $Id: gliffy.py 894 2009-03-25 00:56:18Z JeanLou.Dupont $ by Jean-Lou Dupont *** Backup utility for Gliffy diagrams (http://www.gliffy.com/) *** Usage Notes: 1- This command line utility is meant to complement the cousin 'dlc' command line 2- The command 'import' is used to import bookmarks from the dlc (Delicious) database The command 'import' is to be used with a parameter that denotes the 'tag' used to bookmark the Gliffy diagrams. E.g. glf import my-diagrams Will import from the dlc database all the bookmarks tagged with 'my-diagrams'. 3- The command 'export' is used to retrieve the diagrams from Gliffy. The commands which generate log entries are flagged with (logged) below. Commands: ^^{commands}""" commands_help = backup.genCommandsHelp() tpl = ExTemplate( usage_template ) usage = tpl.substitute( {'commands' : commands_help} ) # Use OptParse to process arguments ui.handleArguments(usage, _options) # Configure ourselves a logger _syslog = False if ui.options.syslog else True logger = dlogger.logger('glf', include_console = False, include_syslog = _syslog ) backup.logger = logger ui.logger = logger # == configuration == # # Process options from the command line: # If an option is missing from the command line, look for it # in the registry.Use conditional 'setKey' if we have valid # overriding values (i.e. not None) to update the registry. # Finally, for missing parameters, look for defaults. # # PRECEDENCE: # 1) Command Line # 2) Registry # 3) Defaults # =================== r = reg.Registry('gliffy') ui.updateRegistry(r, _options, ui.options) params = {} # integrate options which aren't subjected to the registry ui.integrateOptions(ui.options, params, _options) # integrate default config defs = ddef.Gliffy_Defaults() ui.integrateDefaults(defs, r, _options, params) # Verify parameter type ui.verifyType(params, _options) # Configure Backup cmd object ui.copyOptions(params, backup, _options) # == command validation == # ======================== try: command = ui.args[0] except: command = None if command is None: sys.exit(0) backup.validateCommand(command) # get rid of command from the arg list ui.popArg() # == DISPATCHER == # ================ getattr( backup, "cmd_%s" % command )(ui.args) except Exception,e: ui.handleError( e ) return 1
def main(): msgs = msg.Delicious_Messages() ui = dui.Delicious_UI() # == Config UI == # =============== ui.setParams( msgs ) # all the exceptions are handled by 'ui' try: backup = Backup() usage_template = """%prog [options] command version $Id: delicious.py 894 2009-03-25 00:56:18Z JeanLou.Dupont $ by Jean-Lou Dupont *** Interface to Delicious (http://www.delicious.com/) *** Usage notes: 1- for high-rate updates, use the ''updatedb'' command 2- for low-rate updates, use the ''updatedbfull'' command. The ''low-rate updates'' should be used no more than once per hour in order to respect the Delicious policy. The commands which generate log entries are flagged with (logged) below. Commands: ^^{commands}""" commands_help = backup.genCommandsHelp() tpl = ExTemplate( usage_template ) usage = tpl.substitute( {'commands' : commands_help} ) # Use OptParse to process arguments ui.handleArguments(usage, _options) # Configure ourselves a logger _syslog = False if ui.options.syslog else True logger = dlogger.logger('dlc', include_console = False, include_syslog = _syslog ) backup.logger = logger ui.logger = logger # == configuration == # # Process options from the command line: # If an option is missing from the command line, look for it # in the registry.Use conditional 'setKey' if we have valid # overriding values (i.e. not None) to update the registry. # Finally, for missing parameters, look for defaults. # # PRECEDENCE: # 1) Command Line # 2) Registry # 3) Defaults # =================== r = reg.Registry('delicious') ui.updateRegistry(r, _options, ui.options) params = {} # integrate options which aren't subjected to the registry ui.integrateOptions(ui.options, params, _options) # integrate default config defs = ddef.Delicious_Defaults() ui.integrateDefaults(defs, r, _options, params) # Verify parameter type ui.verifyType(params, _options) # Configure Backup cmd object ui.copyOptions(params, backup, _options) # == command validation == # ======================== try: command = ui.args[0] except: command = None if command is None: sys.exit(0) backup.validateCommand(command) # get rid of command from the arg list ui.popArg() # == DISPATCHER == # ================ getattr( backup, "cmd_%s" % command )(ui.args) except Exception,e: ui.handleError( e ) return 1
def main(): msgs = msg.MM_Messages() ui = mui.MM_UI() # == Config UI == # =============== ui.setParams(msgs) # all the exceptions are handled by 'ui' try: backup = Backup() usage_template = """%prog [options] command version $Id: mm.py 894 2009-03-25 00:56:18Z JeanLou.Dupont $ by Jean-Lou Dupont *** Interface to MindMeister (http://www.mindmeister.com/) *** This command-line utility requires valid 'API_KEY' and 'SECRET' parameters obtained from MindMeister. In order to use this tool, the 'auth' command must first be called with the said valid parameters. Usage: Step 1) Authentication: use the 'auth' command with the '-s' and '-k' parameters Step 2) Update local database: use the 'updatedb' command to retrieve/update the local map database Step 3) Export: use the 'export' command to retrieve new maps / update existing ones The commands which generate log entries are flagged with (logged) below. Commands: ^^{commands}""" commands_help = backup.genCommandsHelp() tpl = ExTemplate(usage_template) usage = tpl.substitute({"commands": commands_help}) # Use OptParse to process arguments ui.handleArguments(usage, _options) # Configure ourselves a logger _syslog = False if ui.options.syslog else True logger = mlogger.logger("mm", include_console=False, include_syslog=_syslog) backup.logger = logger ui.logger = logger # == configuration == # # Process options from the command line: # If an option is missing from the command line, look for it # in the registry.Use conditional 'setKey' if we have valid # overriding values (i.e. not None) to update the registry. # Finally, for missing parameters, look for defaults. # # PRECEDENCE: # 1) Command Line # 2) Registry # 3) Defaults # =================== r = reg.Registry("mindmeister") ui.updateRegistry(r, _options, ui.options) params = {} # integrate options which aren't subjected to the registry ui.integrateOptions(ui.options, params, _options) # integrate default config defs = mdef.MM_Defaults() ui.integrateDefaults(defs, r, _options, params) # Verify parameter type ui.verifyType(params, _options) # Configure Backup cmd object ui.copyOptions(params, backup, _options) # == command validation == # ======================== try: command = ui.args[0] except: command = None if command is None: sys.exit(0) backup.validateCommand(command) # get rid of command from the arg list ui.popArg() # == DISPATCHER == # ================ getattr(backup, "cmd_%s" % command)(ui.args) except Exception, e: ui.handleError(e) return 1