scripts/search-index
changeset 94 6673de9bc911
parent 93 48fca00689e3
child 95 ebdbda3dd5d0
equal deleted inserted replaced
93:48fca00689e3 94:6673de9bc911
   265         if not options.quiet :
   265         if not options.quiet :
   266             print "Channel %s:" % channel.id,
   266             print "Channel %s:" % channel.id,
   267 
   267 
   268         # path to our state file
   268         # path to our state file
   269         statefile_path = os.path.join(options.autoload_state_path, 'chan-%s' % channel.id)
   269         statefile_path = os.path.join(options.autoload_state_path, 'chan-%s' % channel.id)
   270         
   270        
   271         # override?
   271         # override?
   272         if options.reload :
   272         if options.reload :
   273             # load all
   273             # load all
   274             mtime = None
   274             mtime = None
   275 
   275 
   289             # unknown, load all
   289             # unknown, load all
   290             mtime = None
   290             mtime = None
   291             
   291             
   292             if not options.quiet :
   292             if not options.quiet :
   293                 print "no previous load state:",
   293                 print "no previous load state:",
       
   294  
       
   295         # only after some specific date?
       
   296         if options.after :
       
   297             after = options.after
       
   298             
       
   299             print "after=%s:" % after,
       
   300 
       
   301         else :
       
   302             after = None
   294         
   303         
   295         # get lines
   304         # get lines
   296         lines = channel.source.get_modified(mtime)
   305         lines = channel.source.get_modified(mtime, after)
   297         
   306         
   298         # insert
   307         # insert
   299         if not options.quiet :
   308         if not options.quiet :
   300             print "inserting..."
   309             print "inserting..."
   301         
   310         
   360         usage           = "%prog [options] <command> [ ... ]",
   369         usage           = "%prog [options] <command> [ ... ]",
   361         add_help_option = False,
   370         add_help_option = False,
   362     )
   371     )
   363 
   372 
   364     # define command-line arguments
   373     # define command-line arguments
   365     parser.add_option('-h', "--help",           dest="help",            help="Show this help message and exit",     action="store_true")
   374     parser.add_option('-h', "--help",           dest="help",            help="Show this help message and exit",     action="store_true" )
   366     parser.add_option('-F', "--formatter",      dest="formatter_name",  help="LogFormatter to use",                 metavar="FMT",  type="choice", default="irssi",
   375     parser.add_option('-F', "--formatter",      dest="formatter_name",  help="LogFormatter to use",                 metavar="FMT",  type="choice", default="irssi",
   367         choices=[fmt_name for fmt_name in config.LOG_FORMATTERS.iterkeys()])
   376         choices=[fmt_name for fmt_name in config.LOG_FORMATTERS.iterkeys()])
   368 
   377 
   369     parser.add_option('-I', "--index",          dest="index_path",      help="Index database path",                 metavar="PATH", default="logs/index")
   378     parser.add_option('-I', "--index",          dest="index_path",      help="Index database path",                 metavar="PATH", default="logs/index"            )
   370     parser.add_option(      "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir",      metavar="PATH", default="logs/autoload-state")
   379     parser.add_option(      "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir",      metavar="PATH", default="logs/autoload-state"   )
   371     parser.add_option('-Z', "--timezone",       dest="tz_name",         help="Timezone for output",                 metavar="TZ",   default="UTC")
   380     parser.add_option(      "--after",          dest="after",           help="Only autoload logfiles after the given date", metavar="DATE", default=None            )
   372     parser.add_option('-f', "--force",          dest="force",           help="Force dangerous operation",           action="store_true")
   381     parser.add_option('-Z', "--timezone",       dest="tz_name",         help="Timezone for output",                 metavar="TZ",   default="UTC"                   )
   373     parser.add_option(      "--create",         dest="create",          help="Create index database",               action="store_true")
   382     parser.add_option('-f', "--force",          dest="force",           help="Force dangerous operation",           action="store_true" )
   374     parser.add_option(      "--skip-missing",   dest="skip_missing",    help="Skip missing logfiles",               action="store_true")
   383     parser.add_option(      "--create",         dest="create",          help="Create index database",               action="store_true" )
   375     parser.add_option(      "--reload",         dest="reload",          help="Force reload lines",                  action="store_true")
   384     parser.add_option(      "--skip-missing",   dest="skip_missing",    help="Skip missing logfiles",               action="store_true" )
   376     parser.add_option(      "--quiet",          dest="quiet",           help="Supress status messages",             action="store_true")
   385     parser.add_option(      "--reload",         dest="reload",          help="Force reload lines",                  action="store_true" )
       
   386     parser.add_option(      "--quiet",          dest="quiet",           help="Supress status messages",             action="store_true" )
   377 
   387 
   378     # parse
   388     # parse
   379     options, args = parser.parse_args(argv[1:])
   389     options, args = parser.parse_args(argv[1:])
   380 
   390 
   381     # postprocess stuff
   391     # postprocess stuff
   382     options._parser = parser
   392     options._parser = parser
   383     options.tz = pytz.timezone(options.tz_name)
   393     options.tz = pytz.timezone(options.tz_name)
   384     options.formatter = config.LOG_FORMATTERS[options.formatter_name](options.tz, "%H:%M:%S", None, None)
   394     options.formatter = config.LOG_FORMATTERS[options.formatter_name](options.tz, "%H:%M:%S", None, None)
   385 
   395 
       
   396     if options.after :
       
   397         options.after = _parse_date(options, options.after)
       
   398 
   386     # special-case --help
   399     # special-case --help
   387     if options.help :
   400     if options.help :
   388         return cmd_help(options, *args)
   401         return cmd_help(options, *args)
   389     
   402     
   390     # must have at least the command argument
   403     # must have at least the command argument