def resolve_argv(): if len(sys.argv) == 1 or (sys.argv[1] in args.available_commands(MOD)) or sys.argv[1].startswith("-"): command_plus_args = sys.argv[1:] mod = MOD default_command = DEFAULT_COMMAND else: if ":" in sys.argv[1]: alias, subcommand = sys.argv[1].split(":") else: alias, subcommand = sys.argv[1], '' try: cmd = dexy.plugin.Command.create_instance(alias) except dexy.exceptions.NoPlugin: msg = "No command '%s' available. Run `dexy help` to see list of available commands.\n" msgargs = (alias) sys.stderr.write(msg % msgargs) sys.exit(1) mod_name = cmd.__module__ mod = args.load_module(mod_name) if cmd.DEFAULT_COMMAND: default_command = cmd.DEFAULT_COMMAND else: default_command = cmd.NAMESPACE command_plus_args = [subcommand] + sys.argv[2:] return command_plus_args, mod, default_command
def run(): warnings.filterwarnings("ignore", category=DeprecationWarning) try: if len(sys.argv) == 1 or (sys.argv[1] in args.available_commands(MOD)): args.parse_and_run_command(sys.argv[1:], MOD, default_command=DEFAULT_COMMAND) else: if ":" in sys.argv[1]: command, subcommand = sys.argv[1].split(":") else: command = sys.argv[1] subcommand = "" command_class = dexy.plugin.Command.aliases.get(command) mod_name = command_class.__module__ mod = args.load_module(mod_name) if hasattr(command_class, 'DEFAULT_COMMAND'): default_command = command_class.DEFAULT_COMMAND else: default_command = command_class.NAMESPACE # TODO improve error message if not a valid command... args.parse_and_run_command([subcommand] + sys.argv[2:], mod, default_command=default_command) except dexy.exceptions.UserFeedback as e: sys.stderr.write(e.message) if not e.message.endswith("\n"): sys.stderr.write("\n") sys.exit(1)
def run(): warnings.filterwarnings("ignore",category=DeprecationWarning) try: if len(sys.argv) == 1 or (sys.argv[1] in args.available_commands(MOD)): args.parse_and_run_command(sys.argv[1:], MOD, default_command=DEFAULT_COMMAND) else: if ":" in sys.argv[1]: command, subcommand = sys.argv[1].split(":") else: command = sys.argv[1] subcommand = "" command_class = dexy.plugin.Command.aliases.get(command) mod_name = command_class.__module__ mod = args.load_module(mod_name) if hasattr(command_class, 'DEFAULT_COMMAND'): default_command = command_class.DEFAULT_COMMAND else: default_command = command_class.NAMESPACE # TODO improve error message if not a valid command... args.parse_and_run_command([subcommand] + sys.argv[2:], mod, default_command=default_command) except dexy.exceptions.UserFeedback as e: sys.stderr.write(e.message) if not e.message.endswith("\n"): sys.stderr.write("\n") sys.exit(1)
def run(): """ Method that runs the command specified on the command line. Ensures that UserFeedback exceptions are handled nicely so end users don't see tracebacks. """ logging.captureWarnings(True) if len(sys.argv) == 1 or (sys.argv[1] in args.available_commands(MOD)) or sys.argv[1].startswith("-"): args.parse_and_run_command(sys.argv[1:], MOD, default_command=DEFAULT_COMMAND) else: if ":" in sys.argv[1]: command, subcommand = sys.argv[1].split(":") else: command = sys.argv[1] subcommand = "" command_class = dexy.plugin.Command.aliases.get(command) if not command_class: args.parse_and_run_command(subcommand, dexy.commands) mod_name = command_class.__module__ mod = args.load_module(mod_name) if command_class.DEFAULT_COMMAND: default_command = command_class.DEFAULT_COMMAND else: default_command = command_class.NAMESPACE args.parse_and_run_command([subcommand] + sys.argv[2:], mod, default_command=default_command)
def resolve_plugin_cmd(raw_command_name): """ Take a command name like viewer:run and return the command method and module object. """ if ":" in raw_command_name: alias, subcommand = raw_command_name.split(":") else: alias, subcommand = raw_command_name, '' try: cmd = dexy.plugin.Command.create_instance(alias) except cashew.exceptions.NoPlugin: msg = """No command '%s' available. Run `dexy help --all` to see list of available commands.""" msgargs = (alias) sys.stderr.write(inspect.cleandoc(msg) % msgargs) sys.stderr.write(os.linesep) sys.exit(1) mod_name = cmd.__module__ cmd_mod = args.load_module(mod_name) return cmd, subcommand, cmd_mod
def resolve_plugin_cmd(raw_command_name): """ Take a command name like viewer:run and return the command method and module object. """ if ":" in raw_command_name: alias, subcommand = raw_command_name.split(":") else: alias, subcommand = raw_command_name, "" try: cmd = dexy.plugin.Command.create_instance(alias) except cashew.exceptions.NoPlugin: msg = """No command '%s' available. Run `dexy help --all` to see list of available commands.""" msgargs = alias sys.stderr.write(inspect.cleandoc(msg) % msgargs) sys.stderr.write(os.linesep) sys.exit(1) mod_name = cmd.__module__ cmd_mod = args.load_module(mod_name) return cmd, subcommand, cmd_mod
def test_load_a_module(): loaded_module = args.load_module("tests.loadme") args.parse_and_run_command(['blahblah', '-port', '200'], loaded_module)