scripts/search-index
changeset 121 86aebc9cb60b
parent 106 0690d715385d
equal deleted inserted replaced
119:df859bfdd3be 121:86aebc9cb60b
   195         
   195         
   196         # handle errors
   196         # handle errors
   197         except CommandError, e :
   197         except CommandError, e :
   198             # skip?
   198             # skip?
   199             if options.skip_missing :
   199             if options.skip_missing :
   200                 print "[ERROR] %s" % (date_name, e)
   200                 if not options.quiet :
       
   201                     print "[ERROR] %s" % (date_name, e)
   201                 continue
   202                 continue
   202 
   203 
   203             else :
   204             else :
   204                 raise
   205                 raise
   205         
   206         
   206         # get the set of days
   207         # get the set of days
   207         days = list(channel.source.get_month_days(month))
   208         days = list(channel.source.get_month_days(month))
   208 
   209         
   209         print "Loading %d days of logs:" % (len(days))
   210         if not options.quiet :
       
   211             print "Loading %d days of logs:" % (len(days))
   210 
   212 
   211         # load each day
   213         # load each day
   212         for date in days :
   214         for date in days :
   213             # convert to datetime
   215             # convert to datetime
   214             dt = datetime.datetime.combine(date, datetime.time(0)).replace(tzinfo=channel.source.tz)
   216             dt = datetime.datetime.combine(date, datetime.time(0)).replace(tzinfo=channel.source.tz)
   302         channels = [config.LOG_CHANNELS.lookup(channel_name) for channel_name in channel_names]
   304         channels = [config.LOG_CHANNELS.lookup(channel_name) for channel_name in channel_names]
   303     
   305     
   304     # reset autoload state?
   306     # reset autoload state?
   305     if options.reset :
   307     if options.reset :
   306         _autoload_reset(options, channels)
   308         _autoload_reset(options, channels)
   307         print
   309         if not options.quiet :
       
   310             print
   308 
   311 
   309     # iterate channels
   312     # iterate channels
   310     for channel in channels :
   313     for channel in channels :
   311         if not options.quiet :
   314         if not options.quiet :
   312             print "Channel %s:" % channel.id
   315             print "Channel %s:" % channel.id
   421 
   424 
   422         # close+delete tempfile
   425         # close+delete tempfile
   423         statefile_tmp.close()
   426         statefile_tmp.close()
   424         os.remove(statefile_tmppath)
   427         os.remove(statefile_tmppath)
   425         
   428         
   426         print
   429         if not options.quiet :
       
   430             print
   427     
   431     
   428     # done
   432     # done
   429     return
   433     return
   430 
   434 
   431 def cmd_help (options, *args) :
   435 def cmd_help (options, *args) :
   547     general = optparse.OptionGroup(parser, "General Options")
   551     general = optparse.OptionGroup(parser, "General Options")
   548     general.add_option('-h', "--help",          dest="help",            help="Show this help message and exit",     
   552     general.add_option('-h', "--help",          dest="help",            help="Show this help message and exit",     
   549                                                 action="store_true"                                         )
   553                                                 action="store_true"                                         )
   550 
   554 
   551     general.add_option(     "--formatter",      dest="formatter_name",  help="LogFormatter to use",                 
   555     general.add_option(     "--formatter",      dest="formatter_name",  help="LogFormatter to use",                 
   552             metavar="FMT",  type="choice",                              default="irssi",
   556             metavar="FMT",  type="choice",                              default=config.PREF_FORMATTER_DEFAULT.name,
   553             choices=[fmt_name for fmt_name in config.LOG_FORMATTERS.iterkeys()]                             )
   557             choices=[fmt_name for fmt_name in config.LOG_FORMATTERS.iterkeys()]                             )
   554 
   558 
   555     general.add_option(     "--index",          dest="index_path",      help="Index database path",                 
   559     general.add_option(     "--index",          dest="index_path",      help="Index database path",                 
   556             metavar="PATH",                                             default="logs/index"                )
   560             metavar="PATH",                                             default=config.SEARCH_INDEX_PATH    )
   557 
   561 
   558     general.add_option(     "--timezone",       dest="timezone",        help="Timezone for output",                 
   562     general.add_option(     "--timezone",       dest="timezone",        help="Timezone for output",                 
   559             metavar="TZ",   type="timezone",                            default=pytz.utc                    )
   563             metavar="TZ",   type="timezone",                            default=pytz.utc                    )
   560 
   564 
   561     general.add_option(     "--force",          dest="force",           help="Force dangerous operation",           
   565     general.add_option(     "--force",          dest="force",           help="Force dangerous operation",           
   577     
   581     
   578 
   582 
   579     # cmd_autoload options  #                   #                       #                                   #
   583     # cmd_autoload options  #                   #                       #                                   #
   580     autoload = optparse.OptionGroup(parser, "Autoload Options")
   584     autoload = optparse.OptionGroup(parser, "Autoload Options")
   581     autoload.add_option(    "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir",      
   585     autoload.add_option(    "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir",      
   582             metavar="PATH",                                             default="logs/autoload-state"       )
   586             metavar="PATH",                                             default=config.SEARCH_AUTOINDEX_PATH)
   583 
   587 
   584     autoload.add_option(    "--from",           dest="after",           help="Only autoload logfiles from the given date on", 
   588     autoload.add_option(    "--from",           dest="after",           help="Only autoload logfiles from the given date on", 
   585             metavar="DATE", type="date",        action="parse_date",    default=None                        )
   589             metavar="DATE", type="date",        action="parse_date",    default=None                        )
   586 
   590 
   587     autoload.add_option(    "--until",          dest="until",           help="Only autoload logfiles up to (and including) the given date",  
   591     autoload.add_option(    "--until",          dest="until",           help="Only autoload logfiles up to (and including) the given date",