Exemple #1
0
def _test():
    verbose=0
    repository = "."
    output = "index.html"
    display=['session','profile','hostname','date','time','path']
    sort=['session','profile']
    breakon='package'
    email=None
    mailserver=None
    selectdate=None
    selectpackage=".*"
    selectprofile=".*"
    selectsession=".*"
    selects=[]
    (opts,args)=getopt.getopt(sys.argv[1:],shortopts,longopts)
    for (o,v) in opts:
        if o in ("-h","--help"):
            print(help_string)
            sys.exit(0)
        elif o in ("-v", "--verbose"):
            verbose=1
        elif o in ("-r","--repository"):
            repository=v
        elif o in ("-o","--output"):
            output=v
        elif o in ("-d","--display"):
            display=v.split(',')
        elif o in ("-s","--sort-order"):
            sort=v.split(',')
        elif o in ("-b","--break-tables-on"):
            breakon=v
        elif o in ("-e","--email"):
            email=v
        elif o in ("-m","--mailserver"):
            mailserver=v
        elif o in ("-b","--break-tables-on"):
            breakon=v
        elif o in ("-t","--today"):
            selectdate="24 hours"
        elif o in ("-l","--select"):
            selects = v.split(',')
            for s in selects:
                (x,y)=s.split('=')
                if x == "package":
                    selectpackage=y
                elif x == "profile":
                    selectprofile=y
                elif x == "session":
                    selectsession=y
                elif x == "date":
                    selectdate=y
                else:
                    print( "Unrecognized select option:", x)

    mgr = session_archiver( repository )
    daterange = parse_date(selectdate)
    msgs = mgr.select(package=selectpackage,profile=selectprofile,
                      session=selectsession,
                      starttime=daterange[0], endtime=daterange[1])
    f = open(output,'w')
    viewer = html_viewer(break_tables_on=breakon,
                         display_order=display,
                         sort_order=sort
                         )
    viewer.html_page( f, msgs )
    f.close()
    
    if not( email == None or mailserver == None):
        f = open(output,'r')
        e = email_display( None, email, mailserver)
        msg = MIMEText(f.read(), "html", "iso-8859-1")
        msg["Precedence"] = "bulk"
        e.verbose = verbose
        whoami = 'unknown'
        try:
            whoami = os.getlogin()
        except:
            pass
        hostname = socket.getfqdn()
        email_from = whoami + "@" + hostname
        date = rfc822time()
        subject="Gantlet Results"
        msg["To"] = email
        msg["From"] = email_from
        msg["Subject"] = "Gantlet Results"
        e.email_to_SMTP(msg)

    f.close()
def _commandline():
    popserver=None
    popuser=None
    passwd = None
    delete_junk = None
    delete_msgs = None
    count = None
    repository = None
    verbose = None
    shortopts = "hvs:u:p:r:cdj"
    longopts = ["help", "verbose" "pop-server=", "userid=", "passwd=", "repository=",
                "count", "delete", "delete-junk" ]

    (opts,args) = getopt.getopt( sys.argv[1:], shortopts, longopts )
    for (o, v) in opts:
        if o in ("-h", "--help"):
            print help_string
            sys.exit(0)
        elif o in ("-v", "--verbose"):
            verbose = 1
        elif o in ("-s", "--pop-server"):
            popserver = v
        elif o in ("-u", "--userid"):
            popuser = v
        elif o in ("-p", "--passwd"):
            passwd = v
        elif o in ("-r", "--repository"):
            repository = v
        elif o in ("-c", "--count"):
            count = 1
        elif o in ( "-d", "--delete" ):
            delete_msgs = 1
        elif o in ("-j", "--delete-junk"):
            delete_junk = 1
            
    if not passwd:
        passwd = getpass.getpass( "Password for %s@%s : " % (popuser, popserver) )

    # Now do the interesting stuff
    mail_reader = session_pop_client( popserver, popuser, passwd, debug=3 )
    all_msgs = mail_reader.load_msgs( )
    (msgs, junk) = mail_reader.split_msgs( all_msgs )
    
    if count or verbose :
        print "%d messages total:  %d gantlet, %d other" % (

            len( all_msgs), len( msgs ), len (junk ) )

    if verbose:
        for msg in msgs:
            #print (msg.id, msg.attr)
            if '/' in msg.attr['session']:
                print '*********************'
                msg.attr['session']='ask_epperly'
            else:
                print '**** NO RENAMING NECESSARY ****'
            print (msg.id, msg.attr)

    if repository and len(msgs):
        if verbose: print "Loading into repository ('%s')" % repository
        mgr = session_archiver(repository)
        for msg in msgs:
            mgr.insert( msg )
        mgr.store_index()

    if delete_junk and delete_msgs:
        mail_reader.del_msgs( all_msgs )
    elif delete_junk:
        mail_reader.del_msgs( junk )
    elif delete_msgs:
        mail_reader.del_msgs( msgs )

    if verbose: print 'Bye.'
Exemple #3
0
def _commandline():
    popserver = None
    popuser = None
    passwd = None
    ssl_encrypted = None
    delete_junk = None
    delete_msgs = None
    count = None
    repository = None
    verbose = None
    shortopts = "hvs:u:p:r:cdjE"
    longopts = [
        "help", "verbose"
        "pop-server=", "userid=", "passwd=", "repository=", "count", "delete",
        "delete-junk", "encrypted"
    ]

    (opts, args) = getopt.getopt(sys.argv[1:], shortopts, longopts)
    for (o, v) in opts:
        if o in ("-h", "--help"):
            print(help_string)
            sys.exit(0)
        elif o in ("-v", "--verbose"):
            verbose = 1
        elif o in ("-s", "--pop-server"):
            popserver = v
        elif o in ("-u", "--userid"):
            popuser = v
        elif o in ("-p", "--passwd"):
            passwd = v
        elif o in ("-r", "--repository"):
            repository = v
        elif o in ("-c", "--count"):
            count = 1
        elif o in ("-d", "--delete"):
            delete_msgs = 1
        elif o in ("-j", "--delete-junk"):
            delete_junk = 1
        elif o in ("-E", "--encrypted"):
            ssl_encrypted = 1

    if not passwd:
        passwd = getpass.getpass("Password for %s@%s : " %
                                 (popuser, popserver))

    # Now do the interesting stuff
    mail_reader = session_pop_client(popserver,
                                     popuser,
                                     passwd,
                                     debug=3,
                                     encrypted=ssl_encrypted)
    all_msgs = mail_reader.load_msgs()
    (msgs, junk) = mail_reader.split_msgs(all_msgs)

    if count or verbose:
        print("%d messages total:  %d gantlet, %d other" %
              (len(all_msgs), len(msgs), len(junk)))

    if verbose:
        for msg in msgs:
            #print (msg.id, msg.attr)
            if '/' in msg.attr['session']:
                print('*********************')
                msg.attr['session'] = 'ask_epperly'
            else:
                print('**** NO RENAMING NECESSARY ****')
            print(msg.id, msg.attr)

    if repository and len(msgs):
        if verbose: print("Loading into repository ('%s')" % repository)
        mgr = session_archiver(repository)
        for msg in msgs:
            mgr.insert(msg)
        mgr.store_index()

    if delete_junk and delete_msgs:
        mail_reader.del_msgs(all_msgs)
    elif delete_junk:
        mail_reader.del_msgs(junk)
    elif delete_msgs:
        mail_reader.del_msgs(msgs)

    if verbose: print('Bye.')
Exemple #4
0
def _test():
    verbose=0
    repository = "."
    output = "index.html"
    display=['session','profile','hostname','date','time','path']
    sort=['session','profile']
    breakon='package'
    email=None
    mailserver=None
    selectdate=None
    selectpackage=".*"
    selectprofile=".*"
    selectsession=".*"
    selects=[]
    (opts,args)=getopt.getopt(sys.argv[1:],shortopts,longopts)
    for (o,v) in opts:
        if o in ("-h","--help"):
            print help_string
            sys.exit(0)
        elif o in ("-v", "--verbose"):
            verbose=1
        elif o in ("-r","--repository"):
            repository=v
        elif o in ("-o","--output"):
            output=v
        elif o in ("-d","--display"):
            display=v.split(',')
        elif o in ("-s","--sort-order"):
            sort=v.split(',')
        elif o in ("-b","--break-tables-on"):
            breakon=v
        elif o in ("-e","--email"):
            email=v
        elif o in ("-m","--mailserver"):
            mailserver=v
        elif o in ("-b","--break-tables-on"):
            breakon=v
        elif o in ("-t","--today"):
            selectdate="24 hours"
        elif o in ("-l","--select"):
            selects = v.split(',')
            for s in selects:
                (x,y)=s.split('=')
                if x == "package":
                    selectpackage=y
                elif x == "profile":
                    selectprofile=y
                elif x == "session":
                    selectsession=y
                elif x == "date":
                    selectdate=y
                else:
                    print "Unrecognized select option:", x

    mgr = session_archiver( repository )
    daterange = parse_date(selectdate)
    msgs = mgr.select(package=selectpackage,profile=selectprofile,
                      session=selectsession,
                      starttime=daterange[0], endtime=daterange[1])
    f = open(output,'w')
    viewer = html_viewer(break_tables_on=breakon,
                         display_order=display,
                         sort_order=sort
                         )
    viewer.html_page( f, msgs )
    f.close()
    
    if not( email == None or mailserver == None):
        f = open(output,'r')
        e = email_display( None, email, mailserver)
        e.file = f
        e.verbose = verbose
        whoami = 'unknown'
        try:
            whoami = os.getlogin()
        except:
            pass
        hostname = socket.getfqdn()
        email_from = whoami + "@" + hostname
        date = rfc822time()
        subject="Gantlet Results"
        header=std_header %( email_from, email, date, subject )
        e.email_from = email_from
        e.email_to = email
        e.email_file_via_SMTP(header)

    f.close()