]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix for bos #18341: HOME environment variable jfa/18341_HOME
authorjfa <jfa@opencascade.com>
Fri, 10 Apr 2020 11:35:30 +0000 (14:35 +0300)
committerjfa <jfa@opencascade.com>
Fri, 10 Apr 2020 11:35:30 +0000 (14:35 +0300)
bin/appliskel/getAppliPath.py
bin/appliskel/kill_remote_containers.py
bin/appliskel/update_catalogs.py
bin/killSalome.py
bin/killSalomeWithPort.py
bin/runSalome.py
src/Basics/Basics_DirUtils.cxx
src/Basics/Basics_DirUtils.hxx
src/Launcher/Launcher_Job.cxx
src/ResourcesManager/ResourcesManager.cxx

index e77f86f66a8e871decab09d114ff9ad80132b273..6ce7001b62750a95858b5a860609bf58eecca728 100755 (executable)
@@ -51,14 +51,14 @@ def get_appli_path(filePath=None):
     if filePath is None:
         filePath = os.path.realpath(os.path.dirname(__file__))
 
-    homePath = os.path.realpath(os.getenv('HOME'))
+    homePath = os.path.realpath(os.path.expanduser("~"))
     applipath = os.path.relpath(filePath, homePath)
     return applipath
 #
 
 if __name__ == "__main__":
     if sys.hexversion < 0x02060000: # Python older than 2.6.0
-        applipath = relpath(os.path.realpath(os.path.dirname(__file__)),os.path.realpath(os.getenv('HOME')))
+        applipath = relpath(os.path.realpath(os.path.dirname(__file__)),os.path.realpath(os.path.expanduser("~")))
     else:
         applipath = get_appli_path()
     print(applipath)
index 6de81b1e5af78f140d1f1cdb7c0ddffc47b21c52..d16c792a16e02862b82a6ec92f9fbc6261f91741 100755 (executable)
@@ -30,7 +30,7 @@ from salome_utils import getUserName
 
 import getAppliPath
 appli_local=os.path.realpath(os.path.dirname(__file__))
-APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.getenv('HOME')))
+APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.path.expanduser("~")))
 
 usage="""%(prog)s [options]
 
index fb637b342d32a991a2a41671bca89729e4d19734..b35cb6b562cfbbab29a98fd686a83654b9da3064 100755 (executable)
@@ -30,7 +30,7 @@ from salome_utils import getUserName
 
 import getAppliPath
 appli_local=os.path.realpath(os.path.dirname(__file__))
-APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.getenv('HOME')))
+APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.path.expanduser("~")))
 
 usage="""%(prog)s [options]
 Typical use is:
@@ -148,7 +148,7 @@ class Resource:
       #local machine, use cp
       if appliPath[0]!='/':
         #relative path
-        appliPath=os.path.join(os.getenv("HOME"),appliPath)
+        appliPath=os.path.join(os.path.expanduser("~"),appliPath)
 
       if appliPath == appli_local:
         return
@@ -191,7 +191,7 @@ class Resource:
     if hostname == "localhost" or hostname == get_hostname() and userName == getUserName():
       #user local resource
       if appliPath[0]!='/':
-        appliPath=os.path.join(os.getenv("HOME"),appliPath)
+        appliPath=os.path.join(os.path.expanduser("~"),appliPath)
       if appliPath == appli_local:
         #main local resource: get catalogs in share/salome/resources
         catalogs_list=glob.glob(os.path.join(appliPath,"share","salome","resources","*","*Catalog.xml"))
index cafe632f7664b8e982f0e3ef61ce08f7ef7b5ef9..9323c9841472bd665465e71e67309f3604a73055 100755 (executable)
@@ -103,7 +103,7 @@ def killAllPorts():
             pass
         pass
         # delete uri files needed by ompi-server
-        cmd = "rm -f " + os.environ['HOME'] + "/.urifile_*"
+        cmd = "rm -f " + os.path.expanduser("~") + "/.urifile_*"
         os.system(cmd)
     pass
 
index 6fc8bae13cd38d3b3f0be652df7cef328c03831e..752e6dc2f449aaa09993c8257f475403a24c6f36 100755 (executable)
@@ -76,7 +76,7 @@ def getPiDict(port,appname='salome',full=True,hidden=True,hostname=None):
         else:
             # old-style non-dot-prefixed pidict files
             # are in the user's home directory
-            dir = os.getenv("HOME")
+            dir = os.path.expanduser("~")
             pass
         pass
 
index 4ef93e418bb2bcffa1d13b0c18d0915aa4718d56..601a2b0e3c3c4d384a7c8d5e18f156de65078021 100755 (executable)
@@ -154,9 +154,9 @@ class CatalogServer(Server):
               self.SCMD1+=["NameService=corbaname::" + machine + ":" + port]
         self.SCMD1+=['-common']
         self.SCMD2=[]
-        home_dir=os.getenv('HOME')
+        home_dir=os.path.expanduser("~")
         if home_dir is not None:
-            self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
+            self.SCMD2=['-personal',os.path.join(home_dir,'Salome', 'resources', 'CatalogModulePersonnel.xml')]
 
     def setpath(self,modules_list,modules_root_dir):
         list_modules = modules_list[:]
@@ -284,9 +284,9 @@ class SessionServer(Server):
                          '(','--salome_session','theSession',')']
         if 'moduleCatalog' in self.args['embedded']:
             self.SCMD1+=['--with','ModuleCatalog','(','-common']
-            home_dir=os.getenv('HOME')
+            home_dir=os.path.expanduser("~")
             if home_dir is not None:
-                self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
+                self.SCMD2+=['-personal',os.path.join(home_dir,'Salome','resources','CatalogModulePersonnel.xml')]
             self.SCMD2+=[')']
         if 'study' in self.args['embedded']:
             self.SCMD2+=['--with','SALOMEDS','(',')']
@@ -398,8 +398,10 @@ class LauncherServer(Server):
                              '(','--salome_session','theSession',')']
             if 'moduleCatalog' in self.args['embedded']:
                 self.SCMD1+=['--with','ModuleCatalog','(','-common']
-                self.SCMD2+=['-personal',
-                             '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
+                home_dir=os.path.expanduser("~")
+                if home_dir is not None:
+                    self.SCMD2=['-personal',os.path.join(home_dir,'Salome','resources','CatalogModulePersonnel.xml')]
+                self.SCMD2+=[')']
             if 'study' in self.args['embedded']:
                 self.SCMD2+=['--with','SALOMEDS','(',')']
             if 'cppContainer' in self.args['embedded']:
index 8a1974a96f21106736cbf46264a0df20e5d2619e..dc2c81fee37d930dde71ba983316f464f2940d67 100644 (file)
@@ -351,4 +351,18 @@ namespace Kernel_Utils
          std::replace(res.begin(), res.end(), '\\', '/');
          return res;
   }
+
+
+  //============================================================================
+  // function : BackSlashToSlash  
+  // purpose  : Convert back slash to slash
+  //============================================================================ 
+  std::string HomePath() {
+#ifdef WIN32
+    std::string homedir = getenv("USERPROFILE");
+#else
+    std::string homedir = getenv("HOME");       
+#endif
+    return homedir;
+  }
 }
index 34dbc7a69f0e3f1d467d2a241ba488b97d929495..cb3cf43502df590f92ed32a16c161823f6f95794 100644 (file)
@@ -70,6 +70,9 @@ namespace Kernel_Utils
   BASICS_EXPORT bool IsEmptyDir( const std::string& path );
 
   BASICS_EXPORT std::string BackSlashToSlash( const std::string& path );
+
+  // Returns getenv("HOME") for Unix or getenv("USERPROFILE") for WIN32
+  BASICS_EXPORT std::string HomePath();
 }
 
 #endif
index 81fd5fc2cf94b407cd2cc0ceba7a4b5822b672de..21b068cf8e7f7babe6b0fd982ba2a8d41fdf407c 100644 (file)
@@ -22,6 +22,9 @@
 //#define _DEBUG_
 #include "Launcher_Job.hxx"
 #include "Launcher.hxx"
+
+#include <Basics_DirUtils.hxx>
+
 #include <boost/filesystem.hpp>
 
 #ifdef WITH_LIBBATCH
@@ -667,11 +670,8 @@ Launcher::Job::common_job_params()
 
   // If result_directory is not defined, we use HOME environment
   if (_result_directory == "")
-#ifndef WIN32
-    _result_directory = getenv("HOME");
-#else
-    _result_directory = getenv("USERPROFILE");
-#endif
+    _result_directory = Kernel_Utils::HomePath();
+
   // _in_files
   std::list<std::string> in_files(_in_files);
   in_files.push_back(_job_file);
index a90ad700413fcf5747f36974bc293d4da2334cd1..f9ba9b70412a6d7ed0fd30cb1f5fd5099a2e58d4 100644 (file)
 //
 
 #include "ResourcesManager.hxx" 
+
 #include "SALOME_ResourcesCatalog_Handler.hxx"
 #include <Basics_Utils.hxx>
+#include <Basics_DirUtils.hxx>
+
 #include <fstream>
 #include <iostream>
 #include <sstream>
@@ -145,7 +148,7 @@ ResourcesManager_cpp::ResourcesManager_cpp() throw(ResourcesException)
     std::string default_file("");
     if (getenv("APPLI") != 0)
     {
-      default_file += getenv("HOME");
+      default_file += Kernel_Utils::HomePath();
       default_file += "/";
       default_file += getenv("APPLI");
       default_file += "/CatalogResources.xml";
@@ -624,7 +627,8 @@ void ResourcesManager_cpp::AddDefaultResourceInCatalog()
   resource.Batch = none;
 #ifndef WIN32
   struct stat statbuf;
-  if (getenv("HOME") != NULL && getenv("APPLI") != NULL)
+  std::string aHomePath = Kernel_Utils::HomePath();
+  if (aHomePath != "" && getenv("APPLI") != NULL)
   {
     if (stat(getenv("APPLI"), &statbuf) ==0 &&  S_ISREG(statbuf.st_mode))
     {
@@ -633,7 +637,7 @@ void ResourcesManager_cpp::AddDefaultResourceInCatalog()
     }
     else
     {
-        resource.AppliPath = string(getenv("HOME")) + "/" + getenv("APPLI");
+        resource.AppliPath = aHomePath + "/" + getenv("APPLI");
     }
   }
   string tmpdir = "/tmp";