20
20
import sys
21
21
22
22
import edi
23
- import cabrillo
23
+ import parse_cabrillo
24
24
import rules as _rules
25
25
import version
26
- from edi import crosscheck_logs_filter
27
26
28
27
# SORT_OUTPUT = False # TODO : sort the results output
29
28
@@ -91,21 +90,21 @@ def load_log_format_module(module_name):
91
90
# pass
92
91
93
92
94
- def print_human_friendly_output (output , verbose = False ):
93
+ def print_human_friendly_output (lfmodule , output , verbose = False ):
95
94
"""Will print a human-fiendly output for easy read"""
96
95
# single log
97
- if output .get (edi .INFO_LOG , False ):
98
- print_log_human_friendly (output )
96
+ if output .get (lfmodule .INFO_LOG , False ):
97
+ print_log_human_friendly (lfmodule , output )
99
98
# multi logs
100
- if output .get (edi .INFO_MLC , False ):
101
- print ('Checking logs from folder : {}' .format (output [edi .INFO_MLC ]))
99
+ if output .get (lfmodule .INFO_MLC , False ):
100
+ print ('Checking logs from folder : {}' .format (output [lfmodule .INFO_MLC ]))
102
101
print ('#########################' )
103
- # print('Checking logs from folder : {}'.format(output[edi .INFO_MLC]))
104
- for log in output [edi .INFO_LOGS ]:
105
- print_log_human_friendly (log )
102
+ # print('Checking logs from folder : {}'.format(output[lfmodule .INFO_MLC]))
103
+ for log in output [lfmodule .INFO_LOGS ]:
104
+ print_log_human_friendly (lfmodule , log )
106
105
print ('--------' )
107
106
# cross check
108
- if output .get (edi .INFO_CC , False ):
107
+ if output .get (lfmodule .INFO_CC , False ):
109
108
print ('Cross check logs from folder : {}' .format (output [edi .INFO_CC ]))
110
109
print ('#########################' )
111
110
for _call , _values in output [edi .INFO_OPERATORS ].items ():
@@ -124,40 +123,40 @@ def print_human_friendly_output(output, verbose=False):
124
123
print ('--------' )
125
124
126
125
127
- def print_log_human_friendly (output ):
126
+ def print_log_human_friendly (lfmodule , output ):
128
127
"""Will print human fiendly info for a log"""
129
128
has_errors = False
130
- print ('Checking log : {}' .format (output [edi .INFO_LOG ]))
131
- if output [edi .ERR_IO ]:
132
- print ('Input/Output : {}' .format (output [edi .ERR_IO ]))
129
+ print ('Checking log : {}' .format (output [lfmodule .INFO_LOG ]))
130
+ if output [lfmodule .ERR_IO ]:
131
+ print ('Input/Output : {}' .format (output [lfmodule .ERR_IO ]))
133
132
has_errors = True
134
133
pass
135
- if output [edi .ERR_HEADER ]:
134
+ if output [lfmodule .ERR_HEADER ]:
136
135
print ('Header errors :' )
137
- for err in output [edi .ERR_HEADER ]:
136
+ for err in output [lfmodule .ERR_HEADER ]:
138
137
print ('Line {} : {}' .format (err [0 ], err [1 ]))
139
138
has_errors = True
140
- if output [edi .ERR_QSO ]:
139
+ if output [lfmodule .ERR_QSO ]:
141
140
print ('QSO errors :' )
142
- for err in output [edi .ERR_QSO ]:
141
+ for err in output [lfmodule .ERR_QSO ]:
143
142
print ('Line {} : {} <- {}' .format (err [0 ], err [1 ], err [2 ]))
144
143
has_errors = True
145
144
146
145
if has_errors is False :
147
146
print ('No error found' )
148
147
149
148
150
- def print_csv_output (output ):
149
+ def print_csv_output (lfmodule , output ):
151
150
# cross check
152
- if output .get (edi .INFO_CC , False ):
151
+ if output .get (lfmodule .INFO_CC , False ):
153
152
print ('Callsign, ValidLog, Band, Category, ConfirmedQso, Points' )
154
- for _call , _values in output [edi .INFO_OPERATORS ].items ():
153
+ for _call , _values in output [lfmodule .INFO_OPERATORS ].items ():
155
154
for _band , _details in _values ['band' ].items ():
156
155
if not _details .get ('checklog' , False ) is True :
157
156
print ('{}, {}, {}, {}, {}, {}' .format (_call , _details ['valid' ], _band , _details ['category' ], _details ['qsos_confirmed' ], _details ['points' ]))
158
157
else :
159
- # if output.get(edi .INFO_LOG, False):
160
- # if output.get(edi .INFO_MLC, False):
158
+ # if output.get(lfmodule .INFO_LOG, False):
159
+ # if output.get(lfmodule .INFO_MLC, False):
161
160
print ('NOT IMPLEMENTED' )
162
161
163
162
@@ -179,6 +178,8 @@ def main():
179
178
180
179
if log_format == 'EDI' :
181
180
lfmodule = edi
181
+ elif log_format == 'CABRILLO' :
182
+ lfmodule = parse_cabrillo
182
183
else :
183
184
print ('Selected log type is unsupported : {}' .format (log_format ))
184
185
sys .exit (1 )
@@ -191,7 +192,7 @@ def main():
191
192
192
193
# if 'validate one log'
193
194
if args .singlelogcheck :
194
- output [edi .INFO_LOG ] = args .singlelogcheck
195
+ output [lfmodule .INFO_LOG ] = args .singlelogcheck
195
196
if not os .path .isfile (args .singlelogcheck ):
196
197
print ('Cannot open file : {}' .format (args .singlelogcheck ))
197
198
sys .exit (1 )
@@ -200,43 +201,44 @@ def main():
200
201
201
202
# validate multiple logs
202
203
elif args .multilogcheck :
203
- output [edi .INFO_MLC ] = args .multilogcheck
204
+ output [lfmodule .INFO_MLC ] = args .multilogcheck
204
205
if not os .path .isdir (args .multilogcheck ):
205
206
print ('Cannot open logs folder : {}' .format (args .multilogcheck ))
206
207
sys .exit (1 )
207
208
logs_output = []
208
209
for filename in os .listdir (args .multilogcheck ):
209
210
log_output = {}
210
211
_log = log (os .path .join (args .multilogcheck , filename ), rules = rules )
211
- log_output [edi .INFO_LOG ] = filename
212
+ log_output [lfmodule .INFO_LOG ] = filename
212
213
log_output .update (_log .errors )
213
214
logs_output .append (log_output )
214
- output [edi .INFO_LOGS ] = logs_output
215
+ output [lfmodule .INFO_LOGS ] = logs_output
215
216
# add also checklogs
216
217
if args .checklogs :
217
218
if os .path .isdir (args .checklogs ):
218
219
logs_output = []
219
220
for filename in os .listdir (args .checklogs ):
220
221
log_output = {}
221
222
_log = log (os .path .join (args .checklogs , filename ), rules = rules , checklog = True )
222
- log_output [edi .INFO_LOG ] = filename
223
+ log_output [lfmodule .INFO_LOG ] = filename
223
224
log_output .update (_log .errors )
224
225
logs_output .append (log_output )
225
- output [edi .INFO_LOGS ].extend (logs_output )
226
+ output [lfmodule .INFO_LOGS ].extend (logs_output )
226
227
227
228
# crosscheck logs
228
229
elif args .crosscheck :
229
230
if not rules :
230
231
print ("No rules were provided" )
231
232
sys .exit (1 )
232
- output [edi .INFO_CC ] = args .crosscheck
233
- output [edi .INFO_OPERATORS ] = {}
234
- op_instance = crosscheck_logs_filter (log , rules = rules , logs_folder = args .crosscheck , checklogs_folder = args .checklogs )
233
+ output [lfmodule .INFO_CC ] = args .crosscheck
234
+ output [lfmodule .INFO_OPERATORS ] = {}
235
+ print ("DEBUG : LOG=" , log )
236
+ op_instance = lfmodule .crosscheck_logs_filter (log , rules = rules , logs_folder = args .crosscheck , checklogs_folder = args .checklogs )
235
237
for _call , _instance in op_instance .items ():
236
238
op_output = {}
237
- op_output [edi .INFO_BANDS ] = {}
239
+ op_output [lfmodule .INFO_BANDS ] = {}
238
240
for _log in _instance .logs :
239
- op_output [edi .INFO_BANDS ][_log .band ] = {
241
+ op_output [lfmodule .INFO_BANDS ][_log .band ] = {
240
242
'path' : _log .path ,
241
243
'points' : _log .qsos_points ,
242
244
'qsos_confirmed' : _log .qsos_confirmed ,
@@ -252,19 +254,19 @@ def main():
252
254
_cc_errors .append ('{} : {}' .format (qso .qso_line , qso .cc_error ))
253
255
else :
254
256
_cc_valid .append ('{} : {} : {}' .format (qso .qso_line , qso .points , qso .cc_confirmed ))
255
- op_output [edi .INFO_BANDS ][_log .band ]['qso_errors' ] = _cc_errors
256
- op_output [edi .INFO_BANDS ][_log .band ]['qso_valid' ] = _cc_valid
257
+ op_output [lfmodule .INFO_BANDS ][_log .band ]['qso_errors' ] = _cc_errors
258
+ op_output [lfmodule .INFO_BANDS ][_log .band ]['qso_valid' ] = _cc_valid
257
259
258
- output [edi .INFO_OPERATORS ][_call ] = op_output
260
+ output [lfmodule .INFO_OPERATORS ][_call ] = op_output
259
261
260
262
if args .output .upper () == 'HUMAN-FRIENDLY' :
261
- print_human_friendly_output (output , verbose = args .verbose )
263
+ print_human_friendly_output (lfmodule , output , verbose = args .verbose )
262
264
elif args .output .upper () == 'JSON' :
263
265
print (edi .dict_to_json (output ))
264
266
elif args .output .upper () == 'XML' :
265
267
print (edi .dict_to_xml (output ))
266
268
elif args .output .upper () == 'CSV' :
267
- print_csv_output (output )
269
+ print_csv_output (lfmodule , output )
268
270
269
271
if __name__ == '__main__' :
270
272
main ()
0 commit comments