3 # Copyright (C) 2010-2013 CEA/DEN
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 In this file : all the stuff that can change with the architecture
21 on which SAT is running
24 import os, sys, platform
27 '''method that checks windows OS
31 return platform.system() == 'Windows'
34 '''method that gets the username that launched sat
40 # In windows case, the USERNAME environment variable has to be set
41 user_name=os.environ['USERNAME']
44 user_name=pwd.getpwuid(os.getuid())[0]
50 def get_distribution(codes):
51 '''Gets the code for the distribution
53 :param codes L{Mapping}: The map containing distribution correlation table.
54 :return: The distribution on which salomeTools is running, regarding the
55 distribution correlation table contained in codes variable.
61 # else get linux distribution description from platform, and encode it with code
62 lin_distrib = platform.dist()[0].lower()
65 if dist in lin_distrib:
68 if distrib=="not found":
69 sys.stderr.write(_(u"Unknown distribution: '%s'\n") % distrib)
70 sys.stderr.write(_(u"Please add your distribution to src/internal_config/distrib.pyconf\n"))
77 Return major and minor version of the distribution
78 from a CentOS example, returns '7.6'
79 extracted from platform.dist()
81 dist_version=platform.dist()[1].split('.')
82 if len(dist_version)==1:
83 version = dist_version[0]
85 version = dist_version[0] + "." + dist_version[1]
89 def get_distrib_version(distrib):
90 '''Return the sat encoded version of the distribution
91 This code is used in config to apend the name of the application directories
92 withdistribution info"
94 :param distrib str: The distribution on which the version will be found.
95 :return: The version of the distribution on which salomeTools is running,
96 regarding the distribution correlation table contained in codes
102 return platform.release()
104 # get version from platform
105 dist_version=platform.dist()[1].split('.')
107 # encode it (conform to src/internal_config/distrib.pyconf VERSIONS dist
109 version=dist_version[0] # for centos, we only care for major version
110 elif distrib == "UB":
111 # for ubuntu, we care for major + minor version
112 version=dist_version[0] + "." + dist_version[1]
113 elif distrib == "DB":
114 if len(dist_version[0]) == 1:
115 version="0"+dist_version[0]
117 version=dist_version[0] # unstable, and version >= 10
118 elif distrib == "MG":
119 version="0"+dist_version[0]
121 version=dist_version[0]
125 def get_python_version():
126 '''Gets the version of the running python.
128 :return: the version of the running python.
132 # The platform python module gives the answer
133 return platform.python_version()
136 '''Gets the number of processors of the machine
137 on which salomeTools is running.
139 :return: the number of processors.
144 import multiprocessing
145 nb_proc=multiprocessing.cpu_count()
147 nb_proc=int(os.sysconf('SC_NPROCESSORS_ONLN'))