diff --git a/src/libdapConnector.py b/src/libdapConnector.py index 73a8d3485902b79b075d90a728d99b420217ee2c..3aca29eff9ae82347b542e977d4c051cdd99fc19 100644 --- a/src/libdapConnector.py +++ b/src/libdapConnector.py @@ -4,33 +4,34 @@ import libdap_python_module class DapIniException(Exception): pass -class Dap: - def __init__(self, data): - res = json.loads(data) - self.modules=res['modules'] - self.config_dir=res['dap']['config_dir'] - self.log_level=res['dap']['log_level'] - self.application_name=res['dap']['application_name'] - res_init = libdap_python_module.init(res['dap']['config_dir'], res['dap']['application_name']) - if res_init == -1 or res_init == -2: - raise DapIniException("Initialization erorr") - def __del__(self): - libdap_python_module.deinit() - def setLogLevel(self, data): - self.log_level=data - res_setLogLevel = libdap_python_module.setLogLevel(data) - if res_setLogLevel == -1: - raise DapIniException("Failed to set the logging level, perhaps you did not correctly specify the name of the level") - def logIt(self, data): - parse_data = json.loads(data) - res_log_it = libdap_python_module.logIt(parse_data['level'], parse_data['data']) - if res_log_it == -1: - raise DapIniException("Could not execute log_it function. Perhaps you did not correctly specify the name of the logging level or did not leave the information that needs to be displayed") - def configGetItem(self, section_path, item_name): - res = libdap_python_module.configGetItem(section_path, item_name) - return res - def configGetItemDefault(self, section_path, item_name, default): - return libdap_python_module.configGetItemDefault(section_path, item_name, default) +def init(data): + res = json.loads(data) + modules=res['modules'] + config_dir=res['dap']['config_dir'] + log_level=res['dap']['log_level'] + application_name=res['dap']['application_name'] + res_init = libdap_python_module.init(config_dir, application_name) + if res_init == -1 or res_init == -2: + raise DapIniException("Initialization erorr") + if log_level != "NOTICE": + setLogLevel(log_level) +def deInit(): + libdap_python_module.deinit() +def setLogLevel(data): + log_level=data + res_setLogLevel = libdap_python_module.setLogLevel(data) + if res_setLogLevel == -1: + raise DapIniException("Failed to set the logging level, perhaps you did not correctly specify the name of the level") +def logIt(data): + parse_data = json.loads(data) + res_log_it = libdap_python_module.logIt(parse_data['level'], parse_data['data']) + if res_log_it == -1: + raise DapIniException("Could not execute log_it function. Perhaps you did not correctly specify the name of the logging level or did not leave the information that needs to be displayed") +def configGetItem(section_path, item_name): + res = libdap_python_module.configGetItem(section_path, item_name) + return res +def configGetItemDefault(section_path, item_name, default): + return libdap_python_module.configGetItemDefault(section_path, item_name, default) diff --git a/test/main_test.py b/test/main_test.py index 45ed2293fdda8195daf4107f04a82f4a009ea348..6a3980ecd83387ab9154b13a512f6a412bc480b9 100644 --- a/test/main_test.py +++ b/test/main_test.py @@ -4,22 +4,24 @@ json_string = """{ "modules": "libdap", "dap": { "config_dir": "/opt/dap/etc", - "log_level": "Debug", + "log_level": "DEBUG", "application_name": "TestAPP" } }""" print("Standard Configuration \n"+json_string) -daptest = libdapConnector.Dap(json_string) +libdapConnector.init(json_string) print("Initialization of the DAP") -daptest.setLogLevel("DEBUG") +libdapConnector.setLogLevel("DEBUG") print("Level logging ""DEBUG"" done") -daptest.logIt("""{ +libdapConnector.logIt("""{ "level": "DEBUG", "data": "Test. Outputting a string using the log_it function in the libdap library" }""") print("Outputting a string using the log_it function done") -res1 = daptest.configGetItem("server", "listen_address") +res1 = libdapConnector.configGetItem("server", "listen_address") print("Output [server] 'listen_address' = "+res1+"\n") -res2 = daptest.configGetItemDefault("server1", "listen_address", "8.8.8.8") +res2 = libdapConnector.configGetItemDefault("server1", "listen_address", "8.8.8.8") print("Output default value '8.8.8.8' \n [server1] 'listen_address' = "+res2+"\n") print("TEST. Get default config done") +libdapConnector.deInit() +print("Deinitialization done")