--- a/log_parser.py Wed Feb 11 04:04:55 2009 +0200
+++ b/log_parser.py Wed Feb 11 04:14:22 2009 +0200
@@ -69,7 +69,8 @@
( LogTypes.JOIN, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has joined ' + _CHAN ),
( LogTypes.PART, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has left ' + _CHAN + ' \[(?P<message>.*?)\]' ),
( LogTypes.KICK, _TS + r' -!- ' + _TARGET + ' was kicked from ' + _CHAN + ' by ' + _NICK + ' \[(?P<message>.*?)\]' ),
- ( LogTypes.MODE, _TS + r' -!- mode/' + _CHAN + ' \[(?P<mode>.+?)\] by (?P<nickname>\S+)' ),
+ # XXX: use hostname instead of nickname for ServerMode
+ ( LogTypes.MODE, _TS + r' -!- (mode|ServerMode)/' + _CHAN + ' \[(?P<mode>.+?)\] by (?P<nickname>\S+)' ),
( LogTypes.NICK, _TS + r' -!- ' + _NICK + ' is now known as (?P<target>\S+)' ),
( LogTypes.QUIT, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has quit \[(?P<message>.*?)\]' ),
( LogTypes.TOPIC, _TS + r' -!- (' + _NICK + ' changed the topic of ' + _CHAN + ' to: (?P<topic>.*)|Topic unset by ' + _NICK2 + ' on ' + _CHAN2 + ')' ),
--- a/log_source.py Wed Feb 11 04:04:55 2009 +0200
+++ b/log_source.py Wed Feb 11 04:14:22 2009 +0200
@@ -162,13 +162,14 @@
abstract
- def get_modified (self, dt=None, after=None) :
+ def get_modified (self, dt=None, after=None, until=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 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.
The LogLines should be in time order.
"""
@@ -415,11 +416,12 @@
else :
raise
- def _iter_logfile_dates (self, after=None) :
+ def _iter_logfile_dates (self, after=None, until=None) :
"""
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
"""
# listdir
@@ -439,8 +441,12 @@
continue
else :
+ # ignore before?
+ if after and date < after :
+ continue
+
# ignore after?
- if after and date < after :
+ if until and date > until :
continue
else :
@@ -617,13 +623,13 @@
# valid
yield dt.date()
- def get_modified (self, dt=None, after=None) :
+ def get_modified (self, dt=None, after=None, until=None) :
"""
Returns the contents off all logfiles with mtimes past the given date
"""
# iterate through all available logfiles in date order, as datetimes, from the given date on
- for log_date in self._iter_logfile_dates(after) :
+ for log_date in self._iter_logfile_dates(after, until) :
# compare against dt?
if dt :
# stat
--- a/scripts/search-index Wed Feb 11 04:04:55 2009 +0200
+++ b/scripts/search-index Wed Feb 11 04:14:22 2009 +0200
@@ -69,8 +69,8 @@
# count
count += 1
- # final count
- if date :
+ # final count?
+ if date and count :
yield date, count
def _insert_lines (index, options, channel, lines) :
@@ -381,14 +381,26 @@
# use unless read from tempfile
if not after :
after = options.after
-
- print "\tUsing after = %s" % after
+
+ if not options.quiet :
+ print "\tOnly including dates after %s" % after
else :
- print "\tIgnoring --after because we found a tempfile"
+ if not options.quiet :
+ print "\t[WARN] Ignoring --after 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
+ else :
+ # default to now
+ until = None
# get lines
- lines = channel.source.get_modified(mtime, after)
+ lines = channel.source.get_modified(mtime, after, until)
# insert
if not options.quiet :
@@ -483,6 +495,7 @@
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( "--until", dest="until", help="Only autoload logfiles up to 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" )
@@ -500,9 +513,13 @@
options.tz = pytz.timezone(options.tz_name)
options.formatter = config.LOG_FORMATTERS[options.formatter_name](options.tz, "%H:%M:%S", None, None)
+ # XXX: convert to custom types
if options.after :
options.after = _parse_date(options, options.after)
+ if options.until :
+ options.until = _parse_date(options, options.until)
+
# special-case --help
if options.help :
return cmd_help(options, *args)