logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

CVS: tmda/bin tmda-clean,NONE,1.1 ChangeLog,1.42,1.43: msg#00022

Subject: CVS: tmda/bin tmda-clean,NONE,1.1 ChangeLog,1.42,1.43
Update of /cvsroot/tmda/tmda/bin
In directory usw-pr-cvs1:/tmp/cvs-serv19227

Modified Files:
        ChangeLog 
Added Files:
        tmda-clean 
Log Message:
New script to remove old messages from the pending queue.


--- NEW FILE ---
#!/usr/bin/env python

"""Remove old messages from the pending queue.

Usage:  %(program)s [-c <file>] [-d] [-v] [-h] timeout

Where:
    -c <file>
    --config-file <file>
       Specify a different configuration file other than ~/.tmdarc.

    -d
    --dry-run
       Don't actually remove files, just show what would have happened.
       This implies --verbose.
       
    -v
    --verbose
       Print a verbose display instead of the default silent display.

    --help
    -h
       Print this help message and exit.

    timeout is the required minimum retention time in seconds (s),
    minutes (m), hours (h), days (d), or weeks (w), for unconfirmed
    messages.  Messages older than timeout will be purged.

    e.g, %(program)s 30d
"""

import getopt
import glob
import os
import sys
import string
import time


program = sys.argv[0]
dry = None
verbose = None

def usage(code, msg=''):
    print __doc__ % globals()
    if msg:
        print msg
    sys.exit(code)

try:
    opts, args = getopt.getopt(sys.argv[1:],
                               'c:dvh',
                               ['config-file=','dry-run','verbose','help'])
except getopt.error, msg:
    usage(1, msg)

for opt, arg in opts:
    if opt in ('-h', '--help'):
        usage(0)
    elif opt in ('-c', '--config-file'):
        os.environ['TMDARC'] = arg
    elif opt in ('-d', '--dry-run'):
        dry, verbose = 1,1
        verbose = 1
    elif opt in ('-v', '--verbose'):
        verbose = 1


try:
    import paths
except ImportError:
    pass
    
from TMDA import Defaults
from TMDA import Util


# timeout is required
try:
    timeout = args[0]
except IndexError:
    usage(0)

pendingdir = Defaults.DATADIR + 'pending'
timeout_in_secs = Util.seconds(timeout)
now = '%d' %time.time()
# Anything less than this is history.
min_time = int(now) - int(timeout_in_secs)


def main():

    os.chdir(pendingdir)
    for msg in glob.glob('*.msg'):
        msg_split = string.split(msg,'.')
        msg_time = int(msg_split[0])
        if msg_time < min_time:
            if verbose:
                message = msg + ' is more than ' + \
                          Util.format_timeout(timeout) + ' old, deleting!'
                if dry:
                    message = message + ' (dry-run)'
                print message
            if not dry:
                os.unlink(msg)


if __name__ == '__main__':
    main()

Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/ChangeLog,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- ChangeLog   2001/07/17 20:03:55     1.42
+++ ChangeLog   2001/07/18 00:22:52     1.43
@@ -1,5 +1,8 @@
 2001-07-17  Jason R. Mastaler  <jasonrm@xxxxxxxxxxxxxxxxxxxxxxxxxx>
 
+       * tmda-clean: New script to remove old messages from the pending
+       queue.
+
        * tmda-filter (inject_pending): Change format of `X-Confirmed:' to
        resemble rfc822 dates to more easily compare it to the `Date:'
        header.




<Prev in Thread] Current Thread [Next in Thread>