def do_setup(self, arg, arguments): """ :: Usage: setup init [--force] Copies a cmd3.yaml file into ~/.cloudmesh/cmd3.yaml """ if arguments["init"]: Console.ok("Initialize cmd3.yaml file") from cmd3.yaml_setup import create_cmd3_yaml_file force = arguments["--force"] create_cmd3_yaml_file(force=force)
def do_setup(self, arg, arguments): """ :: Usage: setup init [--force] Copies a cmd3.yaml file into ~/.cloudmesh/cmd3.yaml """ if arguments["init"]: Console.ok("Initialize cmd3.yaml file") from cmd3.yaml_setup import create_cmd3_yaml_file force = arguments["--force"] create_cmd3_yaml_file(force=force)
def main(): """cm. Usage: cm [-q] help cm [-v] [-b] [--file=SCRIPT] [-i] [COMMAND ...] Arguments: COMMAND A command to be executed Options: --file=SCRIPT -f SCRIPT Executes the script -i After start keep the shell interactive, otherwise quit [default: False] -b surpress the printing of the banner [default: False] """ echo = False try: arguments = docopt(main.__doc__, help=True) # fixing the help parameter parsing if arguments['help']: arguments['COMMAND'] = ['help'] arguments['help'] = 'False' script_file = arguments['--file'] interactive = arguments['-i'] echo = arguments['-v'] if echo: pprint(arguments) except: script_file = None interactive = False arguments = {'-b': True, 'COMMAND': [' '.join(sys.argv[1:])]} plugins = [] plugins.append(dict(get_plugins_from_dir("sys", "cmd3"))) # plugins.append(dict(get_plugins_from_dir("~/.cloudmesh", "cmd3local"))) # if not os.path.exists(path_expand( "~/.cloudmesh/cmd3.yaml")): # from cmd3.plugins.shell_core import create_cmd3_yaml_file # create_cmd3_yaml_file() create_cmd3_yaml_file(force=False, verbose=False) filename = path_expand("~/.cloudmesh/cmd3.yaml") try: module_config = ConfigDict(filename=filename) modules = module_config["cmd3"]["modules"] properties = module_config["cmd3"]["properties"] except: modules = ['cloudmesh_cmd3.plugins'] for module_name in modules: #print ("INSTALL", module_name) try: plugins.append(dict(get_plugins_from_module(module_name))) except: # print "WARNING: could not find", module_name pass # sys.exit() # plugins.append(dict(get_plugins_from_dir("~/.cloudmesh", "cmd3local"))) # plugins.append(dict(get_plugins_from_dir (".", "dot"))) for plugin in plugins: sys.path.append(os.path.expanduser(plugin['dir'])) sys.path.append("../..") sys.path.append(".") sys.path.append("..") for plugin in plugins: plugin['class'] += ".plugins" # pprint(plugins) # pprint(sys.path) # sys.exit() name = "CmCli" # # not yet quite what i want, but falling back to a flatt array # (cmd, plugin_objects) = DynamicCmd(name, plugins) cmd.set_verbose(echo) cmd.activate() cmd.set_verbose(echo) cmd.set_debug(properties["debug"]) if arguments['-b']: cmd.set_banner("") if script_file is not None: cmd.do_exec(script_file) if len(arguments['COMMAND']) > 0: try: user_cmd = " ".join(arguments['COMMAND']) if echo: print(">", user_cmd) cmd.onecmd(user_cmd) except Exception, e: Console.error("") Console.error("ERROR: executing command '{0}'".format(user_cmd)) Console.error("") print (70 * "=") print(e) print (70 * "=") print(traceback.format_exc()) if interactive: cmd.cmdloop()
def main(): """cm. Usage: cm [-q] help cm [-v] [-b] [--file=SCRIPT] [-i] [COMMAND ...] Arguments: COMMAND A command to be executed Options: --file=SCRIPT -f SCRIPT Executes the script -i After start keep the shell interactive, otherwise quit [default: False] -b surpress the printing of the banner [default: False] """ echo = False try: arguments = docopt(main.__doc__, help=True) # fixing the help parameter parsing if arguments['help']: arguments['COMMAND'] = ['help'] arguments['help'] = 'False' script_file = arguments['--file'] interactive = arguments['-i'] echo = arguments['-v'] if echo: pprint(arguments) except: script_file = None interactive = False arguments = {'-b': True, 'COMMAND': [' '.join(sys.argv[1:])]} plugins = [] plugins.append(dict(get_plugins_from_dir("sys", "cmd3"))) # plugins.append(dict(get_plugins_from_dir("~/.cloudmesh", "cmd3local"))) # if not os.path.exists(path_expand( "~/.cloudmesh/cmd3.yaml")): # from cmd3.plugins.shell_core import create_cmd3_yaml_file # create_cmd3_yaml_file() create_cmd3_yaml_file(force=False, verbose=False) filename = path_expand("~/.cloudmesh/cmd3.yaml") try: module_config = ConfigDict(filename=filename) modules = module_config["cmd3"]["modules"] properties = module_config["cmd3"]["properties"] except: modules = ['cloudmesh_cmd3.plugins'] for module_name in modules: #print ("INSTALL", module_name) try: plugins.append(dict(get_plugins_from_module(module_name))) except: # print("WARNING: could not find", module_name) pass # sys.exit() # plugins.append(dict(get_plugins_from_dir("~/.cloudmesh", "cmd3local"))) # plugins.append(dict(get_plugins_from_dir (".", "dot"))) for plugin in plugins: sys.path.append(os.path.expanduser(plugin['dir'])) sys.path.append("../..") sys.path.append(".") sys.path.append("..") for plugin in plugins: plugin['class'] += ".plugins" # pprint(plugins) # pprint(sys.path) # sys.exit() name = "CmCli" # # not yet quite what i want, but falling back to a flatt array # (cmd, plugin_objects) = DynamicCmd(name, plugins) cmd.set_verbose(echo) cmd.activate() cmd.set_verbose(echo) cmd.set_debug(properties["debug"]) if arguments['-b']: cmd.set_banner("") if script_file is not None: cmd.do_exec(script_file) if len(arguments['COMMAND']) > 0: try: user_cmd = " ".join(arguments['COMMAND']) if echo: print(">", user_cmd) cmd.onecmd(user_cmd) except Exception as e: Console.error("") Console.error("ERROR: executing command '{0}'".format(user_cmd)) Console.error("") print(70 * "=") print(e) print(70 * "=") print(traceback.format_exc()) if interactive: cmd.cmdloop() elif not script_file or interactive: cmd.cmdloop()