#! /usr/bin/env python """ #+ # NAME: # eon_filter.py # PURPOSE: # CATEGORY: # tools/python/bin # CALLING SEQUENCE: # INPUTS: # OPTIONAL INPUT PARAMETERS: # -v --verbose verbose mode # OUTPUTS: # CALLS: # EXAMPLE: # PROCEDURE: # MODIFICATION HISTORY: # JAN-2013, Paul Hick (UCSD/CAIDA) # OCT-2013, Paul Hick (UCSD/CAIDA; pphick@caida.org) # Added --strict, and exception handler to catch names # that do not match the regex #- """ import os import sys from eon_date import *; from eon_util import test_time if __name__ == '__main__': from optparse import OptionParser usage = "%prog [options] filename\n\n" version = '1.00' parser = OptionParser(usage=usage,version=version) parser.add_option("-v", "--verbose" , action='store_true', default=False, help="verbose (default: FALSE)") parser.add_option("" , "--start-time" , dest='start_time') parser.add_option("" , "--stop-time" , dest='stop_time' ) parser.add_option("" , "--time-regex" , dest='time_regex') parser.add_option("" , "--bool-test" , dest='bool_test' , action='store_true', default=False) parser.add_option("" , "--strict" , dest='strict' , action='store_true', default=False) (options, args) = parser.parse_args() verbose = options.verbose start_time = options.start_time stop_time = options.stop_time time_regex = options.time_regex bool_test = options.bool_test strict = options.strict if start_time != None: start_time = eon_date(start_time) if stop_time != None: stop_time = eon_date(stop_time) n_arg = len(args) i_arg = -1 while 1: if n_arg > 0: i_arg += 1 if i_arg == n_arg: break filename = args[i_arg] else: filename = sys.stdin.readline() # read one line if filename: filename = filename[:-1] else: break # EOF if test_time(filename, time_regex, start_time, stop_time, strict): print "1" if bool_test else filename elif bool_test: print "0" sys.exit(0)