Example #1
0
def remotecli(argv):
    """remotecli [-h|-?] [-g] [-s <script>]

Provides an interactive session to a remote agent object. Most of the
methods in the module remote.??????Server may be invoked with this tool.

"""
    from pycopia import getopt
    from pycopia.QA import config

    paged = False
    script = None
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "s:?hg")
    except getopt.GetoptError:
        print((remotecli.__doc__))
        return
    for opt, val in optlist:
        if opt == "-?" or opt == "-h":
            print((remotecli.__doc__))
            return
        elif opt == "-g":
            paged = True
        elif opt == "-s":
            script = val

    # do runtime setup
    cf = config.get_config(initdict=longopts)
    # fake test module attributes
    cf.reportfile = "remotecli"
    cf.logbasename = "remotecli.log"
    cf.arguments = argv

    theme = UI.DefaultTheme(PROMPT)
    history = os.path.expandvars("$HOME/.hist_remotecli")
    parser = CLI.get_cli(TopLevelCLI,
                         env=cf,
                         paged=paged,
                         theme=theme,
                         historyfile=history)

    if script:
        try:
            parser.parse(script)
        except KeyboardInterrupt:
            pass
    else:
        parser.interact()
Example #2
0
def remotecli(argv):
    """remotecli [-h|-?] [-g] [-s <script>]

Provides an interactive session to a remote agent object. Most of the
methods in the module remote.??????Server may be invoked with this tool.

"""
    from pycopia import getopt
    from pycopia.QA import config

    paged = False
    script = None
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "s:?hg")
    except getopt.GetoptError:
            print remotecli.__doc__
            return
    for opt, val in optlist:
        if opt == "-?" or opt == "-h":
            print remotecli.__doc__
            return
        elif opt == "-g":
            paged = True
        elif opt == "-s":
            script = val

    # do runtime setup
    cf = config.get_config(initdict=longopts)
    # fake test module attributes
    cf.reportfile = "remotecli"
    cf.logbasename = "remotecli.log"
    cf.arguments = argv

    theme = UI.DefaultTheme(PROMPT)
    history=os.path.expandvars("$HOME/.hist_remotecli")
    parser = CLI.get_cli(TopLevelCLI, env=cf, paged=paged, theme=theme, historyfile=history)

    if script:
        try:
            parser.parse(script)
        except KeyboardInterrupt:
            pass
    else:
        parser.interact()
Example #3
0
def mod_doc(fo, mod):
    setattr(mod, "_visited_", True)
    fo.write("\n.. _%s:\n" % (mod.__name__.split(".")[-1], ))
    if mod.__doc__:
        fo.write(mod.__doc__)  # module doc, should be RST
    else:
        name = mod.__path__[0]
        fo.write(name)
        fo.write("\n")
        fo.write("-" * len(name))
        fo.write("\n\n")

    fo.write("\n:Module Name:\n")
    fo.write("    %s\n" % (mod.__name__, ))
    if hasattr(mod, "__all__"):
        fo.write(":Test Modules:\n")
        for name in mod.__all__:
            fo.write("    - %s_\n" % (name, ))
    if hasattr(mod, "get_suite"):
        fo.write("\n:Default Tests:\n")
        cf = config.get_config()
        suite = mod.get_suite(cf)
        for test in suite:
            fo.write("    - %r\n" % (test, ))
    fo.write("\n")
    for name in dir(mod):
        obj = getattr(mod, name)
        if type(obj) is type(object) and issubclass(obj, core.Test):
            if mod.__name__ == obj.__module__:  # defined in THIS module
                # test ID is full class path
                if obj.__doc__:
                    tid = "%s.%s" % (obj.__module__, obj.__name__)
                    head = "Test Case: %s" % (obj.__name__, )
                    fo.write("\n.. _%s:\n\n%s\n" % (obj.__name__, head))
                    fo.write("*" * len(head))  # Test class header should be H2
                    fo.write("\n:Test Case ID:\n")
                    fo.write("    %s\n" % (tid, ))
                    fo.write(textwrap.dedent(obj.__doc__))
                fo.write("\n")
        elif type(obj) is ModuleType:
            if (hasattr(obj, "__path__") and os.path.split(obj.__file__)[0].startswith(os.path.split(mod.__file__)[0])) or \
                        obj.__name__.startswith(mod.__name__): # sub package or module
                if not hasattr(obj, "_visited_"):
                    mod_doc(fo, obj)
Example #4
0
def mod_doc(fo, mod):
    setattr(mod, "_visited_", True)
    fo.write("\n.. _%s:\n" % (mod.__name__.split(".")[-1],))
    if mod.__doc__:
        fo.write(mod.__doc__) # module doc, should be RST
    else:
        name = mod.__path__[0]
        fo.write(name)
        fo.write("\n")
        fo.write("-" * len(name))
        fo.write("\n\n")

    fo.write("\n:Module Name:\n")
    fo.write("    %s\n" %(mod.__name__,))
    if hasattr(mod, "__all__"):
        fo.write(":Test Modules:\n")
        for name in mod.__all__:
            fo.write("    - %s_\n" %(name,))
    if hasattr(mod, "get_suite"):
        fo.write("\n:Default Tests:\n")
        cf = config.get_config()
        suite = mod.get_suite(cf)
        for test in suite:
            fo.write("    - %r\n" %(test,))
    fo.write("\n")
    for name in dir(mod):
        obj = getattr(mod, name)
        if type(obj) is type(object) and issubclass(obj, core.Test):
            if mod.__name__ == obj.__module__: # defined in THIS module
                # test ID is full class path
                if obj.__doc__:
                    tid = "%s.%s" % (obj.__module__, obj.__name__)
                    head = "Test Case: %s" % (obj.__name__,)
                    fo.write("\n.. _%s:\n\n%s\n" % (obj.__name__, head))
                    fo.write("*"*len(head))       # Test class header should be H2
                    fo.write("\n:Test Case ID:\n")
                    fo.write("    %s\n" %(tid,))
                    fo.write(textwrap.dedent(obj.__doc__))
                fo.write("\n")
        elif type(obj) is ModuleType:
            if (hasattr(obj, "__path__") and os.path.split(obj.__file__)[0].startswith(os.path.split(mod.__file__)[0])) or \
                        obj.__name__.startswith(mod.__name__): # sub package or module
                if not hasattr(obj, "_visited_"):
                    mod_doc(fo, obj)
Example #5
0
    def __call__(self, argv):
        global _DEBUG, _FORCE, _dbsession, debugger
        domodule = False
        opts, longopts, args = getopt.getopt(argv[1:], "h?dMf")
        for opt, arg in opts:
            if opt in ("-h", "-?"):
                print (_DOC)
                return
            elif opt == "-d":
                from pycopia import debugger
                _DEBUG = True
            elif opt == "-f":
                _FORCE = True
            elif opt == "-M":
                domodule = True

        if not args:
            print (_DOC)
            return

        # Look like a test runner.
        self.config = config.get_config()
        _dbsession = models.get_session()
        self.config.options_override = longopts
        self.config.arguments = []
        self.config.username = os.environ["USER"]
        try:
            if domodule:
                for arg in args:
                    self.import_module(arg)
            else:
                for arg in args:
                    self.import_package(arg)
        finally:
            _dbsession.close()
            _dbsession = None
Example #6
0
def configurator_cli(argv):
    """configurator_cli [-s <script>] [-g] <device>

    Interact with a DUT configurator. If no device is specified use the testbed DUT.

    Options:
        -g Use paged output (like 'more')
        -s <script> Run a CLI script from the given file instead of entering
           interactive mode.

    """
    import os
    from pycopia import getopt
    from pycopia.QA import configurator
    from pycopia.QA import config

    paged = False
    script = None

    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "s:?g")
    except GetoptError:
        print configurator_cli.__doc__
        return
    for opt, val in optlist:
        if opt == "-?":
            print configurator_cli.__doc__
            return
        elif opt == "-g":
            paged = True
        elif opt == "-s":
            script = val

    if not args:
        print configurator_cli.__doc__
        return

    if paged:
        from pycopia import tty
        io = tty.PagedIO()
    else:
        io = IO.ConsoleIO()

    # do runtime setup
    cf = config.get_config(initdict=longopts)
    cf.reportfile = "configurator_cli"
    cf.logbasename = "configurator_cli.log"
    cf.arguments = argv

    dev = cf.devices[args[0]]

    ctor = configurator.get_configurator(dev, logfile=cf.logfile)

    # construct the CLI
    theme = ConfiguratorTheme("Configurator> ")
    ui = UI.UserInterface(io, cf, theme)
    cmd = CLI.get_generic_cmd(ctor, ui, ConfiguratorShellCLI)
    cmd.device = dev  # stash actual device for future reference
    parser = CLI.CommandParser(
        cmd, historyfile=os.path.expandvars("$HOME/.hist_configurator"))

    if script:
        try:
            parser.parse(script)
        except KeyboardInterrupt:
            pass
    else:
        parser.interact()
    try:
        ctor.exit()
    except:
        pass
Example #7
0
def controller_cli(argv):
    """controller_cli [-s <script>] [-g] <device>

    Interact with a DUT configurator. If no device is specified use the testbed DUT.

    Options:
        -g Use paged output (like 'more')
        -s <script> Run a CLI script from the given file instead of entering
           interactive mode.

    """
    import os
    from pycopia import getopt
    from pycopia.QA import controller
    from pycopia.QA import config

    paged = False
    script = None

    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "s:?g")
    except GetoptError:
            print((controller_cli.__doc__))
            return
    for opt, val in optlist:
        if opt == "-?":
            print((controller_cli.__doc__))
            return
        elif opt == "-g":
            paged = True
        elif opt == "-s":
            script = val

    if not args:
        print((controller_cli.__doc__))
        return

    if paged:
        from pycopia import tty
        io = tty.PagedIO()
    else:
        io = IO.ConsoleIO()

    # do runtime setup
    cf = config.get_config(initdict=longopts)
    cf.reportfile = "controller_cli"
    cf.logbasename = "controller_cli.log"
    cf.arguments = argv

    dev = cf.devices[args[0]]

    cont = controller.get_configurator(dev, logfile=cf.logfile)

    # construct the CLI
    theme = ConfiguratorTheme("Controller> ")
    ui = UI.UserInterface(io, cf, theme)
    cmd = CLI.get_generic_cmd(cont, ui, ConfiguratorShellCLI)
    cmd.device = dev # stash actual device for future reference
    parser = CLI.CommandParser(cmd, historyfile=os.path.expandvars("$HOME/.hist_controller"))

    if script:
        try:
            parser.parse(script)
        except KeyboardInterrupt:
            pass
    else:
        parser.interact()
    try:
        cont.close()
    except:
        pass
Example #8
0
 def __getattr__(self, name):
     global _config
     if isinstance(_config, _Config_getter):
         _config = config.get_config(session=_session)
     return getattr(_config, name)
Example #9
0
 def __getattr__(self, name):
     global _config
     if isinstance(_config, _Config_getter):
         _config = config.get_config(session=_session)
     return getattr(_config, name)