]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
bos #18341: HOME environment variable
authorjfa <jfa@opencascade.com>
Fri, 10 Apr 2020 11:35:30 +0000 (14:35 +0300)
committervsr <vsr@opencascade.com>
Wed, 13 May 2020 14:08:51 +0000 (17:08 +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 42c0cdf8658ca55150d4ed3bd09045cc6006355e..725597a3d756a902f2d8863b7a5f2d4aacea7780 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 8e98e3b168d60b810f070698ce6eb21c98812e2a..10009f8d9280d59c0d2e4a0947bbce899512ef53 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 c7b6fbb498a47cf5d02916205e4f3f814884117e..94b0f7fd2e0672d61f6b37997ee6351f4d779ebd 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 5454abf6c973d666b44077e62d0f5c32a4a074a5..36c2411584d23682bee1ebe7bf6ffa08f291cb4f 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 d1e7867973bf40eb40ee01cfbfc465ec51597e19..66fd32671d5bc2da8223bdbe7f8c1ccbfb1d00b3 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 10e218f5fec7b4e7b5cb5a93d4f19930c934f19c..b5dad97317965c1b0850a414ed3067b8655fd1f6 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 92661e6035c4176fbdc380ce68bb944b016c7436..90079b283fca4399a28f7033977e2094dd65cf8e 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 755502acd4f2c3ed68f8f40173a4549696a94907..22b90bf285a4295df1f25c9def3da14c798d6550 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 5351908566210e074037f2ae926a62a917429efb..a6d6153ab03f8d28f1b19ef4fcaba8547eb8bc17 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 88bc2e59304180ca3c4543ae06525a352a1b2109..45d6e472d9ddafd6b6dc883102da46230d8a5fb9 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";