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

[-] Removed unnecessary comments, code sections that are not used.

parent 3f8955a7
No related branches found
No related tags found
1 merge request!1Features 2466
#include "libdap-python.h" #include "libdap-python.h"
/*static PyObject *dap_init(PyObject *self, PyObject *args){
//const char *data;
const char *system_configs_dir;
const char *dap_app_name;
char *dap_app_name_logs;
if (!PyArg_ParseTuple(args, "s|s", &system_configs_dir, &dap_app_name))
return NULL;
int len_dap_app_name = strlen(dap_app_name);
dap_app_name_logs = calloc((len_dap_app_name+9), sizeof(char));
memcpy(dap_app_name_logs, dap_app_name, len_dap_app_name);
const char* log = "_logs.txt";
memcpy(dap_app_name_logs+len_dap_app_name, log,9);
dap_config_init(system_configs_dir);
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);
}
if ((g_config = dap_config_open(dap_app_name) ) == NULL){
log_it(L_CRITICAL, "Can't init general configurations");
return PyLong_FromLong(-1);
}
dap_log_level_set( dap_config_get_item_bool_default(g_config,"general","debug_mode", false)? L_DEBUG: L_NOTICE );
return PyLong_FromLong(0);
}
static PyObject *dap_deinit(){
log_it(L_DEBUG, "Running function dap_deinit");
dap_config_close(g_config);
log_it(L_DEBUG, "Config file closed.");
dap_config_deinit();
log_it(L_DEBUG, "Function dap_config_deinit done.");
log_it(L_DEBUG, "Function dap_deinit done.");
return PyLong_FromLong(0);
}*/
PyObject *dap_set_log_level(PyObject *self, PyObject *args){ 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))
...@@ -155,32 +120,3 @@ PyObject* py_m_dap_config_get_item_default(PyObject *self, PyObject *args){ ...@@ -155,32 +120,3 @@ PyObject* py_m_dap_config_get_item_default(PyObject *self, PyObject *args){
const char *res = dap_config_get_item_str_default(g_config, section_path, item_name, def); const char *res = dap_config_get_item_str_default(g_config, section_path, item_name, def);
return Py_BuildValue("s", res); return Py_BuildValue("s", res);
} }
/*PyMODINIT_FUNC PyInit_libdap_python_module(void){
return PyModule_Create(&dapmodule);
}*/
//int main(int argc, char **argv) {
// wchar_t *program = Py_DecodeLocale(argv[0], NULL);
// if (program == NULL) {
// fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
// exit(1);
// }
// /* Add a built-in module, before Py_Initialize */
// PyImport_AppendInittab("libdap_python_module", PyInit_libdap_python_module);
// /* Pass argv[0] to the Python interpreter */
// Py_SetProgramName(program);
// /* Initialize the Python interpreter. Required. */
// Py_Initialize();
// /* Optionally import the module; alternatively,
// import can be deferred until the embedded script
// imports it. */
// PyImport_ImportModule("libdap_python_module");
// PyMem_RawFree(program);
// return 0;
//}
...@@ -14,10 +14,6 @@ typedef struct PyDap{ ...@@ -14,10 +14,6 @@ typedef struct PyDap{
PyObject_HEAD PyObject_HEAD
}PyDapObject; }PyDapObject;
//static PyObject *dap_init(PyObject *self, PyObject *args);
//static PyObject *dap_deinit(PyObject *self, PyObject *args);
PyObject *dap_set_log_level(PyObject *self, PyObject *args); PyObject *dap_set_log_level(PyObject *self, PyObject *args);
PyObject* dap_log_it(PyObject* self, PyObject* args); PyObject* dap_log_it(PyObject* self, PyObject* args);
...@@ -37,21 +33,15 @@ PyObject* py_m_dap_config_get_item(PyObject *self, PyObject *args); ...@@ -37,21 +33,15 @@ PyObject* py_m_dap_config_get_item(PyObject *self, PyObject *args);
PyObject* py_m_dap_config_get_item_default(PyObject *self, PyObject *args); PyObject* py_m_dap_config_get_item_default(PyObject *self, PyObject *args);
static PyMethodDef DapMethods[] = { static PyMethodDef DapMethods[] = {
//{"init", dap_init, METH_VARARGS, "Initialization of the DAP (Deus Applicaions Prototypes) library"},
//{"deinit", dap_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) library"},
//{"setLogLevel", (PyCFunction)dap_set_log_level, METH_STATIC, "Setting the logging level"},
//{"logIt", (PyCFunction)dap_log_it, METH_STATIC, "The wrapper of the log_it function for the libdap library"},
//{"configGetItem", (PyCFunction)py_m_dap_config_get_item, METH_STATIC, ""},
//{"configGetItemDefault", (PyCFunction)py_m_dap_config_get_item_default, METH_STATIC, ""},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
static PyTypeObject DapObject_DapObjectType = { static PyTypeObject DapObject_DapObjectType = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"libCellFrame.Dap", /* tp_name */ "CellFrame.Dap", /* tp_name */
sizeof(PyDapObject), /* tp_basicsize */ sizeof(PyDapObject), /* tp_basicsize */
0, /* tp_itemsize */ 0, /* tp_itemsize */
0,//(destructor)Noddy_dealloc, /* tp_dealloc */ 0, /* tp_dealloc */
0, /* tp_print */ 0, /* tp_print */
0, /* tp_getattr */ 0, /* tp_getattr */
0, /* tp_setattr */ 0, /* tp_setattr */
...@@ -75,33 +65,19 @@ static PyTypeObject DapObject_DapObjectType = { ...@@ -75,33 +65,19 @@ static PyTypeObject DapObject_DapObjectType = {
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
DapMethods,//Noddy_methods, /* tp_methods */ DapMethods, /* tp_methods */
0,//Noddy_members, /* tp_members */ 0, /* tp_members */
0,//Noddy_getseters, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
0,//(initproc)PyDapEventsObject_init,//(initproc)Noddy_init, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
PyType_GenericNew,//Noddy_new, /* tp_new */ PyType_GenericNew, /* tp_new */
}; };
//static struct PyModuleDef dapmodule = {
// PyModuleDef_HEAD_INIT,
// "libdap_python_module", /* name of module */
// NULL, /* module documentation, may be NULL */
// -1, /* size of per-interpreter state of the module,
// or -1 if the module keeps state in global variables. */
// DapMethods
//};
//PyMODINIT_FUNC PyInit_libdap_python_module(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
import json
from enum import Enum
import libdap_python_module
class DapIniException(Exception):
pass
class LogLevel(Enum):
L_CRITICAL=5
L_ERROR=4
L_WARNING=3
L_NOTICE=2
L_INFO=1
L_DEBUG=0
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 != LogLevel.L_NOTICE.name:
setLogLevel(LogLevel[log_level])
def deInit():
libdap_python_module.deinit()
def setLogLevel(logLevel):
res_setLogLevel = libdap_python_module.setLogLevel(logLevel.value)
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(logLevel, data):
res_log_it = libdap_python_module.logIt(logLevel.value, 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)
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