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)