tools/search.py
changeset 68 8157c41b3236
parent 65 8b50694f841e
equal deleted inserted replaced
67:13975aa16b4c 68:8157c41b3236
    20 
    20 
    21     # open the channel
    21     # open the channel
    22     channel = channels.channel_list.lookup(channel_name)
    22     channel = channels.channel_list.lookup(channel_name)
    23     
    23     
    24     for date_name in dates :
    24     for date_name in dates :
    25         # parse date
    25         print "%s..." % (date_name, ),
    26         date = datetime.datetime.strptime(date_name, '%Y-%m-%d').replace(tzinfo=channel.source.tz)
    26         lines = None
       
    27         
       
    28         try :
       
    29             # parse date
       
    30             date = datetime.datetime.strptime(date_name, '%Y-%m-%d').replace(tzinfo=channel.source.tz)
    27 
    31 
    28         print "%s..." % (date, )
    32             # load lines for date
       
    33             lines = channel.source.get_date(date)
       
    34         
       
    35         except Exception, e :
       
    36             print "Skipped: %s" % (e, )
       
    37         
       
    38         else :
       
    39             # insert
       
    40             count = index.insert(channel, lines)
    29 
    41 
    30         # load lines for date
    42             print "%d" % count
    31         lines = channel.source.get_date(date)
       
    32 
       
    33         # insert
       
    34         index.insert(channel, lines)
       
    35 
    43 
    36 def cmd_search (options, channel_name, query) :
    44 def cmd_search (options, channel_name, query) :
    37     """
    45     """
    38         Search the index for events on a specific channel with the given query
    46         Search the index for events on a specific channel with the given query
    39     """
    47     """
    65         add_help_option = True,
    73         add_help_option = True,
    66     )
    74     )
    67 
    75 
    68     # define command-line arguments
    76     # define command-line arguments
    69     parser.add_option("-I", "--index", dest="index_path", help="Index database path", metavar="PATH", default="logs/index")
    77     parser.add_option("-I", "--index", dest="index_path", help="Index database path", metavar="PATH", default="logs/index")
    70     parser.add_option("--create", dest="create_index", help="Create index database", default=False)
    78     parser.add_option("--create", dest="create_index", action="store_true", help="Create index database")
    71     parser.add_option("-f", "--formatter", dest="formatter_name", help="LogFormatter to use", default="irssi")
    79     parser.add_option("-f", "--formatter", dest="formatter_name", help="LogFormatter to use", default="irssi")
    72     parser.add_option("-z", "--timezone", dest="tz_name", help="Timezone for output", metavar="TZ", default="UTC")
    80     parser.add_option("-z", "--timezone", dest="tz_name", help="Timezone for output", metavar="TZ", default="UTC")
       
    81     parser.add_option("--skip-missing", dest="skip_missing", action="store_true", help="Skip missing logfiles")
    73 
    82 
    74     # parse
    83     # parse
    75     options, args = parser.parse_args()
    84     options, args = parser.parse_args()
    76 
    85 
    77     # postprocess stuff
    86     # postprocess stuff