scripts/search-index
changeset 103 0e829e6275dc
parent 101 f5f53cc0ce16
child 104 34c65a8c8b94
equal deleted inserted replaced
102:e396613bc873 103:0e829e6275dc
    67         index.insert_line(channel, line)
    67         index.insert_line(channel, line)
    68 
    68 
    69         # count
    69         # count
    70         count += 1
    70         count += 1
    71     
    71     
    72     # final count
    72     # final count?
    73     if date :
    73     if date and count :
    74         yield date, count
    74         yield date, count
    75 
    75 
    76 def _insert_lines (index, options, channel, lines) :
    76 def _insert_lines (index, options, channel, lines) :
    77     """
    77     """
    78         Insert the given lines into the index.
    78         Insert the given lines into the index.
   379         # only after some specific date?
   379         # only after some specific date?
   380         if options.after :
   380         if options.after :
   381             # use unless read from tempfile
   381             # use unless read from tempfile
   382             if not after :
   382             if not after :
   383                 after = options.after
   383                 after = options.after
   384                 
   384                
   385                 print "\tUsing after = %s" % after
   385                 if not options.quiet :
       
   386                     print "\tOnly including dates after %s" % after
   386             
   387             
   387             else :
   388             else :
   388                 print "\tIgnoring --after because we found a tempfile"
   389                 if not options.quiet :
       
   390                     print "\t[WARN] Ignoring --after because we found a tempfile"
       
   391         
       
   392         # only up to some specific date?
       
   393         if options.until :
       
   394             until = options.until
       
   395 
       
   396             if not options.quiet :
       
   397                 print "\tOnly including dates up to %s" % until
       
   398         else :
       
   399             # default to now
       
   400             until = None
   389 
   401 
   390         # get lines
   402         # get lines
   391         lines = channel.source.get_modified(mtime, after)
   403         lines = channel.source.get_modified(mtime, after, until)
   392         
   404         
   393         # insert
   405         # insert
   394         if not options.quiet :
   406         if not options.quiet :
   395             print "\tLoading and inserting..."
   407             print "\tLoading and inserting..."
   396             print
   408             print
   481         choices=[fmt_name for fmt_name in config.LOG_FORMATTERS.iterkeys()])
   493         choices=[fmt_name for fmt_name in config.LOG_FORMATTERS.iterkeys()])
   482 
   494 
   483     parser.add_option('-I', "--index",          dest="index_path",      help="Index database path",                 metavar="PATH", default="logs/index"            )
   495     parser.add_option('-I', "--index",          dest="index_path",      help="Index database path",                 metavar="PATH", default="logs/index"            )
   484     parser.add_option(      "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir",      metavar="PATH", default="logs/autoload-state"   )
   496     parser.add_option(      "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir",      metavar="PATH", default="logs/autoload-state"   )
   485     parser.add_option(      "--after",          dest="after",           help="Only autoload logfiles after the given date", metavar="DATE", default=None            )
   497     parser.add_option(      "--after",          dest="after",           help="Only autoload logfiles after the given date", metavar="DATE", default=None            )
       
   498     parser.add_option(      "--until",          dest="until",           help="Only autoload logfiles up to the given date", metavar="DATE", default=None            )
   486     parser.add_option('-Z', "--timezone",       dest="tz_name",         help="Timezone for output",                 metavar="TZ",   default="UTC"                   )
   499     parser.add_option('-Z', "--timezone",       dest="tz_name",         help="Timezone for output",                 metavar="TZ",   default="UTC"                   )
   487     parser.add_option('-f', "--force",          dest="force",           help="Force dangerous operation",           action="store_true" )
   500     parser.add_option('-f', "--force",          dest="force",           help="Force dangerous operation",           action="store_true" )
   488     parser.add_option(      "--create",         dest="create",          help="Create index database",               action="store_true" )
   501     parser.add_option(      "--create",         dest="create",          help="Create index database",               action="store_true" )
   489     parser.add_option(      "--skip-missing",   dest="skip_missing",    help="Skip missing logfiles",               action="store_true" )
   502     parser.add_option(      "--skip-missing",   dest="skip_missing",    help="Skip missing logfiles",               action="store_true" )
   490     parser.add_option(      "--reload",         dest="reload",          help="Force reload lines",                  action="store_true" )
   503     parser.add_option(      "--reload",         dest="reload",          help="Force reload lines",                  action="store_true" )
   498     # postprocess stuff
   511     # postprocess stuff
   499     options._parser = parser
   512     options._parser = parser
   500     options.tz = pytz.timezone(options.tz_name)
   513     options.tz = pytz.timezone(options.tz_name)
   501     options.formatter = config.LOG_FORMATTERS[options.formatter_name](options.tz, "%H:%M:%S", None, None)
   514     options.formatter = config.LOG_FORMATTERS[options.formatter_name](options.tz, "%H:%M:%S", None, None)
   502 
   515 
       
   516     # XXX: convert to custom types
   503     if options.after :
   517     if options.after :
   504         options.after = _parse_date(options, options.after)
   518         options.after = _parse_date(options, options.after)
       
   519 
       
   520     if options.until :
       
   521         options.until = _parse_date(options, options.until)
   505 
   522 
   506     # special-case --help
   523     # special-case --help
   507     if options.help :
   524     if options.help :
   508         return cmd_help(options, *args)
   525         return cmd_help(options, *args)
   509     
   526