Skip to content
Snippets Groups Projects
Commit c9a2d0a3 authored by alexey.stratulat's avatar alexey.stratulat
Browse files

Redid the libdapConnector. Now it is not built on class, but on functions, as...

Redid the libdapConnector. Now it is not built on class, but on functions, as was indicated in the problem.
parent a7c9b298
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......@@ -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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment