author | Tero Marttila <terom@fixme.fi> |
Tue, 10 Feb 2009 05:56:57 +0200 | |
changeset 83 | a34e9f56ddda |
parent 82 | afd3120ec71e |
permissions | -rw-r--r-- |
65 | 1 |
""" |
2 |
Tool for accessing the search index |
|
3 |
""" |
|
4 |
||
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
5 |
# XXX: fix path |
65 | 6 |
import sys; sys.path.insert(0, '.'); sys.path.insert(0, '..') |
7 |
||
8 |
import datetime, pytz |
|
9 |
||
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
10 |
# configuration and the LogSearchIndex module |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
11 |
import config, log_search, channels |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
12 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
13 |
def _open_index_and_channel (options, channel_name, open_mode) : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
14 |
""" |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
15 |
Opens+returns a LogSearchIndex and a LogChannel |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
16 |
""" |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
17 |
# open the LogSearchIndex |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
18 |
index = log_search.LogSearchIndex(options.index_path, open_mode) |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
19 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
20 |
# open the channel |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
21 |
channel = config.LOG_CHANNELS.lookup(channel_name) |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
22 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
23 |
# return |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
24 |
return index, channel |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
25 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
26 |
def _load_channel_date (index, options, channel, date) : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
27 |
""" |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
28 |
Loads the logs for the given date from the channel's LogSource into the given LogSearchIndex |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
29 |
""" |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
30 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
31 |
if not options.quiet : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
32 |
print "%s %s..." % (channel.id, date.strftime(channel.source.filename_fmt)), |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
33 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
34 |
try : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
35 |
# load lines for date |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
36 |
lines = channel.source.get_date(date) |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
37 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
38 |
except Exception, e : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
39 |
if not options.skip_missing : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
40 |
raise |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
41 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
42 |
if not options.quiet : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
43 |
print "Skipped: %s" % (e, ) |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
44 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
45 |
else : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
46 |
# insert -> count |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
47 |
count = index.insert(channel, lines) |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
48 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
49 |
if not options.quiet : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
50 |
print "OK: %d lines" % count |
65 | 51 |
|
52 |
def cmd_load (options, channel_name, *dates) : |
|
53 |
""" |
|
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
54 |
Loads the logs for a specific channel for the given dates (in terms of the channe logs' timezone) into the index |
65 | 55 |
""" |
56 |
||
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
57 |
# open index/channel |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
58 |
index, channel = _open_index_and_channel(options, channel_name, '*' if options.create_index else 'a') |
65 | 59 |
|
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
60 |
# handle each date |
65 | 61 |
for date_name in dates : |
68 | 62 |
try : |
63 |
# parse date |
|
64 |
date = datetime.datetime.strptime(date_name, '%Y-%m-%d').replace(tzinfo=channel.source.tz) |
|
65 | 65 |
|
68 | 66 |
except Exception, e : |
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
67 |
print "[ERROR] Invalid date: %s: %s" % (date_name, e) |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
68 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
69 |
if options.skip_missing : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
70 |
continue |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
71 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
72 |
else : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
73 |
raise |
68 | 74 |
|
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
75 |
# load |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
76 |
_load_channel_date(index, options, channel, date) |
65 | 77 |
|
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
78 |
def cmd_load_month (options, channel_name, *months) : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
79 |
""" |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
80 |
Loads the logs for a specific channel for the given months (in terms of the channel's timezone) into the index |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
81 |
""" |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
82 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
83 |
# open index/channel |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
84 |
index, channel = _open_index_and_channel(options, channel_name, '*' if options.create_index else 'a') |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
85 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
86 |
# handle each date |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
87 |
for month_name in months : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
88 |
try : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
89 |
# parse date |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
90 |
month = datetime.datetime.strptime(month_name, '%Y-%m').replace(tzinfo=channel.source.tz) |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
91 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
92 |
except Exception, e : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
93 |
print "[ERROR] Invalid date: %s: %s" % (month_name, e) |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
94 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
95 |
if options.skip_missing : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
96 |
continue |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
97 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
98 |
else : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
99 |
raise |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
100 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
101 |
# get the set of days |
83
a34e9f56ddda
improve parser resilience, improve get_month_days, add 'Channel' item to general menu
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
102 |
days = list(channel.source.get_month_days(month)) |
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
103 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
104 |
print "Loading %d days of logs:" % (len(days)) |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
105 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
106 |
# load each day |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
107 |
for date in days : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
108 |
# convert to datetime |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
109 |
dt = datetime.datetime.combine(date, datetime.time(0)).replace(tzinfo=channel.source.tz) |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
110 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
111 |
# load |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
112 |
_load_channel_date(index, options, channel, dt) |
65 | 113 |
|
114 |
def cmd_search (options, channel_name, query) : |
|
115 |
""" |
|
116 |
Search the index for events on a specific channel with the given query |
|
117 |
""" |
|
118 |
||
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
119 |
# sanity-check |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
120 |
if options.create_index : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
121 |
raise Exception("--create doesn't make sense for 'search'") |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
122 |
|
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
123 |
# open index/channel |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
124 |
index, channel = _open_index_and_channel(options, channel_name, 'r') |
65 | 125 |
|
126 |
# search |
|
127 |
lines = index.search_simple(channel, query) |
|
128 |
||
129 |
# display as plaintext |
|
130 |
for line in options.formatter.format_txt(lines) : |
|
131 |
print line |
|
132 |
||
133 |
if __name__ == '__main__' : |
|
134 |
from optparse import OptionParser |
|
135 |
||
136 |
# define parser |
|
137 |
parser = OptionParser( |
|
138 |
usage = "%prog [options] <command> [ ... ]", |
|
139 |
add_help_option = True, |
|
140 |
) |
|
141 |
||
142 |
# define command-line arguments |
|
143 |
parser.add_option("-I", "--index", dest="index_path", help="Index database path", metavar="PATH", default="logs/index") |
|
68 | 144 |
parser.add_option("--create", dest="create_index", action="store_true", help="Create index database") |
65 | 145 |
parser.add_option("-f", "--formatter", dest="formatter_name", help="LogFormatter to use", default="irssi") |
146 |
parser.add_option("-z", "--timezone", dest="tz_name", help="Timezone for output", metavar="TZ", default="UTC") |
|
68 | 147 |
parser.add_option("--skip-missing", dest="skip_missing", action="store_true", help="Skip missing logfiles") |
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
148 |
parser.add_option("--quiet", dest="quiet", action="store_true", help="Supress status messages") |
65 | 149 |
|
150 |
# parse |
|
151 |
options, args = parser.parse_args() |
|
152 |
||
153 |
# postprocess stuff |
|
154 |
options.tz = pytz.timezone(options.tz_name) |
|
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
155 |
options.formatter = config.LOG_FORMATTERS[options.formatter_name](options.tz, "%H:%M:%S", None, None) |
65 | 156 |
|
157 |
# pop command |
|
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
158 |
if not args : |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
159 |
raise Exception("Missing command") |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
160 |
|
65 | 161 |
command = args.pop(0) |
162 |
||
163 |
# inspect |
|
164 |
func = globals()['cmd_%s' % command] |
|
165 |
||
166 |
# call |
|
167 |
func(options, *args) |
|
168 |
||
169 |