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

[*] Updated wrapping libdap-python. Added support for a modified version of libdap as of 08/06/2019

parent e8d7f4e8
No related branches found
No related tags found
No related merge requests found
[submodule "libdap"] [submodule "libdap"]
path = libdap path = libdap
url = https://github.com/cellframe/libdap.git url = https://gitlab.demlabs.net/cellframe/libdap.git
[submodule "libdap-crypto"] [submodule "libdap-crypto"]
path = libdap-crypto path = libdap-crypto
url = https://github.com/cellframe/libdap-crypto.git url = https://gitlab.demlabs.net/cellframe/libdap-crypto.git
Subproject commit d37b2aa26d2a7cc068529db343a87fd728904d33 Subproject commit 38662bc49038185cd57f486accbc6179a163da14
Subproject commit ff63d762657f9687173db825705b8bf4b958abee Subproject commit 59f374440ff97c46fcdaa0739eb9781979e9799b
...@@ -12,15 +12,15 @@ static PyObject *dap_init(PyObject *self, PyObject *args){ ...@@ -12,15 +12,15 @@ static PyObject *dap_init(PyObject *self, PyObject *args){
memcpy(dap_app_name_logs, dap_app_name, len_dap_app_name); memcpy(dap_app_name_logs, dap_app_name, len_dap_app_name);
const char* log = "_logs.txt"; const char* log = "_logs.txt";
memcpy(dap_app_name_logs+len_dap_app_name, log,9); memcpy(dap_app_name_logs+len_dap_app_name, log,9);
if (dap_common_init(dap_app_name, dap_app_name_logs)!=0){
log_it(L_CRITICAL, "Can't init common functions module");
return PyLong_FromLong(-2);
}
dap_config_init(system_configs_dir); dap_config_init(system_configs_dir);
if ((g_config = dap_config_open(dap_app_name) ) == NULL){ if ((g_config = dap_config_open(dap_app_name) ) == NULL){
log_it(L_CRITICAL, "Can't init general configurations"); log_it(L_CRITICAL, "Can't init general configurations");
return PyLong_FromLong(-1); return PyLong_FromLong(-1);
} }
if (dap_common_init(dap_app_name_logs)!=0){
log_it(L_CRITICAL, "Can't init common functions module");
return PyLong_FromLong(-2);
}
dap_log_level_set( dap_config_get_item_bool_default(g_config,"general","debug_mode", false)? L_DEBUG: L_NOTICE ); dap_log_level_set( dap_config_get_item_bool_default(g_config,"general","debug_mode", false)? L_DEBUG: L_NOTICE );
return PyLong_FromLong(0); return PyLong_FromLong(0);
} }
...@@ -39,7 +39,7 @@ static PyObject *dap_set_log_level(PyObject *self, PyObject *args){ ...@@ -39,7 +39,7 @@ static PyObject *dap_set_log_level(PyObject *self, PyObject *args){
short int new_log_level; short int new_log_level;
if (!PyArg_ParseTuple(args, "h", &new_log_level)) if (!PyArg_ParseTuple(args, "h", &new_log_level))
return NULL; return NULL;
if (new_log_level < 0 || new_log_level > 5 ) { if (new_log_level < 0 || new_log_level > 10 ) {
return PyLong_FromLong(-1); return PyLong_FromLong(-1);
} else { } else {
dap_log_level_set(new_log_level); dap_log_level_set(new_log_level);
...@@ -52,7 +52,7 @@ static PyObject* dap_log_it(PyObject* self, PyObject* args){ ...@@ -52,7 +52,7 @@ static PyObject* dap_log_it(PyObject* self, PyObject* args){
const char* string_output; const char* string_output;
if (!PyArg_ParseTuple(args, "h|s", &log_level, &string_output)) if (!PyArg_ParseTuple(args, "h|s", &log_level, &string_output))
return NULL; return NULL;
if (log_level < 0 || log_level > 5 ) { if (log_level < 0 || log_level > 10 ) {
return PyLong_FromLong(-1); return PyLong_FromLong(-1);
} else { } else {
log_it(log_level, string_output); log_it(log_level, string_output);
......
...@@ -6,12 +6,16 @@ class DapIniException(Exception): ...@@ -6,12 +6,16 @@ class DapIniException(Exception):
pass pass
class LogLevel(Enum): class LogLevel(Enum):
L_CRITICAL=5 L_DEBUG = 0
L_ERROR=4 L_INFO = 1
L_WARNING=3 L_NOTICE = 2
L_NOTICE=2 L_MSG = 3
L_INFO=1 L_DAP = 4
L_DEBUG=0 L_WARNING = 5
L_ATT = 6
L_ERROR = 7
L_CRITICAL = 8
L_TOTAL = 9
def init(data): def init(data):
res = json.loads(data) res = json.loads(data)
...@@ -24,7 +28,7 @@ def init(data): ...@@ -24,7 +28,7 @@ def init(data):
raise DapIniException("Initialization erorr") raise DapIniException("Initialization erorr")
if log_level != LogLevel.L_NOTICE.name: if log_level != LogLevel.L_NOTICE.name:
setLogLevel(LogLevel[log_level]) setLogLevel(LogLevel[log_level])
def deInit(): def deinit():
libdap_python_module.deinit() libdap_python_module.deinit()
def setLogLevel(logLevel): def setLogLevel(logLevel):
res_setLogLevel = libdap_python_module.setLogLevel(logLevel.value) res_setLogLevel = libdap_python_module.setLogLevel(logLevel.value)
......
...@@ -7,12 +7,11 @@ def create_config_file(app_name): ...@@ -7,12 +7,11 @@ def create_config_file(app_name):
f.write("[server]\nlisten_address=0.0.0.0\n") f.write("[server]\nlisten_address=0.0.0.0\n")
f.close() f.close()
logIt(LogLevel.L_INFO,"Start main test") print ("Start main test")
app_name = "TestAPP" app_name = "TestAPP"
logIt(LogLevel.L_INFO, "Create config file") print ("Create config file")
create_config_file(app_name) create_config_file(app_name)
json_string = """{ json_string = """{
"modules": "", "modules": "",
"dap": { "dap": {
...@@ -32,11 +31,10 @@ logIt(LogLevel.L_INFO, "Output [server] 'listen_address' = "+res1+"\n") ...@@ -32,11 +31,10 @@ logIt(LogLevel.L_INFO, "Output [server] 'listen_address' = "+res1+"\n")
res2 = configGetItemDefault("server1", "listen_address", "8.8.8.8") res2 = configGetItemDefault("server1", "listen_address", "8.8.8.8")
logIt(LogLevel.L_INFO, "Output default value '8.8.8.8' [server1] 'listen_address' = "+res2+"\n") logIt(LogLevel.L_INFO, "Output default value '8.8.8.8' [server1] 'listen_address' = "+res2+"\n")
logIt(LogLevel.L_INFO, "TEST. Get default config done") logIt(LogLevel.L_INFO, "TEST. Get default config done")
deInit()
logIt(LogLevel.L_INFO, "Deinitialization done") logIt(LogLevel.L_INFO, "Deinitialization done")
os.remove(app_name+".cfg") os.remove(app_name+".cfg")
logIt(LogLevel.L_INFO, "Dellete config file") logIt(LogLevel.L_INFO, "Dellete config file")
logIt(LogLevel.L_INFO, "Main test done"); logIt(LogLevel.L_INFO, "Main test done");
deinit()
sys.exit(0) sys.exit(0)
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