]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix of bug IPAL21005 - Dump/load python script works only with absolute path CCAR_cm3_start
authorouv <ouv@opencascade.com>
Thu, 30 Apr 2009 07:27:05 +0000 (07:27 +0000)
committerouv <ouv@opencascade.com>
Thu, 30 Apr 2009 07:27:05 +0000 (07:27 +0000)
src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx

index 063562ae304ecf23228cfda72607fdf8f79acb2d..2fa36c294f3201e642ab01d1ecc2e7efd070ad9b 100644 (file)
@@ -1210,13 +1210,24 @@ bool SALOMEDSImpl_Study::DumpStudy(const string& thePath,
   //set sys.path and add a creation of the study.
   fp << GetDumpStudyComment() << endl << endl;
   fp << "import sys" << endl;
+  fp << "import os.path" << endl;
   fp << "import " << aBatchModeScript << endl << endl;
 
   fp << aBatchModeScript << ".salome_init()" << endl << endl;
 
-  fp << _GetNoteBookAccess();
-
-  fp << "sys.path.insert( 0, \'" << thePath << "\')" << endl << endl;
+  fp << _GetNoteBookAccess() << endl;
+
+  // IPAL21005 (Dump/load python script works only with absolute path)
+  // try to use '__file__' to get an absolute path to the generated scripts
+  // or use the path passed to this method (case of using execfile() command)
+  fp << "#Get absolute path to generated scripts:" << endl;
+  fp << "try:"                                     << endl;
+  fp << "    absPath = os.path.dirname(__file__)"  << endl;
+  fp << "except NameError:"                        << endl;
+  fp << "    absPath = \'" << thePath << "\'"      << endl;
+  fp << "    pass"                                 << endl;
+  fp << "sys.path.insert( 0, absPath )"            << endl << endl;
+  //fp << "sys.path.insert( 0, \'" << thePath << "\')" << endl << endl;
 
   //Dump NoteBook Variables
   fp << _GetStudyVariablesScript();