def main(): import cli usagestr = "Usage: %prog [OPTIONS] <command> [args]" PARSER = OptionParser(usage=usagestr) PARSER.add_option("-H", "--host", dest="host", type="string", default="127.0.0.1", help="ip address of api host") PARSER.add_option("-p", "--port", dest="port", type="int", default=9696, help="api poort") PARSER.add_option("-s", "--ssl", dest="ssl", action="store_true", default=False, help="use ssl") PARSER.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False, help="turn on verbose logging") PARSER.add_option("-f", "--logfile", dest="logfile", type="string", default="syslog", help="log file path") PARSER.add_option('--version', default=DEFAULT_QUANTUM_VERSION, help='Accepts 1.1 and 1.0, defaults to env[QUANTUM_VERSION].') options, args = PARSER.parse_args() if options.verbose: LOG.setLevel(logging.DEBUG) else: LOG.setLevel(logging.WARN) if options.logfile == "syslog": LOG.addHandler(logging.handlers.SysLogHandler(address='/dev/log')) else: LOG.addHandler(logging.handlers.WatchedFileHandler(options.logfile)) os.chmod(options.logfile, 0644) version = options.version if len(args) < 1: PARSER.print_help() qcli.help(version) help() sys.exit(1) CMD = args[0] if CMD in qcli.commands.keys(): qcli.main() sys.exit(1) if CMD not in COMMANDS.keys(): LOG.error("Unknown command: %s" % CMD) qcli.help(version) help() sys.exit(1) args = build_args(CMD, COMMANDS[CMD]["args"], args[1:]) LOG.info("Executing command \"%s\" with args: %s" % (CMD, args)) HOST = options.host PORT = options.port USE_SSL = options.ssl COMMANDS[CMD]["func"](*args) LOG.info("Command execution completed") sys.exit(0)
def main(): import cli usagestr = "Usage: %prog [OPTIONS] <command> [args]" PARSER = OptionParser(usage=usagestr) PARSER.add_option("-H", "--host", dest="host", type="string", default="127.0.0.1", help="ip address of api host") PARSER.add_option("-p", "--port", dest="port", type="int", default=9696, help="api poort") PARSER.add_option("-s", "--ssl", dest="ssl", action="store_true", default=False, help="use ssl") PARSER.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False, help="turn on verbose logging") PARSER.add_option("-f", "--logfile", dest="logfile", type="string", default="syslog", help="log file path") options, args = PARSER.parse_args() if options.verbose: LOG.setLevel(logging.DEBUG) else: LOG.setLevel(logging.WARN) if options.logfile == "syslog": LOG.addHandler(logging.handlers.SysLogHandler(address='/dev/log')) else: LOG.addHandler(logging.handlers.WatchedFileHandler(options.logfile)) os.chmod(options.logfile, 0644) if len(args) < 1: PARSER.print_help() qcli.help() help() sys.exit(1) CMD = args[0] if CMD in qcli.commands.keys(): qcli.main() sys.exit(1) if CMD not in COMMANDS.keys(): LOG.error("Unknown command: %s" % CMD) qcli.help() help() sys.exit(1) args = build_args(CMD, COMMANDS[CMD]["args"], args[1:]) LOG.info("Executing command \"%s\" with args: %s" % (CMD, args)) HOST = options.host PORT = options.port USE_SSL = options.ssl COMMANDS[CMD]["func"](*args) LOG.info("Command execution completed") sys.exit(0)
if options.logfile == "syslog": LOG.addHandler(logging.handlers.SysLogHandler(address='/dev/log')) else: LOG.addHandler(logging.handlers.WatchedFileHandler(options.logfile)) os.chmod(options.logfile, 0644) if len(args) < 1: PARSER.print_help() qcli.help() help() sys.exit(1) CMD = args[0] if CMD in qcli.commands.keys(): qcli.main() sys.exit(1) if CMD not in COMMANDS.keys(): LOG.error("Unknown command: %s" % CMD) qcli.help() help() sys.exit(1) args = build_args(CMD, COMMANDS[CMD]["args"], args[1:]) LOG.info("Executing command \"%s\" with args: %s" % (CMD, args)) HOST = options.host PORT = options.port USE_SSL = options.ssl COMMANDS[CMD]["func"](*args)