Esempio n. 1
0
def smtpcli(argv):
    """smtpcli [-h] [-l <logfilename>] [-s <portname>] [host] [port]

Provides an interactive session at a protocol level to an SMTP server. 
    """
    bindto = None
    port = 25
    sourcefile = None
    paged = False
    logname = None
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "b:hp:s:l:g")
    except getopt.GetoptError:
        print(smtpcli.__doc__)
        return
    for opt, val in optlist:
        if opt == "-b":
            bindto = val
        if opt == "-l":
            logname = val
        elif opt == "-s":
            sourcefile = val
        elif opt == "-g":
            paged = True
        elif opt == "-h":
            print(smtpcli.__doc__)
            return
        elif opt == "-p":
            try:
                port = int(val)
            except ValueError:
                print(smtpcli.__doc__)
                return

    theme = UI.DefaultTheme(PROMPT)
    parser = CLI.get_cli(EmailClientCLI, paged=paged, theme=theme)
    if len(args) > 0:
        if len(args) > 1:
            port = int(args[1])
        else:
            port = 25
        host = args[0]
    else:
        host = ""
    if logname:
        parser.commands.logfile(["logfile", logname])
    if host:
        parser.commands.connect(["connect"] + IF(bindto, ["-s", bindto], []) +
                                [host, port])
    else:
        parser.commands._print(
            "Be sure to run 'connect' before anything else.\n")

    if sourcefile:
        try:
            parser.parse(sourcefile)
        except CLI.CommandQuit:
            pass
    else:
        parser.interact()
Esempio n. 2
0
 def __init__(self, syslog, ps1="%Isyslog%N> "):
     self.syslog = syslog
     theme = UI.DefaultTheme(ps1)
     self.parser = CLI.get_cli(SyslogCLI,
                               paged=False,
                               theme=theme,
                               aliases=_CMDALIASES)
     self.parser.command_setup(syslog, ps1)
Esempio n. 3
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()
Esempio n. 4
0
def imapcli(argv):
    """imapcli [-h|--help] [-S] [host] [port]

Provides an interactive session at a protocol level to an IMAP server. 
If the "-S" argument is provided, will connect using SSL.
    """
    from pycopia import getopt
    port = imaplib.IMAP4_PORT
    sourcefile = None
    paged = False
    ssl = True
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "hp:s:gS")
    except getopt.GetoptError:
        print(imapcli.__doc__)
        return
    for opt, val in optlist:
        if opt == "-s":
            sourcefile = val
        elif opt == "-h":
            print(imapcli.__doc__)
            return
        elif opt == "-g":
            paged = True
        elif opt == "-S":
            ssl = True
        elif opt == "-p":
            try:
                port = int(val)
            except ValueError:
                print(imapcli.__doc__)
                return

    theme = UI.DefaultTheme(PROMPT)
    parser = CLI.get_cli(ImapCLI, paged=paged, theme=theme)
    if len(args) > 0:
        parser.commands.connect(["connect"] +
                                ((ssl == True) and ["-S"] or []) + args)
    else:
        parser.commands._print(
            "Be sure to run 'connect' before anything else.\n")
    if sourcefile:
        try:
            parser.parse(sourcefile)
        except CLI.CommandQuit:
            pass
    else:
        parser.interact()