Skip to content

Commit 0927d7a

Browse files
author
8go
committed
minor bug fix, simplifications
1 parent d62f02f commit 0927d7a

1 file changed

Lines changed: 31 additions & 56 deletions

File tree

processing.py

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -211,65 +211,36 @@ def parseArgs(argv, settings, logger):
211211
try:
212212
loglevel = int(loglevelarg)
213213
except Exception, e:
214-
if settings.TArg:
215-
logger.critical("Logging level not specified correctly. "
216-
"Must be integer between 1 and 5. (%s)", loglevelarg)
217-
else:
218-
msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Critical,
219-
"Wrong arguments",
220-
"Error: Logging level not specified correctly. "
221-
"Must be integer between 1 and 5.")
222-
msgBox.exec_()
223-
sys.exit()
214+
reportLogging("Logging level not specified correctly. "
215+
"Must be integer between 1 and 5. (%s)" % loglevelarg, logging.CRITICAL,
216+
"Wrong arguments", settings, logger)
217+
sys.exit(18)
224218
if loglevel > 5 or loglevel < 1:
225-
if settings.TArg:
226-
logger.critical("Logging level not specified correctly. "
227-
"Must be integer between 1 and 5. (%s)", loglevelarg)
228-
else:
229-
msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Critical,
230-
"Wrong arguments",
231-
"Error: Logging level not specified correctly. "
232-
"Must be integer between 1 and 5.")
233-
msgBox.exec_()
234-
sys.exit()
219+
reportLogging("Logging level not specified correctly. "
220+
"Must be integer between 1 and 5. (%s)" % loglevelarg, logging.CRITICAL,
221+
"Wrong arguments", settings, logger)
222+
sys.exit(19)
235223
basics.LOGGINGLEVEL = loglevel * 10 # https://docs.python.org/2/library/logging.html#levels
236224
logger.setLevel(basics.LOGGINGLEVEL)
237225
logger.info('Logging level set to %s (%d).',
238226
logging.getLevelName(basics.LOGGINGLEVEL), basics.LOGGINGLEVEL)
239227

240228
if (settings.DArg and settings.EArg) or (settings.DArg and settings.OArg):
241-
if settings.TArg:
242-
logger.critical("You cannot specify both decrypt and encrypt. "
243-
"It is one or the other. Either -d or -e or -o.")
244-
else:
245-
msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Critical, "Wrong arguments",
246-
"Error: You cannot specify both decrypt and encrypt. "
247-
"It is one or the other. Either -d or -e or -o.")
248-
msgBox.exec_()
229+
reportLogging("You cannot specify both decrypt and encrypt. "
230+
"It is one or the other. Either -d or -e or -o.", logging.CRITICAL,
231+
"Wrong arguments", settings, logger)
249232
sys.exit(2)
250233
if (settings.MArg and settings.DArg) or (settings.MArg and settings.NArg):
251-
if settings.TArg:
252-
logger.critical("You cannot specify both \"encrypt filename\" and "
234+
reportLogging("You cannot specify both \"encrypt filename\" and "
253235
"\"decrypt file(name)\". It is one or the other. "
254-
"Don't use -m when using -d or -n (and vice versa).")
255-
else:
256-
msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Critical, "Wrong arguments",
257-
"Error: You cannot specify both \"encrypt filename\" and "
258-
"\"decrypt file(name)\". It is one or the other. "
259-
"Don't use -m when using -d or -n (and vice versa).")
260-
msgBox.exec_()
236+
"Don't use -m when using -d or -n (and vice versa).", logging.CRITICAL,
237+
"Wrong arguments", settings, logger)
261238
sys.exit(2)
262239
if (settings.NArg and settings.EArg) or (settings.NArg and settings.OArg) or (settings.NArg and settings.MArg):
263-
if settings.TArg:
264-
logger.critical("You cannot specify both \"decrypt filename\" and "
265-
"\"encrypt file(name)\". It is one or the other. Don't use "
266-
"-n when using -e, -o, or -m (and vice versa).")
267-
else:
268-
msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Critical,
269-
"Wrong arguments", "Error: You cannot specify both \"decrypt "
270-
"filename\" and \"encrypt file(name)\". It is one or the other. "
271-
"Don't use -n when using -e, -o, or -m (and vice versa).")
272-
msgBox.exec_()
240+
reportLogging("You cannot specify both \"decrypt filename\" and "
241+
"\"encrypt file(name)\". It is one or the other. Don't use "
242+
"-n when using -e, -o, or -m (and vice versa).", logging.CRITICAL,
243+
"Wrong arguments", settings, logger)
273244
sys.exit(2)
274245
if settings.DArg or settings.NArg or settings.MArg:
275246
settings.XArg = False # X is relevant only when -e or -o is set
@@ -284,7 +255,7 @@ def parseArgs(argv, settings, logger):
284255
logger.debug("Specified files are: %s", str(args))
285256
settings.printSettings()
286257

287-
def reportLogging(str, level, title, settings, logger, feedback):
258+
def reportLogging(str, level, title, settings, logger, feedback=None):
288259
"""
289260
Displays string str depending on scenario:
290261
a) in terminal mode: thru logger (except if loglevel == NOTSET)
@@ -295,10 +266,14 @@ def reportLogging(str, level, title, settings, logger, feedback):
295266
@param level: log level from DEBUG to CRITICAL
296267
@param title: window title text
297268
"""
269+
if feedback == None:
270+
guiExists = False
271+
else:
272+
guiExists = settings.guiExists
298273
if level == logging.NOTSET:
299274
if settings.TArg:
300275
print str # stdout
301-
elif settings.guiExists:
276+
elif guiExists:
302277
print str # stdout
303278
feedback.addFeedback("<br>%s" % (str))
304279
else:
@@ -309,7 +284,7 @@ def reportLogging(str, level, title, settings, logger, feedback):
309284
elif level == logging.DEBUG:
310285
if settings.TArg:
311286
logger.debug(str)
312-
elif settings.guiExists:
287+
elif guiExists:
313288
logger.debug(str)
314289
if logger.getEffectiveLevel() <= level:
315290
feedback.addFeedback("<br>Debug: %s" % (str))
@@ -320,7 +295,7 @@ def reportLogging(str, level, title, settings, logger, feedback):
320295
elif level == logging.INFO:
321296
if settings.TArg:
322297
logger.info(str)
323-
elif settings.guiExists:
298+
elif guiExists:
324299
logger.info(str)
325300
if logger.getEffectiveLevel() <= level:
326301
feedback.addFeedback("<br>Info: %s" % (str))
@@ -333,7 +308,7 @@ def reportLogging(str, level, title, settings, logger, feedback):
333308
elif level == logging.WARN:
334309
if settings.TArg:
335310
logger.warning(str)
336-
elif settings.guiExists:
311+
elif guiExists:
337312
logger.warning(str)
338313
if logger.getEffectiveLevel() <= level:
339314
feedback.addFeedback("<br>Warning: %s" % (str))
@@ -346,27 +321,27 @@ def reportLogging(str, level, title, settings, logger, feedback):
346321
elif level == logging.ERROR:
347322
if settings.TArg:
348323
logger.error(str)
349-
elif settings.guiExists:
324+
elif guiExists:
350325
logger.error(str)
351326
if logger.getEffectiveLevel() <= level:
352327
feedback.addFeedback("<br>Error: %s" % (str))
353328
else:
354329
logger.error(str)
355330
if logger.getEffectiveLevel() <= level:
356-
msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Error,
331+
msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Critical,
357332
title, "Error: %s" % (str))
358333
msgBox.exec_()
359334
elif level == logging.CRITICAL:
360335
if settings.TArg:
361336
logger.critical(str)
362-
elif settings.guiExists:
337+
elif guiExists:
363338
logger.critical(str)
364339
if logger.getEffectiveLevel() <= level:
365340
feedback.addFeedback("<br>Critical: %s" % (str))
366341
else:
367342
logger.critical(str)
368343
if logger.getEffectiveLevel() <= level:
369-
msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Ceitical,
344+
msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Critical,
370345
title, "Critical: %s" % (str))
371346
msgBox.exec_()
372347

0 commit comments

Comments
 (0)