-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.cpp
93 lines (61 loc) · 2.88 KB
/
Configuration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Configuration.hpp"
using namespace std;
Configuration::Configuration() :
RunAsUnixUserID(RUNAS_USER_DEFAULT),
RunAsUnixGroupID(RUNAS_GROUP_DEFAULT)
{
//- TODO: exception handling
DBG(120, "Constructor");
namespace bp = boost::python;
const string PScript = "/home/cpruefer/Documents/Repos/data-gateway/python/config.py";
FILE* fp = fopen(PScript.c_str(), "r");
PyObject *MainModule, *MainDict, *TmpPyObject;
Py_InitializeEx(0);
PyRun_SimpleFile(fp, PScript.c_str());
MainModule = PyImport_ImportModule("__main__");
MainDict = PyModule_GetDict(MainModule);
TmpPyObject = PyMapping_GetItemString(MainDict, "server_run_user");
RunAsUnixUser = PyUnicode_AsUTF8(TmpPyObject);
TmpPyObject = PyMapping_GetItemString(MainDict, "server_run_group");
RunAsUnixGroup = PyUnicode_AsUTF8(TmpPyObject);
TmpPyObject = PyMapping_GetItemString(MainDict, "path_base");
BasePath = PyUnicode_AsUTF8(TmpPyObject);
TmpPyObject = PyMapping_GetItemString(MainDict, "server_ip");
ServerAddress = PyUnicode_AsUTF8(TmpPyObject);
TmpPyObject = PyMapping_GetItemString(MainDict, "server_port");
ServerPort = stoi(PyUnicode_AsUTF8(TmpPyObject));
TmpPyObject = PyMapping_GetItemString(MainDict, "mimetypes");
bp::list TmpMimetypes = bp::extract<bp::list>(TmpPyObject);
for (uint16_t i=0; i<len(TmpMimetypes); ++i) {
Mimetypes.push_back(bp::extract<string>(TmpMimetypes[i]));
}
TmpPyObject = PyMapping_GetItemString(MainDict, "namespaces");
bp::list TmpNamespaces = bp::extract<bp::list>(TmpPyObject);
for (uint16_t i=0; i<len(TmpNamespaces); ++i) {
string NamespaceID;
NamespaceProps_t NamespaceProps;
string AttributeID;
DBG(-1, "Namespace:" << i);
bp::dict TmpAttributesDict = bp::extract<bp::dict>(TmpNamespaces[i]);
bp::list DictAttributes = TmpAttributesDict.items();
NamespaceProps.FilesystemRef = nullptr;
for (uint16_t x=0; x<len(DictAttributes)-1; ++x) {
DBG(-1, "Attribute Nr:" << x);
AttributeID = bp::extract<string>(DictAttributes[x][0]);
const string AttributeValue = bp::extract<string>(DictAttributes[x][1]);
DBG(-1, "AttributeID:" << AttributeID << " Value:" << AttributeValue);
if (AttributeID == "hostname") { NamespaceID = AttributeValue; }
if (AttributeID == "path") { NamespaceProps.PathRel = AttributeValue; }
if (AttributeID == "interpreters") { NamespaceProps.InterpreterCount = stoi(AttributeValue); }
}
DBG(-1, "Namespace:" << NamespaceID << " Path:" << NamespaceProps.PathRel << " Interpreters:" << NamespaceProps.InterpreterCount);
Namespaces.insert(
NamespacePair_t(NamespaceID, NamespaceProps)
);
}
Py_FinalizeEx();
}
Configuration::~Configuration()
{
DBG(120, "Destructor");
}