# HG changeset patch # User Tero Marttila # Date 1234321075 -7200 # Node ID 0690d715385d8bc8b49d7bb0ba191c931aff7c51 # Parent e24da9a94ffb89ffd4705b709af2ee3bb2a4b354 reformat add_option's and rename --after -> --from, and make that and --until inclusive diff -r e24da9a94ffb -r 0690d715385d log_source.py --- a/log_source.py Wed Feb 11 04:41:22 2009 +0200 +++ b/log_source.py Wed Feb 11 04:57:55 2009 +0200 @@ -168,8 +168,8 @@ If the datetime is not given, *all* lines are returned. - If after is given, only lines after said date will be returned, regardless of modification. - If until is given, only lines up to said date will be returned, regardless of modification. + If after is given, only lines from said date onwards will be returned, regardless of modification. + If until is given, only lines up to and including said date will be returned, regardless of modification. The LogLines should be in time order. """ @@ -420,8 +420,8 @@ """ Yields a series of naive datetime objects representing the logfiles that are available, in time order. - If after is given, only dates after said date will be returned - If until is given, only dates up to said date will be returned + If after is given, only dates from said date onwards will be returned + If until is given, only dates up to and including said date will be returned """ # listdir @@ -430,28 +430,26 @@ # sort filenames.sort() + + # iter files for filename in filenames : try : # parse date - date = datetime.datetime.strptime(filename, self.filename_fmt).replace(tzinfo=self.tz) + date = self.tz.localize(datetime.datetime.strptime(filename, self.filename_fmt)) except : # ignore continue else : - # ignore before? - if after and date < after : - continue - - # ignore after? - if until and date > until : - continue - - else : + if (not after or date >= after) and (not until or date <= until) : # yield yield date + + else : + # ignore + continue def _iter_date_reverse (self, dt=None) : """ diff -r e24da9a94ffb -r 0690d715385d scripts/search-index --- a/scripts/search-index Wed Feb 11 04:41:22 2009 +0200 +++ b/scripts/search-index Wed Feb 11 04:57:55 2009 +0200 @@ -311,7 +311,7 @@ if not options.quiet : print "Channel %s:" % channel.id - # no 'after' by default + # no 'from' by default after = None # path to our state file @@ -336,11 +336,8 @@ # parse timestamp after = utils.from_utc_timestamp(int(after_str)) - # one day backwards - after = after.replace(day=after.day - 1) - if not options.quiet : - print "\tContinuing earlier progress: after=%s" % after + print "\tContinuing earlier progress from %s" % after else : # ignore @@ -384,18 +381,18 @@ after = options.after if not options.quiet : - print "\tOnly including dates after %s" % after + print "\tOnly including dates from %s onwards" % after else : if not options.quiet : - print "\t[WARN] Ignoring --after because we found a tempfile" + print "\t[WARN] Ignoring --from because we found a tempfile" # only up to some specific date? if options.until : until = options.until if not options.quiet : - print "\tOnly including dates up to %s" % until + print "\tOnly including dates up to (and including) %s" % until else : # default to now until = None @@ -546,30 +543,58 @@ option_class = MyOption, ) - # define command-line arguments + # general options # # # # general = optparse.OptionGroup(parser, "General Options") - general.add_option('-h', "--help", dest="help", help="Show this help message and exit", action="store_true" ) - general.add_option( "--formatter", dest="formatter_name", help="LogFormatter to use", metavar="FMT", type="choice", default="irssi", - choices=[fmt_name for fmt_name in config.LOG_FORMATTERS.iterkeys()]) + general.add_option('-h', "--help", dest="help", help="Show this help message and exit", + action="store_true" ) - general.add_option( "--index", dest="index_path", help="Index database path", metavar="PATH", default="logs/index" ) - general.add_option( "--timezone", dest="timezone", help="Timezone for output", metavar="TZ", type="timezone", default=pytz.utc ) - general.add_option( "--force", dest="force", help="Force dangerous operation", action="store_true" ) - general.add_option( "--quiet", dest="quiet", help="Supress status messages", action="store_true" ) + general.add_option( "--formatter", dest="formatter_name", help="LogFormatter to use", + metavar="FMT", type="choice", default="irssi", + choices=[fmt_name for fmt_name in config.LOG_FORMATTERS.iterkeys()] ) + + general.add_option( "--index", dest="index_path", help="Index database path", + metavar="PATH", default="logs/index" ) + + general.add_option( "--timezone", dest="timezone", help="Timezone for output", + metavar="TZ", type="timezone", default=pytz.utc ) + + general.add_option( "--force", dest="force", help="Force dangerous operation", + action="store_true" ) + + general.add_option( "--quiet", dest="quiet", help="Supress status messages", + action="store_true" ) parser.add_option_group(general) + + # cmd_load options # # # # load = optparse.OptionGroup(parser, "Load Options") - load.add_option( "--skip-missing", dest="skip_missing", help="Skip missing logfiles", action="store_true" ) - load.add_option( "--create", dest="create", help="Create index database", action="store_true" ) + load.add_option( "--skip-missing", dest="skip_missing", help="Skip missing logfiles", + action="store_true" ) + + load.add_option( "--create", dest="create", help="Create index database", + action="store_true" ) parser.add_option_group(load) + + # cmd_autoload options # # # # autoload = optparse.OptionGroup(parser, "Autoload Options") - autoload.add_option( "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir", metavar="PATH", default="logs/autoload-state" ) - autoload.add_option( "--after", dest="after", help="Only autoload logfiles after the given date", metavar="DATE", type="date", action="parse_date", default=None ) - autoload.add_option( "--until", dest="until", help="Only autoload logfiles up to the given date", metavar="DATE", type="date", action="parse_date", default=None ) - autoload.add_option( "--reload", dest="reload", help="Force reload lines", action="store_true" ) - autoload.add_option( "--reset", dest="reset", help="Reset old autload state", action="store_true" ) - autoload.add_option( "--ignore-resume", dest="ignore_resume", help="Do not try and resume interrupted autoload", action="store_true" ) + autoload.add_option( "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir", + metavar="PATH", default="logs/autoload-state" ) + + autoload.add_option( "--from", dest="after", help="Only autoload logfiles from the given date on", + metavar="DATE", type="date", action="parse_date", default=None ) + + autoload.add_option( "--until", dest="until", help="Only autoload logfiles up to (and including) the given date", + metavar="DATE", type="date", action="parse_date", default=None ) + + autoload.add_option( "--reload", dest="reload", help="Force reload lines", + action="store_true" ) + + autoload.add_option( "--reset", dest="reset", help="Reset old autload state", + action="store_true" ) + + autoload.add_option( "--ignore-resume", dest="ignore_resume", help="Do not try and resume interrupted autoload", + action="store_true" ) parser.add_option_group(autoload) # parse