Skip to content

Commit

Permalink
Merge pull request #73 from Jainpriyal/exception_color
Browse files Browse the repository at this point in the history
Adding color to exception and error messages
  • Loading branch information
Jainpriyal committed Apr 1, 2016
2 parents cc2b085 + 490bf94 commit 5ea8b1b
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 151 deletions.
50 changes: 25 additions & 25 deletions lib/jnpr/jsnapy/jsnapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ def get_hosts(self):
else:
if (self.args.check is True and (
self.args.file is None or self.args.pre_snapfile is None or self.args.post_snapfile is None)):
self.logger.error(
"Arguments not given correctly, Please refer help message",
extra=self.log_detail)
self.logger.error(colorama.Fore.RED +
"Arguments not given correctly, Please refer help message",
extra=self.log_detail)
self.parser.print_help()
sys.exit(1)
self.login(output_file)
Expand Down Expand Up @@ -373,16 +373,16 @@ def login(self, output_file):
try:
k = self.main_file['hosts'][0]
except KeyError as ex:
self.logger.error(
"\nERROR occurred !! Hostname not given properly %s" %
str(ex),
extra=self.log_detail)
self.logger.error(colorama.Fore.RED +
"\nERROR occurred !! Hostname not given properly %s" %
str(ex),
extra=self.log_detail)
#raise Exception(ex)
except Exception as ex:
self.logger.error(
"\nERROR occurred !! %s" %
str(ex),
extra=self.log_detail)
self.logger.error(colorama.Fore.RED +
"\nERROR occurred !! %s" %
str(ex),
extra=self.log_detail)
#raise Exception(ex)
else:
# when group of devices are given, searching for include keyword in
Expand Down Expand Up @@ -559,16 +559,16 @@ def connect(self, hostname, username, password, output_file,
action,
post_snap)
else:
self.logger.error(
"\nERROR occurred %s" %
str(ex),
extra=self.log_detail)
self.logger.error(colorama.Fore.RED +
"\nERROR occurred %s" %
str(ex),
extra=self.log_detail)
raise Exception(ex)
except Exception as ex:
self.logger.error(
"\nERROR occurred %s" %
str(ex),
extra=self.log_detail)
self.logger.error(colorama.Fore.RED +
"\nERROR occurred %s" %
str(ex),
extra=self.log_detail)
raise Exception(ex)
else:
self.generate_rpc_reply(
Expand Down Expand Up @@ -761,10 +761,10 @@ def extract_dev_data(
hostname,
config_data)
except Exception as ex:
self.logger.error(
"\nERROR occurred %s" %
str(ex),
extra=self.log_detail)
self.logger.error(colorama.Fore.RED +
"\nERROR occurred %s" %
str(ex),
extra=self.log_detail)
else:
res = True
if action in ["snapcheck", "check"]:
Expand Down Expand Up @@ -873,8 +873,8 @@ def check_arguments(self):
(self.args.snapcheck is True and self.args.file is None) or
(self.args.check is True and self.args.file is None)
):
self.logger.error(
"Arguments not given correctly, Please refer help message", extra=self.log_detail)
self.logger.error(colorama.Fore.RED +
"Arguments not given correctly, Please refer help message", extra=self.log_detail)
self.parser.print_help()
sys.exit(1)
if self.args.diff is True:
Expand Down
6 changes: 2 additions & 4 deletions lib/jnpr/jsnapy/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ def _write_file(self, rpc_reply, format, output_file):
"\nERROR:",
extra=self.log_detail)
for err_node in err:
self.logger_snap.error(
err_node.findtext(
colorama.Fore.RED +
'.//error-message'), extra=self.log_detail)
self.logger_snap.error(colorama.Fore.RED +
err_node.findtext('.//error-message'), extra=self.log_detail)
else:
"""
with open(output_file, 'w') as f:
Expand Down
4 changes: 2 additions & 2 deletions lib/jnpr/jsnapy/sqlite_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_xml_using_snapname(self, hostname, command_name, snap_name):
except Exception as ex:
self.logger_sqlite.error(
colorama.Fore.RED +
"ERROR!! Eror message is %s" %
"ERROR!! Complete message is %s" %
ex,
extra=self.sqlite_logs)
else:
Expand All @@ -71,7 +71,7 @@ def get_xml_using_snap_id(self, hostname, command_name, snap_id):
except Exception as ex:
self.logger_sqlite.error(
colorama.Fore.RED +
"ERROR!! Error message is: %s" % ex, extra=self.sqlite_logs)
"ERROR!! Complete message is: %s" % ex, extra=self.sqlite_logs)
return str(None), None

else:
Expand Down
Loading

0 comments on commit 5ea8b1b

Please sign in to comment.