X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Farchitecture.py;h=6e83d0beeea8dcb950ea3f9cd0c98dba03cd7e8d;hb=c76437f0fb9f7f66bfca0eb10674fbdd3d22ba6c;hp=662578ec0fe062db00331cda8c3f81fd78cb0d20;hpb=e45de9349c425e5c640a1710ac6f83b6f6ab64e8;p=tools%2Fsat.git diff --git a/src/architecture.py b/src/architecture.py index 662578e..6e83d0b 100644 --- a/src/architecture.py +++ b/src/architecture.py @@ -21,28 +21,47 @@ In this file : all the stuff that can change with the architecture on which SAT is running ''' -import os, sys, platform +import os, sys +from platform import system,python_version,release + +# linux_distribution is removed from platform module in python 3.8+ +# we have to use distro module, which is not standard. +# write an error message if distro is not installed +try: + from platform import linux_distribution +except: + try: + from distro import linux_distribution + except: + print ("\nError :\n" + " linux_distribution was removed from platform module in Python 3.8+\n" + " For python 3.8+ sat requires distro module to get information on linux distribution.\n" + " Please install distro module with : pip install distro") + sys.exit(-1) + def is_windows(): '''method that checks windows OS :rtype: boolean ''' - return platform.system() == 'Windows' + return system() == 'Windows' def get_user(): '''method that gets the username that launched sat :rtype: str ''' - # In windows case, the USERNAME environment variable has to be set - if is_windows(): - if not 'USERNAME' in os.environ: - raise Exception('USERNAME environment variable not set') - return os.environ['USERNAME'] - else: # linux - import pwd - return pwd.getpwuid(os.getuid())[0] + try : + if is_windows(): + # In windows case, the USERNAME environment variable has to be set + user_name=os.environ['USERNAME'] + else: # linux + import pwd + user_name=pwd.getpwuid(os.getuid())[0] + except : + user_name="Unknown" + return user_name def get_distribution(codes): @@ -57,7 +76,7 @@ def get_distribution(codes): return "W" # else get linux distribution description from platform, and encode it with code - lin_distrib = platform.dist()[0].lower() + lin_distrib = linux_distribution()[0].lower() distrib="not found" for dist in codes: if dist in lin_distrib: @@ -74,9 +93,9 @@ def get_version_XY(): """ Return major and minor version of the distribution from a CentOS example, returns '7.6' - extracted from platform.dist() + extracted from platform.linux_distribution() """ - dist_version=platform.dist()[1].split('.') + dist_version=linux_distribution()[1].split('.') if len(dist_version)==1: version = dist_version[0] else: @@ -97,10 +116,10 @@ def get_distrib_version(distrib): ''' if is_windows(): - return "64" + return release() # get version from platform - dist_version=platform.dist()[1].split('.') + dist_version=linux_distribution()[1].split('.') # encode it (conform to src/internal_config/distrib.pyconf VERSIONS dist if distrib == "CO": @@ -128,7 +147,7 @@ def get_python_version(): ''' # The platform python module gives the answer - return platform.python_version() + return python_version() def get_nb_proc(): '''Gets the number of processors of the machine @@ -142,5 +161,11 @@ def get_nb_proc(): import multiprocessing nb_proc=multiprocessing.cpu_count() except : - nb_proc=int(os.sysconf('SC_NPROCESSORS_ONLN')) + if is_windows(): + if os.environ.has_key("NUMBER_OF_PROCESSORS"): + nb_proc = int(os.environ["NUMBER_OF_PROCESSORS"]) + else: + nb_proc = 1 + else: + nb_proc=int(os.sysconf('SC_NPROCESSORS_ONLN')) return nb_proc