From 461ed556cab6c7a8fc916a1f08973ea73e932697 Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Tue, 2 Feb 2016 16:18:06 +0100 Subject: [PATCH] Remarks from sprint 1 : do not consider 32/64 bits, have only one user config file (~/.salomeTools.pyconf), add a CEA licence to pyconf.py --- src/common/architecture.py | 19 ----------- src/common/pyconf.py | 23 ++++++++++++-- src/config.py | 65 ++++---------------------------------- src/salomeTools.py | 2 +- 4 files changed, 28 insertions(+), 81 deletions(-) diff --git a/src/common/architecture.py b/src/common/architecture.py index fe32ca8..d10b06c 100644 --- a/src/common/architecture.py +++ b/src/common/architecture.py @@ -108,25 +108,6 @@ def get_distrib_version(distrib, codes): return version -def get_nb_bit(): - '''Gets the number of bytes. - - :return: the number of bytes of the OS on which salomeTools is running. - :rtype: str - ''' - - # The platform python module gives the answer - nb_bit = platform.architecture()[0] - if nb_bit == "64bit": - nb_bit = "64" - elif nb_bit == "32bit": - nb_bit = "32" - else: - sys.stderr.write(_(u"Unknown architecture: '%s'\n") % nb_bit) - sys.exit(-1) - - return nb_bit - def get_python_version(): '''Gets the version of the running python. diff --git a/src/common/pyconf.py b/src/common/pyconf.py index 53bd184..821f3d6 100644 --- a/src/common/pyconf.py +++ b/src/common/pyconf.py @@ -1,8 +1,6 @@ #!/usr/bin/env python #-*- coding:utf-8 -*- - - # Copyright 2004-2007 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its @@ -19,6 +17,27 @@ # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# Copyright (C) 2010-2013 CEA/DEN +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# CEA adds : +# Possibility to overwrites value in a pyconf file +# Python 3 porting + + """ This is a configuration module for Python. diff --git a/src/config.py b/src/config.py index 5f18159..03984b2 100644 --- a/src/config.py +++ b/src/config.py @@ -97,33 +97,21 @@ class ConfigManager: # read linux distributions dictionary distrib_cfg = common.pyconf.Config(os.path.join(var['srcDir'], 'common', 'internal_config', 'distrib.pyconf')) - + # set platform parameters dist_name = common.architecture.get_distribution(codes=distrib_cfg.DISTRIBUTIONS) dist_version = common.architecture.get_distrib_version(dist_name, codes=distrib_cfg.VERSIONS) dist = dist_name + dist_version - # Forcing architecture with env variable ARCH on Windows - if common.architecture.is_windows() and "ARCH" in os.environ : - bitsdict={"Win32":"32","Win64":"64"} - nb_bits = bitsdict[os.environ["ARCH"]] - else : - nb_bits = common.architecture.get_nb_bit() - var['dist_name'] = dist_name var['dist_version'] = dist_version var['dist'] = dist - var['arch'] = dist + '_' + nb_bits - var['bits'] = nb_bits var['python'] = common.architecture.get_python_version() var['nb_proc'] = common.architecture.get_nb_proc() node_name = platform.node() var['node'] = node_name var['hostname'] = node_name - # particular win case - if common.architecture.is_windows() : - var['hostname'] = node_name+'-'+nb_bits # set date parameters dt = datetime.datetime.now() @@ -295,54 +283,13 @@ class ConfigManager: :param config class 'common.pyconf.Config': The global config (containing all pyconf). ''' - if not config: - raise common.SatException(_("Error in setUserConfigFile: config is None")) - sat_version = config.INTERNAL.sat_version # get the expected name and path of the file - self.config_file_name = 'salomeTools-%s.pyconf'%sat_version + self.config_file_name = 'salomeTools.pyconf' self.user_config_file_path = os.path.join(config.VARS.personalDir, self.config_file_name) - if not os.path.isfile(self.user_config_file_path): - # if pyconf does not exist, - # Make a copy of an existing salomeTools-.pyconf - # or at least a copy of salomeTools.pyconf - # If there is no pyconf file at all, create it from scratch - already_exisiting_pyconf_file = self.getAlreadyExistingUserPyconf( config.VARS.personalDir, sat_version ) - if already_exisiting_pyconf_file: - # copy - shutil.copyfile( already_exisiting_pyconf_file, self.user_config_file_path ) - else: # create from scratch - self.createConfigFile(config) - - def getAlreadyExistingUserPyconf(self, userDir, sat_version ): - '''Get a pyconf file younger than the given sat version in the given directory - The file basename can be one of salometools-.pyconf or salomeTools.pyconf - Returns the file path or None if no file has been found. - - :param userDir str: the directory that contain the user pyconf to find. (~/.salomeTools) - :param sat_version str: the version of salomeTools. - :return: the path to the already existing user pyconf. - :rtype: str - ''' - file_path = None - # Get a younger pyconf version - pyconfFiles = glob.glob( os.path.join(userDir, 'salomeTools-*.pyconf') ) - sExpr = "^salomeTools-(.*)\.pyconf$" - oExpr = re.compile(sExpr) - younger_version = None - for s in pyconfFiles: - oSreMatch = oExpr.search( os.path.basename(s) ) - if oSreMatch: - pyconf_version = oSreMatch.group(1) - if pyconf_version < sat_version: - younger_version = pyconf_version - - # Build the pyconf filepath - if younger_version : - file_path = os.path.join( userDir, 'salomeTools-%s.pyconf'%younger_version ) - elif os.path.isfile( os.path.join(userDir, 'salomeTools.pyconf') ): - file_path = os.path.join( userDir, 'salomeTools.pyconf' ) - return file_path + # if pyconf does not exist, create it from scratch + if not os.path.isfile(self.user_config_file_path): + self.createConfigFile(config) def createConfigFile(self, config): '''This method is called when there are no user config file. It build it from scratch. @@ -467,7 +414,7 @@ def run(args, runner): elif options.edit: editor = runner.cfg.USER.editor if 'APPLICATION' not in runner.cfg: # edit user pyconf - usercfg = os.path.join(runner.cfg.VARS.personalDir, 'salomeTools-%s.pyconf'%runner.cfg.INTERNAL['sat_version']) + usercfg = os.path.join(runner.cfg.VARS.personalDir, 'salomeTools.pyconf') common.system.show_in_editor(editor, usercfg) else: # search for file .pyconf and open it diff --git a/src/salomeTools.py b/src/salomeTools.py index a120254..014c9ee 100755 --- a/src/salomeTools.py +++ b/src/salomeTools.py @@ -123,7 +123,7 @@ class salomeTools(object): ''' argv = args.split(" ") - # first argument is the APPLICATION + # if it is provided by the command line, get the application appliToLoad = None if argv != [''] and argv[0][0] != "-": appliToLoad = argv[0].rstrip('*') -- 2.39.2