254 lines = index.list(channel, date) |
254 lines = index.list(channel, date) |
255 |
255 |
256 # display |
256 # display |
257 _output_lines(options, lines) |
257 _output_lines(options, lines) |
258 |
258 |
|
259 def _autoload_reset (options, channels) : |
|
260 """ |
|
261 Reset old autoload state |
|
262 """ |
|
263 |
|
264 # warn |
|
265 if not options.quiet : |
|
266 print "[WARN] Resetting autoload state for: %s" % ', '.join(channel.id for channel in channels) |
|
267 |
|
268 # iter |
|
269 for channel in channels : |
|
270 # statefile path |
|
271 statefile_path = os.path.join(options.autoload_state_path, 'chan-%s' % channel.id) |
|
272 |
|
273 # is it present? |
|
274 if not os.path.exists(statefile_path) : |
|
275 if not options.quiet : |
|
276 print "[WARN] No statefile found at %s" % statefile_path |
|
277 |
|
278 else : |
|
279 if not options.quiet : |
|
280 print "\t%s: " % channel.id, |
|
281 |
|
282 # remove the statefile |
|
283 os.remove(statefile_path) |
|
284 |
|
285 if not options.quiet : |
|
286 print "OK" |
|
287 |
259 def cmd_autoload (options, *channel_names) : |
288 def cmd_autoload (options, *channel_names) : |
260 """ |
289 """ |
261 Automatically loads all channel logs that have not been indexed yet (by logfile mtime) |
290 Automatically loads all channel logs that have not been indexed yet (by logfile mtime) |
262 """ |
291 """ |
263 |
292 |
268 if not channel_names : |
297 if not channel_names : |
269 channels = config.LOG_CHANNELS |
298 channels = config.LOG_CHANNELS |
270 |
299 |
271 else : |
300 else : |
272 channels = [config.LOG_CHANNELS.lookup(channel_name) for channel_name in channel_names] |
301 channels = [config.LOG_CHANNELS.lookup(channel_name) for channel_name in channel_names] |
|
302 |
|
303 # reset autoload state? |
|
304 if options.reset : |
|
305 _autoload_reset(options, channels) |
|
306 print |
273 |
307 |
274 # iterate channels |
308 # iterate channels |
275 for channel in channels : |
309 for channel in channels : |
276 if not options.quiet : |
310 if not options.quiet : |
277 print "Channel %s:" % channel.id |
311 print "Channel %s:" % channel.id |
376 open(statefile_path, 'w').close() |
410 open(statefile_path, 'w').close() |
377 |
411 |
378 # close+delete tempfile |
412 # close+delete tempfile |
379 statefile_tmp.close() |
413 statefile_tmp.close() |
380 os.remove(statefile_tmppath) |
414 os.remove(statefile_tmppath) |
|
415 |
|
416 print |
|
417 |
|
418 # done |
|
419 return |
381 |
420 |
382 def cmd_help (options, *args) : |
421 def cmd_help (options, *args) : |
383 """ |
422 """ |
384 Help about commands |
423 Help about commands |
385 """ |
424 """ |
447 parser.add_option('-Z', "--timezone", dest="tz_name", help="Timezone for output", metavar="TZ", default="UTC" ) |
486 parser.add_option('-Z', "--timezone", dest="tz_name", help="Timezone for output", metavar="TZ", default="UTC" ) |
448 parser.add_option('-f', "--force", dest="force", help="Force dangerous operation", action="store_true" ) |
487 parser.add_option('-f', "--force", dest="force", help="Force dangerous operation", action="store_true" ) |
449 parser.add_option( "--create", dest="create", help="Create index database", action="store_true" ) |
488 parser.add_option( "--create", dest="create", help="Create index database", action="store_true" ) |
450 parser.add_option( "--skip-missing", dest="skip_missing", help="Skip missing logfiles", action="store_true" ) |
489 parser.add_option( "--skip-missing", dest="skip_missing", help="Skip missing logfiles", action="store_true" ) |
451 parser.add_option( "--reload", dest="reload", help="Force reload lines", action="store_true" ) |
490 parser.add_option( "--reload", dest="reload", help="Force reload lines", action="store_true" ) |
|
491 parser.add_option( "--reset", dest="reset", help="Reset old autload state", action="store_true" ) |
452 parser.add_option( "--ignore-resume", dest="ignore_resume", help="Do not try and resume interrupted autoload", action="store_true" ) |
492 parser.add_option( "--ignore-resume", dest="ignore_resume", help="Do not try and resume interrupted autoload", action="store_true" ) |
453 parser.add_option( "--quiet", dest="quiet", help="Supress status messages", action="store_true" ) |
493 parser.add_option( "--quiet", dest="quiet", help="Supress status messages", action="store_true" ) |
454 |
494 |
455 # parse |
495 # parse |
456 options, args = parser.parse_args(argv[1:]) |
496 options, args = parser.parse_args(argv[1:]) |