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, pwd
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 os.environ.has_key('USERNAME'):
41 raise Exception('USERNAME environment variable not set')
42 return os.environ['USERNAME']
44 return pwd.getpwuid(os.getuid())[0]
46 def _lsb_release(args):
47 '''Get system information with lsb_release.
49 :param args str: The arguments to give to lsb_release.
50 :return: The distribution.
54 path = '/usr/local/bin:/usr/bin:/bin'
55 lsb_path = os.getenv("LSB_PATH")
56 if lsb_path is not None:
57 path = lsb_path + ":" + path
59 from subprocess import Popen, PIPE
60 res = Popen(['lsb_release', args], env={'PATH': path},
61 stdout=PIPE).communicate()[0][:-1]
62 # in case of python3, convert byte to str
63 if isinstance(res, bytes):
67 sys.stderr.write(_(u"lsb_release not installed\n"))
68 sys.stderr.write(_(u"You can define $LSB_PATH to give"
69 " the path to lsb_release\n"))
72 def get_distribution(codes):
73 '''Gets the code for the distribution
75 :param codes L{Mapping}: The map containing distribution correlation table.
76 :return: The distribution on which salomeTools is running, regarding the
77 distribution correlation table contained in codes variable.
84 distrib = _lsb_release('-si')
85 if codes is not None and distrib in codes:
86 distrib = codes[distrib]
88 sys.stderr.write(_(u"Unknown distribution: '%s'\n") % distrib)
89 sys.stderr.write(_(u"Please add your distribution to"
90 " data/distrib.pyconf\n"))
96 def get_distrib_version(distrib, codes):
97 '''Gets the version of the distribution
99 :param distrib str: The distribution on which the version will be found.
100 :param codes L{Mapping}: The map containing distribution correlation table.
101 :return: The version of the distribution on which salomeTools is running,
102 regarding the distribution correlation table contained in codes
108 return platform.release()
110 # Call to lsb_release
111 version = _lsb_release('-sr')
113 if version in codes[distrib]:
114 version = codes[distrib][version]
118 def get_python_version():
119 '''Gets the version of the running python.
121 :return: the version of the running python.
125 # The platform python module gives the answer
126 return platform.python_version()
129 '''Gets the number of processors of the machine
130 on which salomeTools is running.
132 :return: the number of processors.
137 import multiprocessing
138 nb_proc=multiprocessing.cpu_count()
140 nb_proc=int(os.sysconf('SC_NPROCESSORS_ONLN'))