35
35
from logdissect import __version__
36
36
from optparse import OptionParser
37
37
from optparse import OptionGroup
38
+ import gettext
39
+ gettext .install ('licins' )
38
40
39
41
class LogDissectCore :
40
42
@@ -60,108 +62,63 @@ def __init__(self):
60
62
_ ("Output options" ))
61
63
62
64
# run_job does the actual job using the other functions.
63
- def run_job
65
+ def run_job ( self ):
64
66
"""Execute a logdissect job"""
65
67
# To Do: execute the other functions here
66
- # load_parsers()
67
- # load_outputs()
68
- # config_options()
69
- # load_inputs
70
- # run_parse()
68
+ self . load_parsers ()
69
+ self . load_outputs ()
70
+ self . config_options ()
71
+ self . load_inputs ()
72
+ self . run_parse ()
71
73
# Note to self: leave morphing out until the rest works.
72
- # run_morph() run_morph should look like run_parse
74
+ # self. run_morph() run_morph should look like run_parse
73
75
# We'll need to split self.options.morphers_list and then split
74
76
# the list into range x y, grep z, etc.
75
77
# Probably do that in load_morphers
76
- # run_merge()
77
- # run_output()
78
+ self . run_merge ()
79
+ self . run_output ()
78
80
# This will have to parse outputs_list into a list, etc.
79
81
80
82
def run_parse (self ):
81
83
"""Parse one or more log files"""
82
84
# Data set already has source file names from load_inputs
83
85
parsedset = self .data_set
84
86
for l in self .data_set .data_set :
85
- parsemodule = self .parse_modules [self .options .parser ]()
87
+ parsemodule = self .parse_modules [self .options .parser ]
86
88
parsemodule .data = l
87
89
parsedlog = parsemodule .run_parse ()
88
90
parsedset .data_set .append (parsedlog )
89
91
self .data_set = parsedset
90
92
91
93
def run_merge (self ):
92
94
"""Merge all our data sets together"""
93
- if self .data_set .data_set < 2 :
94
- self .data_set .finalized_data = self .data_set .data_set [0 ]
95
- return 0
96
- else :
97
- ourdataset = self .data_set
98
- ourfinallog = self .data_set .finalized_data
99
- key_log = ourdataset .data_set .pop (0 )
100
- while ourdataset .data_set [0 ]:
101
- second_log = ourdataset .data_set .pop (0 )
102
- for x , y in map (None , key_log , second_log ):
103
- if not x :
104
- ourfinallog .append (y )
105
- elif not y :
106
- ourfinallog .append (x )
107
- else :
108
- if x .date_stamp_year <= y .date_stamp_year :
109
- ourfinallog .append (x )
110
- ourfinallog .append (y )
111
- else :
112
- ourfinallog .append (y )
113
- ourfinallog .append (x )
114
- key_log = ourfinallog
115
- self .data_set .finalized_data = key_log
116
- # for otherlog in ourdataset.data_set:
117
- # for trial_entry in key_log:
118
- # if trial_entry.date_stamp_year < \
119
- # otherlog[0].date_stamp_year:
120
- # ourfinallog.append(trial_entry)
121
- # else:
122
- # ourfinallog.append(otherlog.pop(
123
-
124
- # To Do: replace this stuff above inside the else loop:
125
- # for log in self.data_set.data_set:
126
- # key_log = self.data_set.data_set.pop(0)
127
- # for entry in key_log:
128
- # if self.data_set.data_set > 0:
129
- # this_try = self.data_set.data_set[0].entries.pop(0)
130
- # for log in self.data_set.data_set:
131
- # for other_entry in log:
132
- # if entry.date_stamp_year < \
133
- # this_try.date_stamp_year:
134
- # self.data_set.finalized_data.append(other_entry.raw_text)
135
- # self.data_set.finalized_data.append(entry.raw_text)
136
-
137
- # def run_morph(self, options):
138
- # """Morph the data set using the selected modules"""
139
- # pass
95
+ #Note: just add the logs together then sort the final list.
96
+ for l in self .data_set .data_set :
97
+ self .data_set .finalized_data += l
98
+ self .data_set .finalized_data .sort (key = lambda x : x .date_stamp_year )
140
99
141
- def do_output (self ):
100
+ def run_output (self ):
142
101
"""Output finalized data"""
143
102
for o in self .options .output_list .split (',' ):
144
103
if o in logdissect .output .__all__ :
145
104
self .output_list [o ](data = self .data_set .finalized_data )
146
105
147
-
148
-
149
106
def config_options (self ):
150
107
"""Set config options"""
151
108
# Input option:
152
109
self .option_parser .add_option ("-i" , "--input" ,
153
110
action = "store" ,
154
- dest = "input_list " ,
111
+ dest = "inputs_list " ,
155
112
help = _ ("specifies input files" ))
156
113
# Module list options:
157
114
self .option_parser .add_option ("--list-parsers" ,
158
115
action = "callback" ,
159
116
callback = self .list_parsers ,
160
117
help = _ ("returns a list of available parsers" ))
161
- self .option_parser .add_option ("--list-morphers" ,
162
- action = "callback" ,
163
- callback = self .list_morphers ,
164
- help = _ ("returns a list of available morphers" ))
118
+ # self.option_parser.add_option("--list-morphers",
119
+ # action="callback",
120
+ # callback=self.list_morphers,
121
+ # help=_("returns a list of available morphers"))
165
122
self .option_parser .add_option ("--list-outputs" ,
166
123
action = "callback" ,
167
124
callback = self .list_outputs ,
@@ -180,24 +137,24 @@ def config_options(self):
180
137
dest = "output_list" ,
181
138
help = _ ("specifies output formats to use" ))
182
139
183
- self .option_parser .add_option_group (self .input_options )
184
- self .option_parser .add_option_group (self .parse_options )
185
- self .option_parser .add_option_group (self .morph_options )
186
- self .option_parser .add_option_group (self .output_options )
140
+ # self.option_parser.add_option_group(self.input_options)
141
+ # self.option_parser.add_option_group(self.parse_options)
142
+ # self.option_parser.add_option_group(self.morph_options)
143
+ # self.option_parser.add_option_group(self.output_options)
187
144
self .options , args = self .option_parser .parse_args (sys .argv [1 :])
188
145
189
146
# To Do: finish input file loading
190
147
# Load input files:
191
148
def load_inputs (self ):
192
149
"""Load the specified inputs"""
193
- for f in self .inputs_list :
150
+ for f in self .options . inputs_list . split ( ' ' ) :
194
151
fullpath = os .path .abspath (f )
195
152
log = LogData ()
196
153
log .source_full_path = fullpath
197
154
self .data_set .data_set .append (log )
198
155
199
156
# Parsing modules:
200
- def list_parsers (self ):
157
+ def list_parsers (self , * args ):
201
158
"""Return a list of available parsing modules"""
202
159
print '==== Available parsing modules: ===='
203
160
print
@@ -208,7 +165,7 @@ def list_parsers(self):
208
165
209
166
def load_parsers (self ):
210
167
"""Load parsing module(s)"""
211
- for parser in sorted (logdissect .parsers .__parsers__ ):
168
+ for parser in sorted (logdissect .parsers .__all__ ):
212
169
self .parse_modules [parser ] = \
213
170
__import__ ('logdissect.parsers.' + parser , globals (), \
214
171
locals (), [logdissect ]).ParseModule (self .parse_options )
@@ -231,13 +188,13 @@ def load_parsers(self):
231
188
# locals(), [logdissect]).MorphModule(self.morph_options)
232
189
233
190
# Output modules (log file, csv, html, etc)
234
- def list_outputs (self ):
191
+ def list_outputs (self , * args ):
235
192
"""Return a list of available output modules"""
236
193
print '==== Available output modules ===='
237
194
print
238
195
for output in sorted (self .output_modules ):
239
196
print string .ljust (self .output_modules [output ].name , 16 ) + \
240
- ': ' + self .format_module [ format ].desc
197
+ ': ' + self .output_modules [ output ].desc
241
198
sys .exit (0 )
242
199
243
200
def load_outputs (self ):
@@ -249,4 +206,4 @@ def load_outputs(self):
249
206
250
207
if __name__ == "__main__" :
251
208
dissect = LogDissectCore ()
252
- dissect .run_parse ()
209
+ dissect .run_job ()
0 commit comments