# HG changeset patch # User Tero Marttila # Date 1234311371 -7200 # Node ID 6673de9bc9119b438481e03bf3ddca96627a8758 # Parent 48fca00689e3089d83f5b26ff439de2a91c95884 implement --after for autoload diff -r 48fca00689e3 -r 6673de9bc911 log_source.py --- a/log_source.py Wed Feb 11 02:07:07 2009 +0200 +++ b/log_source.py Wed Feb 11 02:16:11 2009 +0200 @@ -162,11 +162,13 @@ abstract - def get_modified (self, dt=None) : + def get_modified (self, dt=None, after=None) : """ Returns a sequence of LogLines that may have been *modified* from their old values since the given datetime. - If the datetime is not given, *all* lines are returned + 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. The LogLines should be in time order. """ @@ -413,9 +415,11 @@ else : raise - def _iter_logfile_dates (self) : + def _iter_logfile_dates (self, after=None) : """ - Yields a series of naive datetime objects representing the logfiles that are available, in time order + 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 """ # listdir @@ -427,12 +431,21 @@ # iter files for filename in filenames : try : - # parse date + yield - yield datetime.datetime.strptime(filename, self.filename_fmt).replace(tzinfo=self.tz) + # parse date + date = datetime.datetime.strptime(filename, self.filename_fmt).replace(tzinfo=self.tz) except : # ignore continue + + else : + # ignore after? + if after and date < after : + continue + + else : + # yield + yield date def _iter_date_reverse (self, dt=None) : """ @@ -604,13 +617,13 @@ # valid yield dt.date() - def get_modified (self, dt=None) : + def get_modified (self, dt=None, after=None) : """ Returns the contents off all logfiles with mtimes past the given date """ - - # iterate through all available logfiles in date order, as datetimes - for log_date in self._iter_logfile_dates() : + + # iterate through all available logfiles in date order, as datetimes, from the given date on + for log_date in self._iter_logfile_dates(after) : # compare against dt? if dt : # stat diff -r 48fca00689e3 -r 6673de9bc911 scripts/search-index --- a/scripts/search-index Wed Feb 11 02:07:07 2009 +0200 +++ b/scripts/search-index Wed Feb 11 02:16:11 2009 +0200 @@ -267,7 +267,7 @@ # path to our state file statefile_path = os.path.join(options.autoload_state_path, 'chan-%s' % channel.id) - + # override? if options.reload : # load all @@ -291,9 +291,18 @@ if not options.quiet : print "no previous load state:", + + # only after some specific date? + if options.after : + after = options.after + + print "after=%s:" % after, + + else : + after = None # get lines - lines = channel.source.get_modified(mtime) + lines = channel.source.get_modified(mtime, after) # insert if not options.quiet : @@ -362,18 +371,19 @@ ) # define command-line arguments - parser.add_option('-h', "--help", dest="help", help="Show this help message and exit", action="store_true") + parser.add_option('-h', "--help", dest="help", help="Show this help message and exit", action="store_true" ) parser.add_option('-F', "--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()]) - parser.add_option('-I', "--index", dest="index_path", help="Index database path", metavar="PATH", default="logs/index") - parser.add_option( "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir", metavar="PATH", default="logs/autoload-state") - parser.add_option('-Z', "--timezone", dest="tz_name", help="Timezone for output", metavar="TZ", default="UTC") - parser.add_option('-f', "--force", dest="force", help="Force dangerous operation", action="store_true") - parser.add_option( "--create", dest="create", help="Create index database", action="store_true") - parser.add_option( "--skip-missing", dest="skip_missing", help="Skip missing logfiles", action="store_true") - parser.add_option( "--reload", dest="reload", help="Force reload lines", action="store_true") - parser.add_option( "--quiet", dest="quiet", help="Supress status messages", action="store_true") + parser.add_option('-I', "--index", dest="index_path", help="Index database path", metavar="PATH", default="logs/index" ) + parser.add_option( "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir", metavar="PATH", default="logs/autoload-state" ) + parser.add_option( "--after", dest="after", help="Only autoload logfiles after the given date", metavar="DATE", default=None ) + parser.add_option('-Z', "--timezone", dest="tz_name", help="Timezone for output", metavar="TZ", default="UTC" ) + parser.add_option('-f', "--force", dest="force", help="Force dangerous operation", action="store_true" ) + parser.add_option( "--create", dest="create", help="Create index database", action="store_true" ) + parser.add_option( "--skip-missing", dest="skip_missing", help="Skip missing logfiles", action="store_true" ) + parser.add_option( "--reload", dest="reload", help="Force reload lines", action="store_true" ) + parser.add_option( "--quiet", dest="quiet", help="Supress status messages", action="store_true" ) # parse options, args = parser.parse_args(argv[1:]) @@ -383,6 +393,9 @@ options.tz = pytz.timezone(options.tz_name) options.formatter = config.LOG_FORMATTERS[options.formatter_name](options.tz, "%H:%M:%S", None, None) + if options.after : + options.after = _parse_date(options, options.after) + # special-case --help if options.help : return cmd_help(options, *args)