Mailinglist Archive: yast-commit (535 mails)

< Previous Next >
[yast-commit] r41234 - /trunk/python-bindings/src/YPython.cc
  • From: juhliarik@xxxxxxxxxxxxxxxx
  • Date: Wed, 03 Oct 2007 13:37:11 -0000
  • Message-id: <20071003133711.823452FC6C@xxxxxxxxxxxxxxxx>
Author: juhliarik
Date: Wed Oct  3 15:37:10 2007
New Revision: 41234

URL: http://svn.opensuse.org/viewcvs/yast?rev=41234&view=rev
Log:
added check for existing importing module in global dictionary


Modified:
    trunk/python-bindings/src/YPython.cc

Modified: trunk/python-bindings/src/YPython.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.cc?rev=41234&r1=41233&r2=41234&view=diff
==============================================================================
--- trunk/python-bindings/src/YPython.cc (original)
+++ trunk/python-bindings/src/YPython.cc Wed Oct  3 15:37:10 2007
@@ -81,17 +81,6 @@
     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
@@ -117,6 +106,7 @@
 {
     string path;
     string module_name;
+    PyObject* pModuleName;
     size_t found;
     PyObject* pMain;
 
@@ -135,13 +125,20 @@
        YPython::_pMainDicts = PyDict_New();
     }
 
-    //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));
+    pModuleName = PyString_FromString(module_name.c_str());
+
+    if ( PyDict_Contains(YPython::_pMainDicts, pModuleName) == 0) {
+       pMain = PyImport_ImportModule(module_name.c_str());
+       int ret = PyDict_SetItem(YPython::_pMainDicts, pModuleName, PyModule_GetDict(pMain));
+       if (ret != 0)
+          return YCPError("The module was not imported");
+    } else {
+
+       return YCPError("The module is imported");
+    }
+
 
     return YCPVoid();
  

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages