Exemple #1
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()
Exemple #2
0
def get_cli(cmdclass,
            env=None,
            aliases=None,
            logfile=None,
            paged=False,
            theme=None,
            historyfile=None):
    if paged:
        io = tty.PagedIO()
    else:
        io = ConsoleIO()
    ui = UserInterface(io, env, theme)
    cmd = cmdclass(ui, aliases)
    parser = CommandParser(cmd, logfile, historyfile)
    return parser
Exemple #3
0
def instrumentshell(argv):
  """pdish [-?rg]

  Provides an interactive session to the GPIB bus.

  Options:
   -?, -h  = This help text.
   -g      = used paged output (like 'more').
   -d      = Enable debugging.

"""
  paged = False

  try:
    optlist, longopts, args = getopt.getopt(argv[1:], "?hgd")
  except getopt.GetoptError:
      print instrumentshell.__doc__
      return
  for opt, val in optlist:
    if opt in ("-?", "-h"):
      print instrumentshell.__doc__
      return
    elif opt == "-g":
      paged = True
    elif opt == "-d":
      from pycopia import autodebug

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

  env = measurecore.MeasurementContext()
  env.evalupdate(longopts)
  ui = CLI.UserInterface(io, env)

  conf = core._GetConfig()
  cmd = TopLevel(ui)
  cmd._setup(conf, "pdish> ")

  parser = CLI.CommandParser(cmd, 
        historyfile=os.path.expandvars("$HOME/.hist_pdish"))

  parser.interact()
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
Exemple #5
0
def get_terminal_ui(env=None, paged=False, theme=None):
    if paged:
        io = tty.PagedIO()
    else:
        io = ConsoleIO()
    return UserInterface(io, env, theme)