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
38 # In windows case, the USERNAME environment variable has to be set
40 if not 'USERNAME' in os.environ:
41 raise Exception('USERNAME environment variable not set')
42 return os.environ['USERNAME']
45 return pwd.getpwuid(os.getuid())[0]
48 def get_distribution(codes):
49 '''Gets the code for the distribution
51 :param codes L{Mapping}: The map containing distribution correlation table.
52 :return: The distribution on which salomeTools is running, regarding the
53 distribution correlation table contained in codes variable.
59 # else get linux distribution description from platform, and encode it with code
60 lin_distrib = platform.dist()[0].lower()
63 if dist in lin_distrib:
66 if distrib=="not found":
67 sys.stderr.write(_(u"Unknown distribution: '%s'\n") % distrib)
68 sys.stderr.write(_(u"Please add your distribution to src/internal_config/distrib.pyconf\n"))
75 Return major and minor version of the distribution
76 from a CentOS example, returns '7.6'
77 extracted from platform.dist()
79 dist_version=platform.dist()[1].split('.')
80 if len(dist_version)==1:
81 version = dist_version[0]
83 version = dist_version[0] + "." + dist_version[1]
87 def get_distrib_version(distrib):
88 '''Return the sat encoded version of the distribution
89 This code is used in config to apend the name of the application directories
90 withdistribution info"
92 :param distrib str: The distribution on which the version will be found.
93 :return: The version of the distribution on which salomeTools is running,
94 regarding the distribution correlation table contained in codes
100 return platform.release()
102 # get version from platform
103 dist_version=platform.dist()[1].split('.')
105 # encode it (conform to src/internal_config/distrib.pyconf VERSIONS dist
107 version=dist_version[0] # for centos, we only care for major version
108 elif distrib == "UB":
109 # for ubuntu, we care for major + minor version
110 version=dist_version[0] + "." + dist_version[1]
111 elif distrib == "DB":
112 if len(dist_version[0]) == 1:
113 version="0"+dist_version[0]
115 version=dist_version[0] # unstable, and version >= 10
116 elif distrib == "MG":
117 version="0"+dist_version[0]
119 version=dist_version[0]
123 def get_python_version():
124 '''Gets the version of the running python.
126 :return: the version of the running python.
130 # The platform python module gives the answer
131 return platform.python_version()
134 '''Gets the number of processors of the machine
135 on which salomeTools is running.
137 :return: the number of processors.
142 import multiprocessing
143 nb_proc=multiprocessing.cpu_count()
145 nb_proc=int(os.sysconf('SC_NPROCESSORS_ONLN'))