Author: juhliarik Date: Wed Oct 3 15:06:07 2007 New Revision: 41233 URL: http://svn.opensuse.org/viewcvs/yast?rev=41233&view=rev Log: reimplementation import process Modified: trunk/python-bindings/src/YPython.cc trunk/python-bindings/src/YPythonNamespace.cc Modified: trunk/python-bindings/src/YPython.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.cc?rev=41233&r1=41232&r2=41233&view=diff ============================================================================== --- trunk/python-bindings/src/YPython.cc (original) +++ trunk/python-bindings/src/YPython.cc Wed Oct 3 15:06:07 2007 @@ -56,7 +56,7 @@ YPython * YPython::_yPython = 0; -PyObject * YPython::_pMain = NULL; +PyObject * YPython::_pMainDicts = NULL; YPython::YPython(){} @@ -75,13 +75,25 @@ PyObject* -YPython::pMain() +YPython::pMainDicts() { - return _pMain; + return _pMainDicts; +} + +bool +AddNewDict(string name, PyObject* dict) +{ + int ret = PyDict_SetItem(YPython::_pMainDicts, PyString_FromString(name.c_str()), dict); + if (ret == 0) + return true; + else + return false; } + + YCPValue YPython::destroy() { @@ -106,6 +118,7 @@ string path; string module_name; size_t found; + PyObject* pMain; //found last "/" in path found = module.find_last_of("/"); @@ -119,12 +132,19 @@ if (!Py_IsInitialized()) { setenv("PYTHONPATH", path.c_str(), 1); Py_Initialize(); - + YPython::_pMainDicts = PyDict_New(); } - YPython::_pMain = PyImport_ImportModule(module_name.c_str()); + //YPython::_pMain = PyImport_ImportModule(module_name.c_str()); + + //new style + + pMain = PyImport_ImportModule(module_name.c_str()); + PyDict_SetItem(YPython::_pMainDicts, PyString_FromString(module_name.c_str()), PyModule_GetDict(pMain)); + //YPython::yPython()->AddNewDict(module_name, PyModule_GetDict(pMain)); return YCPVoid(); + } /** @@ -139,16 +159,13 @@ YPython::callInner (string module, string function, bool method, YCPList argList) { - PyObject* pMain; PyObject* pMainDict; PyObject* pFunc; PyObject* pArgs; PyObject* pReturn; YCPValue result = YCPNull (); - - //pMain = PyImport_AddModule("__main__"); - pMainDict = PyModule_GetDict(YPython::_pMain); + pMainDict = PyDict_GetItemString(YPython::yPython()->pMainDicts(),module.c_str()); pFunc = PyDict_GetItemString(pMainDict, function.c_str()); pArgs = PyTuple_New(argList->size()-1); Modified: trunk/python-bindings/src/YPythonNamespace.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPythonNamespace.cc?rev=41233&r1=41232&r2=41233&view=diff ============================================================================== --- trunk/python-bindings/src/YPythonNamespace.cc (original) +++ trunk/python-bindings/src/YPythonNamespace.cc Wed Oct 3 15:06:07 2007 @@ -154,7 +154,8 @@ long num = 0; //number of function arguments //obtain main dictionary of globals variables - pMainDict = PyModule_GetDict(YPython::yPython()->pMain()); + pMainDict = PyDict_GetItemString(YPython::yPython()->pMainDicts(),name.c_str()); + //keys from dictionary fun_names = PyDict_Keys(pMainDict); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org