scripts/search-index
changeset 106 0690d715385d
parent 105 e24da9a94ffb
child 121 86aebc9cb60b
equal deleted inserted replaced
105:e24da9a94ffb 106:0690d715385d
   309     # iterate channels
   309     # iterate channels
   310     for channel in channels :
   310     for channel in channels :
   311         if not options.quiet :
   311         if not options.quiet :
   312             print "Channel %s:" % channel.id
   312             print "Channel %s:" % channel.id
   313 
   313 
   314         # no 'after' by default
   314         # no 'from' by default
   315         after = None
   315         after = None
   316 
   316 
   317         # path to our state file
   317         # path to our state file
   318         statefile_path = os.path.join(options.autoload_state_path, 'chan-%s' % channel.id)
   318         statefile_path = os.path.join(options.autoload_state_path, 'chan-%s' % channel.id)
   319         statefile_tmppath = statefile_path + '.tmp'
   319         statefile_tmppath = statefile_path + '.tmp'
   334 
   334 
   335             if after_str :
   335             if after_str :
   336                 # parse timestamp
   336                 # parse timestamp
   337                 after = utils.from_utc_timestamp(int(after_str))
   337                 after = utils.from_utc_timestamp(int(after_str))
   338 
   338 
   339                 # one day backwards
       
   340                 after = after.replace(day=after.day - 1)
       
   341 
       
   342                 if not options.quiet :
   339                 if not options.quiet :
   343                     print "\tContinuing earlier progress: after=%s" % after
   340                     print "\tContinuing earlier progress from %s" % after
   344 
   341 
   345             else :
   342             else :
   346                 # ignore
   343                 # ignore
   347                 if not options.quiet :
   344                 if not options.quiet :
   348                     print "\t[WARN] Ignoring empty temporary statefile"
   345                     print "\t[WARN] Ignoring empty temporary statefile"
   382             # use unless read from tempfile
   379             # use unless read from tempfile
   383             if not after :
   380             if not after :
   384                 after = options.after
   381                 after = options.after
   385                
   382                
   386                 if not options.quiet :
   383                 if not options.quiet :
   387                     print "\tOnly including dates after %s" % after
   384                     print "\tOnly including dates from %s onwards" % after
   388             
   385             
   389             else :
   386             else :
   390                 if not options.quiet :
   387                 if not options.quiet :
   391                     print "\t[WARN] Ignoring --after because we found a tempfile"
   388                     print "\t[WARN] Ignoring --from because we found a tempfile"
   392             
   389             
   393         # only up to some specific date?
   390         # only up to some specific date?
   394         if options.until :
   391         if options.until :
   395             until = options.until
   392             until = options.until
   396 
   393 
   397             if not options.quiet :
   394             if not options.quiet :
   398                 print "\tOnly including dates up to %s" % until
   395                 print "\tOnly including dates up to (and including) %s" % until
   399         else :
   396         else :
   400             # default to now
   397             # default to now
   401             until = None
   398             until = None
   402 
   399 
   403         # get lines
   400         # get lines
   544         usage           = "%prog [options] <command> [ ... ]",
   541         usage           = "%prog [options] <command> [ ... ]",
   545         add_help_option = False,
   542         add_help_option = False,
   546         option_class    = MyOption,
   543         option_class    = MyOption,
   547     )
   544     )
   548 
   545 
   549     # define command-line arguments
   546     # general options       #                   #                       #                                   #
   550     general = optparse.OptionGroup(parser, "General Options")
   547     general = optparse.OptionGroup(parser, "General Options")
   551     general.add_option('-h', "--help",           dest="help",            help="Show this help message and exit",     action="store_true"    )
   548     general.add_option('-h', "--help",          dest="help",            help="Show this help message and exit",     
   552     general.add_option(      "--formatter",      dest="formatter_name",  help="LogFormatter to use",                 metavar="FMT",  type="choice", default="irssi",
   549                                                 action="store_true"                                         )
   553         choices=[fmt_name for fmt_name in config.LOG_FORMATTERS.iterkeys()])
   550 
   554 
   551     general.add_option(     "--formatter",      dest="formatter_name",  help="LogFormatter to use",                 
   555     general.add_option(      "--index",          dest="index_path",      help="Index database path",                 metavar="PATH", default="logs/index"               )
   552             metavar="FMT",  type="choice",                              default="irssi",
   556     general.add_option(      "--timezone",       dest="timezone",        help="Timezone for output",                 metavar="TZ",   type="timezone", default=pytz.utc  )
   553             choices=[fmt_name for fmt_name in config.LOG_FORMATTERS.iterkeys()]                             )
   557     general.add_option(      "--force",          dest="force",           help="Force dangerous operation",           action="store_true"    )
   554 
   558     general.add_option(      "--quiet",          dest="quiet",           help="Supress status messages",             action="store_true"    )
   555     general.add_option(     "--index",          dest="index_path",      help="Index database path",                 
       
   556             metavar="PATH",                                             default="logs/index"                )
       
   557 
       
   558     general.add_option(     "--timezone",       dest="timezone",        help="Timezone for output",                 
       
   559             metavar="TZ",   type="timezone",                            default=pytz.utc                    )
       
   560 
       
   561     general.add_option(     "--force",          dest="force",           help="Force dangerous operation",           
       
   562                                                 action="store_true"                                         )
       
   563 
       
   564     general.add_option(     "--quiet",          dest="quiet",           help="Supress status messages",             
       
   565                                                 action="store_true"                                         )
   559     parser.add_option_group(general)
   566     parser.add_option_group(general)
   560     
   567     
       
   568 
       
   569     # cmd_load options      #                   #                       #                                   #
   561     load = optparse.OptionGroup(parser, "Load Options")
   570     load = optparse.OptionGroup(parser, "Load Options")
   562     load.add_option(      "--skip-missing",   dest="skip_missing",    help="Skip missing logfiles",               action="store_true"       )
   571     load.add_option(        "--skip-missing",   dest="skip_missing",    help="Skip missing logfiles",
   563     load.add_option(      "--create",         dest="create",          help="Create index database",               action="store_true"       )
   572                                                 action="store_true"                                         )
       
   573 
       
   574     load.add_option(        "--create",         dest="create",          help="Create index database", 
       
   575                                                 action="store_true"                                         )
   564     parser.add_option_group(load)
   576     parser.add_option_group(load)
   565     
   577     
       
   578 
       
   579     # cmd_autoload options  #                   #                       #                                   #
   566     autoload = optparse.OptionGroup(parser, "Autoload Options")
   580     autoload = optparse.OptionGroup(parser, "Autoload Options")
   567     autoload.add_option(      "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir",      metavar="PATH", default="logs/autoload-state"   )
   581     autoload.add_option(    "--autoload-state", dest="autoload_state_path", help="Path to autoload state dir",      
   568     autoload.add_option(      "--after",          dest="after",           help="Only autoload logfiles after the given date", metavar="DATE", type="date", action="parse_date", default=None )
   582             metavar="PATH",                                             default="logs/autoload-state"       )
   569     autoload.add_option(      "--until",          dest="until",           help="Only autoload logfiles up to the given date", metavar="DATE", type="date", action="parse_date", default=None )
   583 
   570     autoload.add_option(      "--reload",         dest="reload",          help="Force reload lines",                  action="store_true"   )
   584     autoload.add_option(    "--from",           dest="after",           help="Only autoload logfiles from the given date on", 
   571     autoload.add_option(      "--reset",          dest="reset",           help="Reset old autload state",             action="store_true"   )
   585             metavar="DATE", type="date",        action="parse_date",    default=None                        )
   572     autoload.add_option(      "--ignore-resume",  dest="ignore_resume",   help="Do not try and resume interrupted autoload",  action="store_true" )
   586 
       
   587     autoload.add_option(    "--until",          dest="until",           help="Only autoload logfiles up to (and including) the given date",  
       
   588             metavar="DATE", type="date",        action="parse_date",    default=None                        )
       
   589 
       
   590     autoload.add_option(    "--reload",         dest="reload",          help="Force reload lines",
       
   591                                                 action="store_true"                                         )
       
   592 
       
   593     autoload.add_option(    "--reset",          dest="reset",           help="Reset old autload state",
       
   594                                                 action="store_true"                                         )
       
   595 
       
   596     autoload.add_option(    "--ignore-resume",  dest="ignore_resume",   help="Do not try and resume interrupted autoload",  
       
   597                                                 action="store_true"                                         )
   573     parser.add_option_group(autoload)
   598     parser.add_option_group(autoload)
   574 
   599 
   575     # parse
   600     # parse
   576     options, args = parser.parse_args(argv[1:])
   601     options, args = parser.parse_args(argv[1:])
   577 
   602