def sslcli(argv): b"""sslcli [-?D] Provides an interactive CLI for managing SSL certificates and CA operations. Options: -? = This help text. -D = Debug on. """ import os import getopt try: optlist, args = getopt.getopt(argv[1:], b"?hD") except getopt.GetoptError: print(sslcli.__doc__) return for opt, val in optlist: if opt in (b"-?", b"-h"): print(sslcli.__doc__) return elif opt == b"-D": from pycopia import autodebug io = CLI.ConsoleIO() ui = CLI.UserInterface(io) ui._env[b"PS1"] = b"SSL> " cmd = SSLCommands(ui) parser = CLI.CommandParser( cmd, historyfile=os.path.expandvars(b"$HOME/.hist_sslcli")) parser.interact()
def cacli(argv): """cacli [-?D] <configfile>... Provides an interactive CLI for managing the certificate authority. Options: -? = This help text. -D = Debug on. """ import os import getopt try: optlist, args = getopt.getopt(argv[1:], "?D") except getopt.GetoptError: print(cacli.__doc__) return for opt, val in optlist: if opt == "-?": print(cacli.__doc__) return elif opt == "-D": from pycopia import autodebug io = CLI.ConsoleIO() ui = CLI.UserInterface(io) cmd = CACommands(ui) mgr = CA.get_manager() cmd._setup(mgr, "%YCA%N> ") parser = CLI.CommandParser( cmd, historyfile=os.path.expandvars("$HOME/.hist_cacli")) parser.interact()
def adbsh(argv): """adbsh [-?hD] Provides an interactive session for ADB. Options: -? = This help text. -D = Enable debugging. """ try: optlist, longopts, args = getopt.getopt(argv[1:], "?hD") except getopt.GetoptError: print adbsh.__doc__ return for opt, optarg in optlist: if opt in ("-?", "-h"): print adbsh.__doc__ return elif opt == "-D": from pycopia import autodebug client = adb.AdbClient() io = CLI.ConsoleIO() ui = CLI.UserInterface(io) cmd = AdbClientCommands(ui) cmd._setup(client, "ADB> ") parser = CLI.CommandParser( cmd, historyfile=os.path.expandvars("$HOME/.hist_androidsh")) parser.interact()
def dbconfig(argv): """dbconfig [-?D] Options: -? = This help text. -D = Debug on. """ global _session from pycopia import getopt try: optlist, longopts, args = getopt.getopt(argv[1:], "?") except getopt.GetoptError: print (dbconfig.__doc__) return for opt, val in optlist: if opt == "-?": print (dbconfig.__doc__) return if opt == "-D": from pycopia import autodebug io = CLI.ConsoleIO() ui = CLI.UserInterface(io) cmd = ConfigCommands(ui) _session = models.get_session() root = get_root(_session) cmd._setup(root, "%%Ydbconfig%%N:%s> " % (root.name,)) cmd._environ["session"] = _session parser = CLI.CommandParser(cmd, historyfile=os.path.expandvars("$HOME/.hist_dbconfig")) parser.interact()
def jsoncli(argv): """jsoncli [-?D] <configfile>... Provides an interactive CLI for editing a JSON format config file. Options: -? = This help text. -D = Debug on. """ import os from pycopia import getopt try: optlist, longopts, args = getopt.getopt(argv[1:], "?D") except getopt.GetoptError: print (jsoncli.__doc__) return for opt, val in optlist: if opt == "-?": print (jsoncli.__doc__) return elif opt == "-D": from pycopia import autodebug io = CLI.ConsoleIO() ui = CLI.UserInterface(io) cmd = RootCommands(ui) for fname in args: root = jsonconfig.get_config(fname) cmd._setup(root, fname, "%%Yjsonconfig%%N:%s> " % (fname,)) parser = CLI.CommandParser(cmd, historyfile=os.path.expandvars("$HOME/.hist_jsonconfig")) parser.interact()
def doccli(argv): """doccli [-h?] [-D] [<filename>] Create and interactively edit an XHTML document. """ filename = None try: optlist, longopts, args = getopt.getopt(argv[1:], "?hD") except getopt.GetoptError: print doccli.__doc__ return for opt, optarg in optlist: if opt in ("-?", "-h"): print doccli.__doc__ return elif opt == "-D": from pycopia import autodebug if args: filename = args[0] io = CLI.ConsoleIO() ui = CLI.UserInterface(io) cmd = TopLevel(ui) cmd._environ["filename"] = filename if filename: doc = XHTML.get_document(filename) else: doc = XHTML.new_document() cmd._setup(doc, "doc> ") parser = CLI.CommandParser(cmd, historyfile=os.path.expandvars("$HOME/.hist_doccli")) parser.interact()
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()
def androidsh(argv): """androidsh [-d <index>] [-s <serial_no>] [-?hD] [<scriptfilename>] Provides an interactive session to an Android device connected via adb. Options: -d = Device index to use (default 1). -r = Device revision: sooner: 0, dream v2: 2, dream v3: 3 -s = Device serial number. -? = This help text. -D = Enable debugging. """ serial_no = None device_id = 1 try: optlist, longopts, args = getopt.getopt(argv[1:], "?hDd:") except getopt.GetoptError: print androidsh.__doc__ return for opt, optarg in optlist: if opt in ("-?", "-h"): print androidsh.__doc__ return elif opt == "-s": serial_no = optarg elif opt == "-d": device_id = int(optarg) elif opt == "-D": from pycopia import autodebug if serial_no is not None: dev = devices.GetDevice(serial_no) else: dev = devices.GetDevice(device_id) io = CLI.ConsoleIO() ui = CLI.UserInterface(io) cmd = AndroidCommands(ui) cmd._setup(dev, "%s-%s> " % ( dev.build.product, device_id, )) parser = CLI.CommandParser( cmd, historyfile=os.path.expandvars("$HOME/.hist_androidsh")) if args: scriptfilename = args[0] text = open(scriptfilename).read() parser.feed(text) else: parser.interact()
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 dbcli(argv): """dbcli [-?] Provides an interactive session to the database. Options: -? = This help text. """ global _session from pycopia import getopt try: optlist, longopts, args = getopt.getopt(argv[1:], "?") except getopt.GetoptError: print (dbcli.__doc__) return for opt, val in optlist: if opt == "-?": print (dbcli.__doc__) return io = CLI.ConsoleIO() ui = CLI.UserInterface(io) cmd = DBSessionCommands(ui) _session = models.get_session() cmd._setup(_session, "db> ") cmd._environ["session"] = _session parser = CLI.CommandParser(cmd, historyfile=os.path.expandvars("$HOME/.hist_dbcli")) if args: for arg in args: try: parser.parse(arg) except KeyboardInterrupt: break else: parser.interact()