コード例 #1
0
ファイル: shell.py プロジェクト: hanjinze/cloud-metrics
def main():
    plugins = get_plugins("./plugins")

    name    = "CmCli"

    (cmd, plugin_objects) = DynamicCmd(name, plugins)
    cmd.activate()
    cmd.cmdloop()
コード例 #2
0
ファイル: shell.py プロジェクト: hanjinze/cmd3
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()
コード例 #3
0
ファイル: shell.py プロジェクト: hanjinze/cloud-metrics
       def activate_status(self):
           print "Active:", self.active

       def activate(self, plugins):
           d = dir(self)
           result = []
           for key in d:
               if key.startswith("activate_"):
                   result.append(key)
           print result
           for key in result:
               print "> %s" % key.replace("_"," ")
               exec("self.%s()" % key)
"""

import sys
import cmd
import readline

from cyberaide import load_plugins
from cyberaide import make_cmd_class
from cyberaide import DynamicCmd

plugins = ["foo", "bar","activate"]
name    = "CmCli"

(cmd, plugin_objects) = DynamicCmd(name, plugins)
cmd.activate(plugin_objects)
cmd.cmdloop()
コード例 #4
0
ファイル: shell.py プロジェクト: futuregrid/cmd3
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()
コード例 #5
0
ファイル: shell.py プロジェクト: cloudmesh/cmd3
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()
コード例 #6
0
ファイル: shell.py プロジェクト: amimoto/cmd3
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()
コード例 #7
0
ファイル: shell.py プロジェクト: thorwald/cmd3
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()
コード例 #8
0
ファイル: shell.py プロジェクト: zaber-paul/cmd3
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()