From 86210dbbfaa7a0f499473f816f6f11e19812b0a9 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Tue, 23 Feb 2010 20:05:29 +0000 Subject: [PATCH] return/raise SfaAPIException with stacktrace if we fail to connect to PLCAPI --- sfa/plc/api.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sfa/plc/api.py b/sfa/plc/api.py index 903df154..cfda3278 100644 --- a/sfa/plc/api.py +++ b/sfa/plc/api.py @@ -26,6 +26,11 @@ def list_to_dict(recs, key): keys = [rec[key] for rec in recs] return dict(zip(keys, recs)) +def handle_exception(method): + def wrapper(*args, **kwargs): + try: return method(*args, **kwargs) + except: raise SfaAPIError(traceback.format_exc()) + return wrapper class SfaAPI(BaseAPI): @@ -66,6 +71,7 @@ class SfaAPI(BaseAPI): self.time_format = "%Y-%m-%d %H:%M:%S" self.logger=get_sfa_logger() + @handle_exception def getPLCShell(self): self.plauth = {'Username': self.config.SFA_PLC_USER, 'AuthMethod': 'password', @@ -84,7 +90,8 @@ class SfaAPI(BaseAPI): shell = xmlrpclib.Server(url, verbose = 0, allow_none = True) shell.AuthCheck(self.plauth) return shell - + + @handle_exception def getPLCShellVersion(self): # We need to figure out what version of PLCAPI we are talking to. # Some calls we need to make later will be different depending on -- 2.43.0