From b7b56c83266bce662874c74057210aeafe91dd97 Mon Sep 17 00:00:00 2001 From: jfa Date: Fri, 10 Apr 2020 14:35:30 +0300 Subject: [PATCH] Fix for bos #18341: HOME environment variable --- bin/appliskel/getAppliPath.py | 4 ++-- bin/appliskel/kill_remote_containers.py | 2 +- bin/appliskel/update_catalogs.py | 6 +++--- bin/killSalome.py | 2 +- bin/killSalomeWithPort.py | 2 +- bin/runSalome.py | 14 ++++++++------ src/Basics/Basics_DirUtils.cxx | 14 ++++++++++++++ src/Basics/Basics_DirUtils.hxx | 3 +++ src/Launcher/Launcher_Job.cxx | 10 +++++----- src/ResourcesManager/ResourcesManager.cxx | 10 +++++++--- 10 files changed, 45 insertions(+), 22 deletions(-) diff --git a/bin/appliskel/getAppliPath.py b/bin/appliskel/getAppliPath.py index e77f86f66..6ce7001b6 100755 --- a/bin/appliskel/getAppliPath.py +++ b/bin/appliskel/getAppliPath.py @@ -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) diff --git a/bin/appliskel/kill_remote_containers.py b/bin/appliskel/kill_remote_containers.py index 6de81b1e5..d16c792a1 100755 --- a/bin/appliskel/kill_remote_containers.py +++ b/bin/appliskel/kill_remote_containers.py @@ -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] diff --git a/bin/appliskel/update_catalogs.py b/bin/appliskel/update_catalogs.py index fb637b342..b35cb6b56 100755 --- a/bin/appliskel/update_catalogs.py +++ b/bin/appliskel/update_catalogs.py @@ -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")) diff --git a/bin/killSalome.py b/bin/killSalome.py index cafe632f7..9323c9841 100755 --- a/bin/killSalome.py +++ b/bin/killSalome.py @@ -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 diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index 6fc8bae13..752e6dc2f 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -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 diff --git a/bin/runSalome.py b/bin/runSalome.py index 4ef93e418..601a2b0e3 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -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']: diff --git a/src/Basics/Basics_DirUtils.cxx b/src/Basics/Basics_DirUtils.cxx index 8a1974a96..dc2c81fee 100644 --- a/src/Basics/Basics_DirUtils.cxx +++ b/src/Basics/Basics_DirUtils.cxx @@ -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; + } } diff --git a/src/Basics/Basics_DirUtils.hxx b/src/Basics/Basics_DirUtils.hxx index 34dbc7a69..cb3cf4350 100644 --- a/src/Basics/Basics_DirUtils.hxx +++ b/src/Basics/Basics_DirUtils.hxx @@ -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 diff --git a/src/Launcher/Launcher_Job.cxx b/src/Launcher/Launcher_Job.cxx index 81fd5fc2c..21b068cf8 100644 --- a/src/Launcher/Launcher_Job.cxx +++ b/src/Launcher/Launcher_Job.cxx @@ -22,6 +22,9 @@ //#define _DEBUG_ #include "Launcher_Job.hxx" #include "Launcher.hxx" + +#include + #include #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 in_files(_in_files); in_files.push_back(_job_file); diff --git a/src/ResourcesManager/ResourcesManager.cxx b/src/ResourcesManager/ResourcesManager.cxx index a90ad7004..f9ba9b704 100644 --- a/src/ResourcesManager/ResourcesManager.cxx +++ b/src/ResourcesManager/ResourcesManager.cxx @@ -21,8 +21,11 @@ // #include "ResourcesManager.hxx" + #include "SALOME_ResourcesCatalog_Handler.hxx" #include +#include + #include #include #include @@ -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"; -- 2.39.2