scripts/search-index
changeset 100 147be2910b02
parent 99 8719ac564b22
child 101 f5f53cc0ce16
equal deleted inserted replaced
99:8719ac564b22 100:147be2910b02
   280         after = None
   280         after = None
   281 
   281 
   282         # path to our state file
   282         # path to our state file
   283         statefile_path = os.path.join(options.autoload_state_path, 'chan-%s' % channel.id)
   283         statefile_path = os.path.join(options.autoload_state_path, 'chan-%s' % channel.id)
   284         statefile_tmppath = statefile_path + '.tmp'
   284         statefile_tmppath = statefile_path + '.tmp'
       
   285 
       
   286         # does it exist?
       
   287         have_tmpfile = os.path.exists(statefile_tmppath)
   285         
   288         
   286         # do we have a tempfile from a previous crash?
   289         # do we have a tempfile from a previous crash?
   287         if os.path.exists(statefile_tmppath) :
   290         if have_tmpfile and not options.ignore_resume :
   288             # first, open it...
   291             # first, open it...
   289             statefile_tmp = open(statefile_tmppath, 'r+')
   292             statefile_tmp = open(statefile_tmppath, 'r+')
   290 
   293 
   291             # ... then lock it
   294             # ... then lock it
   292             fcntl.lockf(statefile_tmp, fcntl.LOCK_EX | fcntl.LOCK_NB)
   295             fcntl.lockf(statefile_tmp, fcntl.LOCK_EX | fcntl.LOCK_NB)
   293             
   296             
   294             # read after timestamp
   297             # read after timestamp
   295             after_str = statefile_tmp.read().rstrip()
   298             after_str = statefile_tmp.read().rstrip()
   296 
   299 
   297             if after_str :
   300             if after_str :
   298                 # XXX: one day backwards
   301                 # parse timestamp
   299                 after = utils.from_utc_timestamp(int(after_str))
   302                 after = utils.from_utc_timestamp(int(after_str))
       
   303 
       
   304                 # one day backwards
       
   305                 after = after.replace(day=after.day - 1)
   300 
   306 
   301                 if not options.quiet :
   307                 if not options.quiet :
   302                     print "\tContinuing earlier progress: after=%s" % after
   308                     print "\tContinuing earlier progress: after=%s" % after
   303 
   309 
   304             else :
   310             else :
   305                 # ignore
   311                 # ignore
   306                 if not options.quiet :
   312                 if not options.quiet :
   307                     print "\tIgnoring empty temporary statefile"
   313                     print "\t[WARN] Ignoring empty temporary statefile"
   308 
   314 
   309         else :
   315         else :
       
   316             # warn about old tmpfile that was ignored
       
   317             if have_tmpfile and not options.quiet :
       
   318                 print "\t[WARN] Ignoring old tmpfile state"
       
   319 
   310             # open new tempfile
   320             # open new tempfile
   311             statefile_tmp = open(statefile_tmppath, 'w')
   321             statefile_tmp = open(statefile_tmppath, 'w')
   312             
   322             
   313             # lock
   323             # lock
   314             fcntl.lockf(statefile_tmp, fcntl.LOCK_EX | fcntl.LOCK_NB)
   324             fcntl.lockf(statefile_tmp, fcntl.LOCK_EX | fcntl.LOCK_NB)
   328 
   338 
   329             if mtime and not options.quiet :
   339             if mtime and not options.quiet :
   330                 print "\tLast load time was %s" % mtime
   340                 print "\tLast load time was %s" % mtime
   331 
   341 
   332             elif not options.quiet :
   342             elif not options.quiet :
   333                 print "\tN previous load state!"
   343                 print "\t[WARN] No previous load state! Loading full logs"
   334  
   344  
   335         # only after some specific date?
   345         # only after some specific date?
   336         if options.after :
   346         if options.after :
   337             # use unless read from tempfile
   347             # use unless read from tempfile
   338             if not after :
   348             if not after :
   437     parser.add_option('-Z', "--timezone",       dest="tz_name",         help="Timezone for output",                 metavar="TZ",   default="UTC"                   )
   447     parser.add_option('-Z', "--timezone",       dest="tz_name",         help="Timezone for output",                 metavar="TZ",   default="UTC"                   )
   438     parser.add_option('-f', "--force",          dest="force",           help="Force dangerous operation",           action="store_true" )
   448     parser.add_option('-f', "--force",          dest="force",           help="Force dangerous operation",           action="store_true" )
   439     parser.add_option(      "--create",         dest="create",          help="Create index database",               action="store_true" )
   449     parser.add_option(      "--create",         dest="create",          help="Create index database",               action="store_true" )
   440     parser.add_option(      "--skip-missing",   dest="skip_missing",    help="Skip missing logfiles",               action="store_true" )
   450     parser.add_option(      "--skip-missing",   dest="skip_missing",    help="Skip missing logfiles",               action="store_true" )
   441     parser.add_option(      "--reload",         dest="reload",          help="Force reload lines",                  action="store_true" )
   451     parser.add_option(      "--reload",         dest="reload",          help="Force reload lines",                  action="store_true" )
       
   452     parser.add_option(      "--ignore-resume",  dest="ignore_resume",   help="Do not try and resume interrupted autoload",  action="store_true" )
   442     parser.add_option(      "--quiet",          dest="quiet",           help="Supress status messages",             action="store_true" )
   453     parser.add_option(      "--quiet",          dest="quiet",           help="Supress status messages",             action="store_true" )
   443 
   454 
   444     # parse
   455     # parse
   445     options, args = parser.parse_args(argv[1:])
   456     options, args = parser.parse_args(argv[1:])
   446 
   457