[Spambayes-checkins] spambayes/testtools sort+group.py,1.2,1.3
Tony Meyer
anadelonbrin at users.sourceforge.net
Thu Apr 7 03:33:52 CEST 2005
Update of /cvsroot/spambayes/spambayes/testtools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13964/testtools
Modified Files:
sort+group.py
Log Message:
Add options to sort_group.py
-h usage
-q for suppressing verbose output
-o Skip's fantastic set and option at the command line
Also observe the ham/spam directory options, rather than assuming a "Data" directory in the cwd. In addition, only run through the specified directories, unless
the -a option is used (this is more like the old behaviour).
Index: sort+group.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/testtools/sort+group.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** sort+group.py 28 Dec 2003 01:12:11 -0000 1.2
--- sort+group.py 7 Apr 2005 01:33:50 -0000 1.3
***************
*** 1,11 ****
#! /usr/bin/env python
! ### Sort and group the messages in the Data hierarchy.
! ### Run this prior to mksets.py for setting stuff up for
! ### testing of chronological incremental training.
! """Usage: sort+group.py
! This program has no options! Muahahahaha!
"""
--- 1,22 ----
#! /usr/bin/env python
! """Usage: sort+group.py [options]
! Where:
! -h
! Show usage and exit.
! -q
! Suppress verbose output.
! -a
! Run through all directories in the directories that the
! ham_directories and spam_directories are in. This is
! similar (identical with default ham/spam directories)
! to the 1.0.x sort+group.py behaviour.
! -o section:option:value
! set [section, option] in the options database to value.
! Sort and group the messages in the Data hierarchy.
! Run this prior to mksets.py for setting stuff up for testing of
! chronological incremental training.
"""
***************
*** 14,21 ****
import glob
import time
from email.Utils import parsedate_tz, mktime_tz
! loud = True
SECONDS_PER_DAY = 24 * 60 * 60
--- 25,34 ----
import glob
import time
+ import getopt
from email.Utils import parsedate_tz, mktime_tz
! from spambayes.Options import options
!
SECONDS_PER_DAY = 24 * 60 * 60
***************
*** 60,67 ****
--- 73,106 ----
return mktime_tz(as_tuple)
+ def usage(code, msg=''):
+ """Print usage message and sys.exit(code)."""
+ if msg:
+ print >> sys.stderr, msg
+ print >> sys.stderr
+ print >> sys.stderr, __doc__ % globals()
+ sys.exit(code)
+
def main():
"""Main program; parse options and go."""
from os.path import join, split
+ import getopt
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'hqao:')
+ except getopt.error, msg:
+ usage(1, msg)
+
+ loud = True
+ all_data = False
+ for opt, arg in opts:
+ if opt == '-h':
+ usage(0)
+ elif opt == '-q':
+ loud = False
+ elif opt == '-a':
+ all_data = True
+ elif opt in ('-o', '--option'):
+ options.set_from_cmdline(arg, sys.stderr)
data = [] # list of (time_received, dirname, basename) triples
***************
*** 69,73 ****
print "Scanning everything"
now = time.time()
! for name in glob.glob('Data/*/*/*'):
if loud:
sys.stdout.write("%-78s\r" % name)
--- 108,123 ----
print "Scanning everything"
now = time.time()
! hdir = os.path.dirname(options["TestDriver", "ham_directories"])
! sdir = os.path.dirname(options["TestDriver", "spam_directories"])
! if all_data:
! hdir = os.path.dirname(hdir)
! sdir = os.path.dirname(sdir)
! files = glob.glob(os.path.join(hdir, "*", "*", "*"))
! if sdir != hdir:
! files.extend(glob.glob(os.path.join(sdir, "*", "*", "*")))
! else:
! files = glob.glob(os.path.join(hdir, "*", "*"))
! files.extend(glob.glob(os.path.join(sdir, "*", "*")))
! for name in files:
if loud:
sys.stdout.write("%-78s\r" % name)
More information about the Spambayes-checkins
mailing list