示例#1
0
 def test_storage(self):
     db = Storage.get_client()
     r = db.get_root()
     c = r.add_container("subtree")
     c.value = 1
     db.commit()
     del db, r
     db = Storage.get_client()
     r = db.get_root()
     assert r.subtree.value == 1
示例#2
0
文件: test.py 项目: xiangke/pycopia
 def test_storage(self):
     db = Storage.get_client()
     r = db.get_root()
     c = r.add_container("subtree")
     c.value = 1
     db.commit()
     del db, r
     db = Storage.get_client()
     r = db.get_root()
     assert r.subtree.value == 1
示例#3
0
def storagecli(argv):
    """storagecli [-?rg] [<scriptfile>...]

Provides an interactive session to the configuration server. This allows you to
interactively view and change the persistent database.

Options:
   -?        = This help text.
   -g        = used paged output (like 'more').

"""
    from pycopia import getopt

    paged = False

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

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

    ui = CLI.UserInterface(io)

    cf = Storage.get_config(initdict=longopts)

    cf.reportfile = __name__.replace(".", "_")
    cf.logbasename = "%s.log" % (__name__.replace(".", "_"), )
    cf.arguments = argv
    cmd = RootContainerEditor(ui)
    cmd._setup(cf, "root")

    parser = CLI.CommandParser(
        cmd, historyfile=os.path.expandvars("$HOME/.hist_storagecli"))
    if args:
        for arg in args:
            try:
                parser.parse(arg)
            except KeyboardInterrupt:
                break
    else:
        parser.interact()
示例#4
0
def storagecli(argv):
    """storagecli [-?rg] [<scriptfile>...]

Provides an interactive session to the configuration server. This allows you to
interactively view and change the persistent database.

Options:
   -?        = This help text.
   -g        = used paged output (like 'more').

"""
    from pycopia import getopt

    paged = False

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

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

    ui = CLI.UserInterface(io)

    cf = Storage.get_config(initdict=longopts)

    cf.reportfile = __name__.replace(".", "_")
    cf.logbasename = "%s.log" % (__name__.replace(".", "_"),)
    cf.arguments = argv
    cmd = RootContainerEditor(ui)
    cmd._setup(cf, "root")

    parser = CLI.CommandParser(cmd, historyfile=os.path.expandvars("$HOME/.hist_storagecli"))
    if args:
        for arg in args:
            try:
                parser.parse(arg)
            except KeyboardInterrupt:
                break
    else:
        parser.interact()
示例#5
0
def remotecli(argv):
    """remotecli [-h|-?] [-g] [-s <script>]

Provides an interactive session to a remote Client server object. Most of the
methods in the module remote.Server may be called this way.

"""
    from pycopia import getopt
    from pycopia.storage import Storage

    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 = Storage.get_config(initdict=longopts)
    #testrunner.connect_user(cf)
    #testrunner.runtime_config(cf)
    # fake test module attributes
    cf.reportfile = "remotecli"
    cf.logbasename = "remotecli.log"
    cf.arguments = argv

    theme = UI.DefaultTheme(PROMPT)
    history = os.path.expandvars("$HOME/.hist_clientcli")
    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()
示例#6
0
def remotecli(argv):
    """remotecli [-h|-?] [-g] [-s <script>]

Provides an interactive session to a remote Client server object. Most of the
methods in the module remote.Server may be called this way.

"""
    from pycopia import getopt
    from pycopia.storage import Storage

    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 = Storage.get_config(initdict=longopts)
    #testrunner.connect_user(cf)
    #testrunner.runtime_config(cf)
    # fake test module attributes
    cf.reportfile = "remotecli"
    cf.logbasename = "remotecli.log"
    cf.arguments = argv

    theme = UI.DefaultTheme(PROMPT)
    history=os.path.expandvars("$HOME/.hist_clientcli")
    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()
示例#7
0
def mod_doc(fo, mod):
    setattr(mod, "_visited_", True)
    fo.write("\n.. _%s:\n" % (mod.__name__.split(".")[-1],))
    fo.write(mod.__doc__) # module doc, should be RST
    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 = Storage.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(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_"):
                    #setattr(obj, "_visited_", True)
                    mod_doc(fo, obj)
示例#8
0
def mod_doc(fo, mod):
    setattr(mod, "_visited_", True)
    fo.write("\n.. _%s:\n" % (mod.__name__.split(".")[-1], ))
    fo.write(mod.__doc__)  # module doc, should be RST
    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 = Storage.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(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_"):
                    #setattr(obj, "_visited_", True)
                    mod_doc(fo, obj)
示例#9
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.QA import configurator
    from pycopia import getopt
    from pycopia.storage import Storage

    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 = Storage.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
示例#10
0
 def __init__(self):
     cf = Storage.get_config()
     self._config = cf
示例#11
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.QA import configurator
    from pycopia import getopt
    from pycopia.storage import Storage

    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 = Storage.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