Example #1
0
def main():
  """
  
  """

  try:
    opts, args = getopt.getopt(sys.argv[1:],
                                "hif:",
                                ["help", "interactive", "file="])
  except getopt.GetoptError:
    usage()
    sys.exit(2)
  script_file = None
  interactive = False
  for option, argument in opts:
    if option in ("-h", "--help"):
      usage()
      sys.exit()
    if option in ("-f", "--file"):
      script_file = argument
    if option in ("-i", "--interactive"):
      interactive = True

  plugin_path = os.path.join(os.path.dirname(__file__),'plugins')

  plugins = get_plugins(plugin_path)

  name    = "CmCli"
  
  (cmd, plugin_objects) = DynamicCmd(name, plugins)
  cmd.version()
  cmd.activate()
  cmd.do_exec(script_file)

  if is_subcmd(opts, args):
    try:
      user_cmd = " ".join(args)
      print ">", user_cmd
      cmd.onecmd(user_cmd)
    except:
      print "'%s' is not recognized" % user_cmd
  elif not script_file or interactive:
    cmd.cmdloop()
Example #2
0
def main():
    """cm.

    Usage:
      cm --help
      cm [--echo] [--debug] [--nosplash] [-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]
      --nosplash    do not show the banner [default: False]
    """

    def manual():
        print(main.__doc__)

    args = sys.argv[1:]

    arguments = {
        '--echo': '--echo' in args,
        '--help': '--help' in args,
        '--debug': '--debug' in args,
        '--nosplash': '--nosplash' in args,
        '-i': '-i' in args}

    echo = arguments["--echo"]
    if arguments['--help']:
        manual()
        sys.exit()

    for a in args:
        if a in arguments:
            args.remove(a)

    arguments['COMMAND'] = [' '.join(args)]

    commands = arguments["COMMAND"]
    if len(commands) > 0:
        if ".cm" in commands[0]:
            arguments["SCRIPT"] = commands[0]
            commands = commands[1:]
        else:
            arguments["SCRIPT"] = None

        arguments["COMMAND"] = ' '.join(commands)
        if arguments["COMMAND"] == '':
            arguments["COMMAND"] = None

    # noinspection PySimplifyBooleanCheck
    if arguments['COMMAND'] == []:
        arguments['COMMAND'] = None

    splash = not arguments['--nosplash']
    debug = arguments['--debug']
    interactive = arguments['-i']
    script = arguments["SCRIPT"]
    command = arguments["COMMAND"]

    context = CloudmeshContext(
        interactive=interactive,
        debug=debug,
        echo=echo,
        splash=splash)
    cmd = CloudmeshConsole(context)

    if script is not None:
        cmd.do_exec(script)

    try:
        if echo:
            print("cm>", command)
        if command is not None:
            cmd.precmd(command)
            stop = cmd.onecmd(command)
            cmd.postcmd(stop, command)
    except Exception as e:
        print("ERROR: executing command '{0}'".format(command))
        print(70 * "=")
        print(e)
        print(70 * "=")
        Error.traceback()

    if interactive or (command is None and script is None):
        cmd.cmdloop()
Example #3
0
File: cm.py Project: atavism/client
def main():
    """cm.

    Usage:
      cm --help
      cm [--debug] [--nosplash] [--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]
      --nosplash    do not show the banner [default: False]
    """

    try:
        arg = docopt(main.__doc__, help=True)
        if arg['--help']:
            print(main.__doc__)
            sys.exit()

        # fixing the help parameter parsing

        #   arguments['COMMAND'] = ['help']
        #   arguments['help'] = 'False'

        script_file = arg['--file']

    except:
        script_file = None
        interactive = False

        arguments = sys.argv[1:]
        arg = {
            '--debug': '--debug' in arguments,
            '--nosplash': '--nosplash' in arguments,
            '-i': '-i' in arguments}

        for a in arg:
            if arg[a]:
                arguments.remove(a)

        arg['COMMAND'] = [' '.join(arguments)]

    splash = not arg['--nosplash']
    debug = arg['--debug']
    interactive = arg['-i']

    context = CloudmeshContext(debug=debug,
                               splash=splash)
    cmd = CloudmeshConsole(context)

    # TODO: check if cludmesh_yaml exists and if not create it
    # also creat .cloudmesh dir if it not exists
    """
    from cloudmesh_client.common import cloudmesh_yaml

    create_cmd3_yaml_file(force=False, verbose=False)

    filename = cloudmesh_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

    """

    if len(arg['COMMAND']) == 1:
        command = arg['COMMAND'][0]
        print(command)
        if command.endswith(".cm"):
            script_file = command

    if script_file is not None:
        cmd.do_exec(script_file)

    if len(arg['COMMAND']) > 0:
        user_cmd = None
        try:
            user_cmd = " ".join(arg['COMMAND'])
            if debug:
                print(">", user_cmd)
            cmd.onecmd(user_cmd)
        except Exception, e:
            print("ERROR: executing command '{0}'".format(user_cmd))
            print(70 * "=")
            print(e)
            print(70 * "=")
            print(traceback.format_exc())

        if interactive:
            cmd.cmdloop()
Example #4
0
def main():
    """cm.

    Usage:
      cm [--file=SCRIPT] [--interactive] [--quiet] [COMMAND ...]
      cm [-f SCRIPT] [-i] [-q] [COMMAND ...]

    Arguments:
      COMMAND                  A command to be executed

    Options:
      --file=SCRIPT -f SCRIPT  Executes the scipt
      --interactive -i         After start keep the shell interactive, otherwise quit
      --quiet       -q         Surpress some of the informational messages.
    """

    #    __version__ = pkg_resources.require("cmd3")[0].version
    #arguments = docopt(main.__doc__, help=True, version=__version__)

    arguments = docopt(main.__doc__, help=True)

    script_file = arguments['--file']
    interactive = arguments['--interactive']
    quiet = arguments['--quiet']

    def get_plugins_from_dir(dir_path, classbase):
        """dir_path/classbase/plugins"""

        if dir_path == "sys":
            dir_path = os.path.abspath(
                os.path.join(os.path.dirname(__file__), 'plugins'))
            dir_plugins = get_plugins(dir_path)
            return {"dir": dir_path, "plugins": dir_plugins, "class": classbase}

        if dir_path == ".":
            dir_path = os.path.expanduser(
                os.path.expandvars(os.path.join(os.getcwd(), 'plugins')))
            dir_plugins = get_plugins(dir_path)
            return {"dir": dir_path, "plugins": dir_plugins, "class": classbase}
        else:

            dir_path = os.path.expanduser(os.path.expandvars(dir_path))
            prefix = "{0}/{1}".format(dir_path, classbase)

            user_path = "{0}/plugins".format(prefix)

            create_dir(user_path)
            create_file("{0}/__init__.py".format(prefix))
            create_file("{0}/plugins/__init__.py".format(prefix))
            sys.path.append(os.path.expanduser(dir_path))
            dir_plugins = get_plugins(user_path)
            return {"dir": dir_path, "plugins": dir_plugins, "class": classbase}

    plugins = []
    plugins.append(dict(get_plugins_from_dir("sys", "cmd3")))
    plugins.append(dict(get_plugins_from_dir("~/.futuregrid", "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'] = 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.version()
    # cmd.set_verbose(quiet)
    cmd.activate()
    cmd.do_exec(script_file)

    if len(arguments['COMMAND']) > 0:
        try:
            user_cmd = " ".join(arguments['COMMAND'])
            print ">", user_cmd
            cmd.onecmd(user_cmd)
        except:
            print "'%s' is not recognized" % user_cmd
    elif not script_file or interactive:
        cmd.cmdloop()
Example #5
0
def main():
    """cm.

    Usage:
      cm --help
      cm [--echo] [--debug] [--nosplash] [-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]
      --nosplash    do not show the banner [default: False]
    """
    def manual():
        print(main.__doc__)

    args = sys.argv[1:]

    arguments = {
        '--echo': '--echo' in args,
        '--help': '--help' in args,
        '--debug': '--debug' in args,
        '--nosplash': '--nosplash' in args,
        '-i': '-i' in args
    }

    echo = arguments["--echo"]
    if arguments['--help']:
        manual()
        sys.exit()

    for a in args:
        if a in arguments:
            args.remove(a)

    arguments['COMMAND'] = [' '.join(args)]

    commands = arguments["COMMAND"]
    if len(commands) > 0:
        if ".cm" in commands[0]:
            arguments["SCRIPT"] = commands[0]
            commands = commands[1:]
        else:
            arguments["SCRIPT"] = None

        arguments["COMMAND"] = ' '.join(commands)
        if arguments["COMMAND"] == '':
            arguments["COMMAND"] = None

    # noinspection PySimplifyBooleanCheck
    if arguments['COMMAND'] == []:
        arguments['COMMAND'] = None

    splash = not arguments['--nosplash']
    debug = arguments['--debug']
    interactive = arguments['-i']
    script = arguments["SCRIPT"]
    command = arguments["COMMAND"]

    context = CloudmeshContext(interactive=interactive,
                               debug=debug,
                               echo=echo,
                               splash=splash)
    cmd = CloudmeshConsole(context)

    if script is not None:
        cmd.do_exec(script)

    try:
        if echo:
            print("cm>", command)
        if command is not None:
            cmd.precmd(command)
            stop = cmd.onecmd(command)
            cmd.postcmd(stop, command)
    except Exception as e:
        print("ERROR: executing command '{0}'".format(command))
        print(70 * "=")
        print(e)
        print(70 * "=")
        Error.traceback()

    if interactive or (command is None and script is None):
        cmd.cmdloop()
Example #6
0
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]
    """

    #    __version__ = pkg_resources.require("cmd3")[0].version
    # arguments = docopt(main.__doc__, help=True, version=__version__)

    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:
        print(arguments)
        
    
    plugins = []

    plugins.append(dict(get_plugins_from_dir("sys", "cmd3")))
    # plugins.append(dict(get_plugins_from_dir("~/.cloudmesh", "cmd3local")))


    modules = ['cloudmesh_cmd3.plugins',
               'cloudmesh_docker.plugins',
               'cloudmesh_slurm.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'] = 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.get_version()
    cmd.set_verbose(echo)
    cmd.activate()
    cmd.set_verbose(echo)

    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:
            print()
            print("ERROR: executing command '{0}'".format(user_cmd))
            print()
            print(e)
            print(traceback.format_exc())
        if interactive:
            cmd.cmdloop()
Example #7
0
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()
Example #8
0
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]
    """

    #    __version__ = pkg_resources.require("cmd3")[0].version
    # arguments = docopt(main.__doc__, help=True, version=__version__)

    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 = {}
        arguments['-b'] = True
        arguments['COMMAND'] = [' '.join(sys.argv[1:])]

    plugins = []

    plugins.append(dict(get_plugins_from_dir("sys", "cmd3")))
    # plugins.append(dict(get_plugins_from_dir("~/.cloudmesh", "cmd3local")))

    modules = [
        'cloudmesh_cmd3.plugins', 'cloudmesh_docker.plugins',
        'cloudmesh_slurm.plugins', 'cloudmesh_deploy.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'] = 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.get_version()
    cmd.set_verbose(echo)
    cmd.activate()
    cmd.set_verbose(echo)

    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:
            print()
            print("ERROR: executing command '{0}'".format(user_cmd))
            print()
            print(e)
            print(traceback.format_exc())
        if interactive:
            cmd.cmdloop()
Example #9
0
def main():
    """
    OnTalk OnConsole.
    Usage: 
      onconsole [-q] help
      onconsole [-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)
        if arguments['help']:
            arguments['COMMAND'] = ['help']
            arguments['help'] = 'False'

        script_file = arguments['--file']
        interactive = arguments['-i']
        echo = arguments['-v']
        if echo:
            pprint(arguments)
        print(arguments)

    except:
        script_file = None
        interactive = False

        arguments = {'-b': True,
                     'COMMAND': [' '.join(sys.argv[1:])]}

    cmd.Cmd.set_verbose(echo)
    cmd.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()
Example #10
0
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()
Example #11
0
def main():
    """cm.

    Usage:
      cm --help
      cm [--debug] [--nosplash] [-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]
      --nosplash    do not show the banner [default: False]
    """

    def manual():
        print(main.__doc__)

    args = sys.argv[1:]

    arguments = {
        '--debug': '--debug' in args,
        '--nosplash': '--nosplash' in args,
        '-i': '-i' in args}

    for a in args:
        if a in arguments:
            args.remove(a)

    arguments['COMMAND'] = [' '.join(args)]

    commands = arguments["COMMAND"]
    if len(commands) > 0:
        if ".cm" in commands[0]:
            arguments["SCRIPT"] = commands[0]
            commands = commands[1:]
        else:
            arguments["SCRIPT"] = None

        arguments["COMMAND"] = ' '.join(commands)
        if arguments["COMMAND"] == '':
            arguments["COMMAND"] = None


    if arguments['COMMAND'] == []:
        arguments['COMMAND'] = None

    splash = not arguments['--nosplash']
    debug = arguments['--debug']
    interactive = arguments['-i']
    script = arguments["SCRIPT"]
    command = arguments["COMMAND"]



    context = CloudmeshContext(debug=debug,
                               splash=splash)
    cmd = CloudmeshConsole(context)


    if script is not None:
        cmd.do_exec(script)

    try:
        if debug:
            print(">", command)
        if command is not None:
            cmd.onecmd(command)
    except Exception, e:
        print("ERROR: executing command '{0}'".format(command))
        print(70 * "=")
        print(e)
        print(70 * "=")
        Error.traceback()
Example #12
0
def main():
    """
    OnTalk OnConsole.
    Usage: 
      onconsole [-q] help
      onconsole [-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)
        if arguments['help']:
            arguments['COMMAND'] = ['help']
            arguments['help'] = 'False'

        script_file = arguments['--file']
        interactive = arguments['-i']
        echo = arguments['-v']
        if echo:
            pprint(arguments)
        print(arguments)

    except:
        script_file = None
        interactive = False

        arguments = {'-b': True, 'COMMAND': [' '.join(sys.argv[1:])]}

    cmd.Cmd.set_verbose(echo)
    cmd.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()