Ejemplo n.º 1
0
def main():
    """
    The main routine.
    """
    # Instantiate the app
    app = CmdlineApplication()

    caOption = Option(
        "-C",
        "--ca",
        action="store_true",
        dest="is_ca_mode",
        default=0,
        help="Use CA mode for this invocation of the certificate manager.")
    idOption = Option(
        "-I",
        "--id",
        action="store_false",
        dest="is_ca_mode",
        default=0,
        help="Use ID mode for this invocation of the certificate manager.")

    forceOption = Option("-f",
                         "--force",
                         action="store_true",
                         dest="force_overwrite",
                         default=0,
                         help="Overwrite existing files.")
    app.AddCmdLineOption(caOption)
    app.AddCmdLineOption(idOption)
    app.AddCmdLineOption(forceOption)

    try:
        args = app.Initialize("CertificateManager")
    except Exception:
        sys.exit(0)

    cmd = CertMgrCmdProcessor(app.GetCertificateManager(), app.GetLog())

    #
    # If no args were passed, start up the command-driver
    # cert mgr.
    #

    if app.GetOption("is_ca_mode"):
        cmd.setCAMode()

    if len(args) == 0:

        cmd.cmdloop()

    else:

        #
        # Otherwise, process a single command from teh command line.
        #

        cmd.setInteractive(0)
        cmd.setForceOverwrite(app.GetOption("force_overwrite"))

        mycmd = args[0] + " " + " ".join(map(lambda a: '"' + a + '"',
                                             args[1:]))
        print mycmd
        cmd.onecmd(mycmd)