def usage(args, v): version(args, v) print(USAGE.rstrip())
def main(argv, v): # NOTE: No default for argv, because what script name would we use? description = "Control saxo irc bot instances" parser = argparse.ArgumentParser(description=description, add_help=False) parser.add_argument("-f", "--foreground", action="store_true", help="run in the foreground instead of as a daemon") parser.add_argument("-h", "--help", action="store_true", help="show a short help message") parser.add_argument("-o", "--output", metavar="filename", help="removed command: use -l / --log with no arg instead") parser.add_argument("-l", "--log", action="store_true", help="log to the standard log file") parser.add_argument("-v", "--version", action="store_true", help="show the current saxo version") parser.add_argument("action", nargs="?", help="use --help to show the available actions") parser.add_argument("directory", nargs="?", help="the path to the saxo configuration directory") args = parser.parse_args(argv[1:]) args.original = argv[1:] if args.output: print("Sorry, -o / --output has been removed!") print("Use -l / --log instead, with no arguments") sys.exit(2) if args.help: help(args, v) elif args.version: version(args, v) elif args.action: if args.action in action.names: code = action.names[args.action](args) if isinstance(code, int): sys.exit(code) elif args.action.startswith("."): # Save PEP 3122! if "." in __name__: from . import saxo else: import saxo def do(cmd, arg): import subprocess cmd = os.path.join(saxo.path, "commands", cmd) try: octets = subprocess.check_output([cmd, arg]) except Exception as err: raise err # return "Error: %s" % err return octets.decode("utf-8").rstrip("\r\n") print(do(args.action[1:], args.directory or "")) else: common.error("unrecognised action: %s" % args.action, code=2) else: usage(args, v)
def help(args, v): version(args, v) print(HELP.rstrip())
def main(argv, v): # NOTE: No default for argv, because what script name would we use? description = "Control saxo irc bot instances" parser = argparse.ArgumentParser(description=description, add_help=False) parser.add_argument("-f", "--foreground", action="store_true", help="run in the foreground instead of as a daemon") parser.add_argument("-h", "--help", action="store_true", help="show a short help message") parser.add_argument( "-o", "--output", metavar="filename", help="removed command: use -l / --log with no arg instead") parser.add_argument("-l", "--log", action="store_true", help="log to the standard log file") parser.add_argument("-v", "--version", action="store_true", help="show the current saxo version") parser.add_argument("action", nargs="?", help="use --help to show the available actions") parser.add_argument("directory", nargs="?", help="the path to the saxo configuration directory") args = parser.parse_args(argv[1:]) args.original = argv[1:] if args.output: print("Sorry, -o / --output has been removed!") print("Use -l / --log instead, with no arguments") sys.exit(2) if args.help: help(args, v) elif args.version: version(args, v) elif args.action: if args.action in action.names: code = action.names[args.action](args) if isinstance(code, int): sys.exit(code) elif args.action.startswith("."): # Save PEP 3122! if "." in __name__: from . import saxo else: import saxo def do(cmd, arg): import subprocess cmd = os.path.join(saxo.path, "commands", cmd) try: octets = subprocess.check_output([cmd, arg]) except Exception as err: raise err # return "Error: %s" % err return octets.decode("utf-8").rstrip("\r\n") print(do(args.action[1:], args.directory or "")) else: common.error("unrecognised action: %s" % args.action, code=2) else: usage(args, v)