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)
'jld.api.ErrorValidation': { 'msg': 'error_validation','help': 'help_validation', }, 'jld.api.ErrorProtocol': { 'msg': 'error_protocol', 'help': 'help_protocol', }, 'jld.api.ErrorInvalidCommand': { 'msg': 'error_command', 'help': 'help_command', }, 'jld.registry.exception.RegistryException':{ 'msg': 'error_registry', 'help_win': 'help_registry_win', 'help_nix':'help_registry_nix' }, } # ============================================== # ============================================== if __name__ == "__main__": """ Tests """ import jld.backup.mindmeister_messages as msg msgs = msg.MM_Messages() ui = MM_UI( msgs ) import jld.registry.exception as regExc e = regExc.RegistryException('test') ui.handleError( e ) class NotDefined(Exception): pass nd = NotDefined('not defined...') ui.handleError( nd ) ea = api.ErrorAuth() ui.handleError( ea )