Ejemplo n.º 1
0
def run_openssl(config, app, *args, **kwargs):
    orig = os.getcwd()
    os.chdir(CA_DIR)
    env = environ.Environ()
    env.inherit()
    env.update(CA_ENV)
    try:
        cmd = ["{} {} -config {}".format(OPENSSL, app, config)]
        if kwargs:
            for name, value in kwargs.items():
                if name.endswith("_"):
                    name = name[:-1]
                if value is None:
                    cmd.append("-{}".format(name))
                else:
                    cmd.append("-{} {}".format(name, value))
        if args:
            for arg in args:
                if type(arg) is tuple:
                    name, value = arg
                    cmd.append("-{} {}".format(name, value))
                else:
                    cmd.append(str(arg))
        cmd = " ".join(cmd)
        exitstatus, out = proctools.getstatusoutput(cmd, env=env)
        if not exitstatus:
            raise SSLExecError(exitstatus)
    finally:
        os.chdir(orig)
Ejemplo n.º 2
0
 def __init__(self, io, env=None, theme=None):
     self.set_IO(io)
     self._env = env or environ.Environ()
     assert hasattr(self._env, "get")
     self._env["_"] = None
     self._cache = {}
     self.set_theme(theme)
     self._initfsm()
     self.initialize()
Ejemplo n.º 3
0
def run_generic_cli(cmdclass=BaseCommands):
    env = environ.Environ()
    env.inherit()
    io = ConsoleIO()
    run_cli(cmdclass, io, env)
Ejemplo n.º 4
0

#### self test


# models a BaseCommands class, but only prints argv (used to test parser)
class _CmdTest(BaseCommands):
    def __call__(self, argv):
        self._print("argv: ")
        self._print(str(argv))
        self._print("\n")
        return 0


if __name__ == "__main__":
    env = environ.Environ()
    env.inherit()
    io = ConsoleIO()
    #io = tty.PagedIO()
    print("=======================")
    run_cli(_CmdTest, io, env)
    print("=======================")
    env["PS1"] = "CLItest> "
    ui = UserInterface(io, env, DefaultTheme())
    cmd = BaseCommands(ui)
    cmd = cmd.clone(DictCLI)
    cmd._setup({"testkey": "testvalue"}, "dicttest> ")
    parser = CommandParser(cmd)
    parser.interact()

    f = UserInterface(ConsoleIO(), env, DefaultTheme())