Salome HOME
Properly set sys.argv in Python interpreter when using driver executable
authorRenaud Barate <renaud.barate@edf.fr>
Tue, 8 Jul 2014 14:50:14 +0000 (16:50 +0200)
committerRenaud Barate <renaud.barate@edf.fr>
Tue, 8 Jul 2014 14:50:14 +0000 (16:50 +0200)
src/runtime/RuntimeSALOME.cxx
src/runtime/RuntimeSALOME.hxx
src/yacsloader/driver.cxx

index 9a56086d776e70f07615a83a864a0f8f6e45463f..288553987f170277fc1b602cfc0e6ad02da8f98a 100644 (file)
 using namespace std;
 using namespace YACS::ENGINE;
 
-void RuntimeSALOME::setRuntime(long flags) // singleton creation (not thread safe!)
+void RuntimeSALOME::setRuntime(long flags, int argc, char* argv[]) // singleton creation (not thread safe!)
 {
   if (! Runtime::_singleton)
     {
-      RuntimeSALOME* r=new RuntimeSALOME(flags);
+      RuntimeSALOME* r=new RuntimeSALOME(flags, argc, argv);
       Runtime::_singleton = r;
       r->initBuiltins();
     }
@@ -182,7 +182,7 @@ void RuntimeSALOME::initBuiltins()
   typeMap["dataref"]= t;
 }
 
-RuntimeSALOME::RuntimeSALOME(long flags)
+RuntimeSALOME::RuntimeSALOME(long flags, int argc, char* argv[])
 {
   // If all flags (apart the IsPyExt flags) are unset, force them to true
   if ((flags - flags & RuntimeSALOME::IsPyExt) == 0)
@@ -209,7 +209,7 @@ RuntimeSALOME::RuntimeSALOME(long flags)
   if (_usePython) _setOfImplementation.insert(PythonNode::IMPL_NAME);
   if (_useCorba)  _setOfImplementation.insert(CORBANode::IMPL_NAME);
   if (_useXml)    _setOfImplementation.insert(XmlNode::IMPL_NAME);
-  init(flags);
+  init(flags, argc, argv);
 }
 
 RuntimeSALOME::~RuntimeSALOME()
@@ -236,7 +236,7 @@ RuntimeSALOME::~RuntimeSALOME()
  *
  */
 
-void RuntimeSALOME::init(long flags)
+void RuntimeSALOME::init(long flags, int argc, char* argv[])
 {
   bool ispyext = flags & RuntimeSALOME::IsPyExt;
   if (_useCorba)
@@ -270,6 +270,7 @@ void RuntimeSALOME::init(long flags)
 #else
           Py_InitializeEx(0); // do not install signal handlers
 #endif
+          PySys_SetArgv(argc, argv);
           PyEval_InitThreads(); /* Create (and acquire) the interpreter lock (for threads)*/
           PyEval_SaveThread(); /* Release the thread state */
           //here we do not have the Global Interpreter Lock
index 9a3a9dd765304744b85d3e6e1308c17ccea50da6..20f5d63c0a8ae5296350753c46f206c691163562 100644 (file)
@@ -86,13 +86,15 @@ namespace YACS
         UseSalome = 32
       } FLAGS;
 
-      static void setRuntime(long flags = UsePython+UseCorba+UseXml+UseCpp+UseSalome); // singleton creation
+      // singleton creation
+      static void setRuntime(long flags = UsePython+UseCorba+UseXml+UseCpp+UseSalome,
+                             int argc = 0, char* argv[] = NULL);
       
       friend RuntimeSALOME* getSALOMERuntime();
       
       virtual std::string getVersion() const;
 
-      virtual void init(long flags);
+      virtual void init(long flags, int argc, char* argv[]);
       virtual void fini();
 
       virtual InputPort* createInputPort(const std::string& name,
@@ -250,7 +252,7 @@ namespace YACS
 
     protected:
       RuntimeSALOME();  // singleton
-      RuntimeSALOME(long flags);  // singleton
+      RuntimeSALOME(long flags, int argc, char* argv[]);  // singleton
       void initBuiltins();
       CORBA::ORB_var _orb;
       PyObject * _pyorb;
index c081a97f29465ab522cfe51314faf9710c063bbf..cfb9350aa00f2e77cf1b06873b748154dcb414a4 100644 (file)
@@ -312,7 +312,9 @@ int main (int argc, char* argv[])
 #endif
 
   timer("Starting ");
-  RuntimeSALOME::setRuntime();
+  long flags = RuntimeSALOME::UsePython + RuntimeSALOME::UseCorba + RuntimeSALOME::UseXml + \
+               RuntimeSALOME::UseCpp + RuntimeSALOME::UseSalome;
+  RuntimeSALOME::setRuntime(flags, argc, argv);
 
   // Try to load the session catalog if it exists
   try