From cd80d6a7a7a7947b203382895727ef4a368bb593 Mon Sep 17 00:00:00 2001 From: Christian Van Wambeke Date: Wed, 14 Mar 2018 13:18:03 +0100 Subject: [PATCH] fix #8798 for project_path : /volatile/wambeke/SAT5/SAT5_S840_MATIX24/salomeTools-5-tuleap and add debug.py for DBG.write(title, value) (on stderr) --- commands/package.py | 20 +++-- src/debug.py | 179 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 194 insertions(+), 5 deletions(-) create mode 100644 src/debug.py diff --git a/commands/package.py b/commands/package.py index 6d796ff..a7b708f 100644 --- a/commands/package.py +++ b/commands/package.py @@ -27,6 +27,7 @@ import string import src from application import get_SALOME_modules +import src.debug as DBG BINARY = "binary" SOURCE = "Source" @@ -970,7 +971,7 @@ def find_application_pyconf(config, application_tmp_dir): application_pyconf_cfg.__save__(ff, 1) ff.close() -def project_package(project_file_path, tmp_working_dir): +def project_package(config, name_project, project_file_path, tmp_working_dir, logger): '''Prepare a dictionary that stores all the needed directories and files to add in a project package. @@ -985,7 +986,15 @@ def project_package(project_file_path, tmp_working_dir): ''' d_project = {} # Read the project file and get the directories to add to the package - project_pyconf_cfg = src.pyconf.Config(project_file_path) + + try: + project_pyconf_cfg = config.PROJECTS.projects.__getattr__(name_project) + except: + logger.write(""" +WARNING: inexisting config.PROJECTS.projects.%s, try to read now from:\n%s\n""" % (name_project, project_file_path)) + project_pyconf_cfg = src.pyconf.Config(project_file_path) + project_pyconf_cfg.PWD = os.path.dirname(project_file_path) + paths = {"ARCHIVEPATH" : "archives", "APPLICATIONPATH" : "applications", "PRODUCTPATH" : "products", @@ -1279,7 +1288,7 @@ Please add it in file: msg = _("Preparation of files to add to the archive") logger.write(src.printcolors.printcLabel(msg), 2) logger.write("\n", 2) - + d_files_to_add={} # content of the archive # a dict to hold paths that will need to be substitute for users recompilations @@ -1328,9 +1337,10 @@ Please add it in file: if options.sat: d_files_to_add.update({"salomeTools" : (runner.cfg.VARS.salometoolsway, "")}) - + DBG.write("config for package %s" % project_name, runner.cfg) + if options.project: - d_files_to_add.update(project_package(options.project_file_path, tmp_working_dir)) + d_files_to_add.update(project_package(runner.cfg, project_name, options.project_file_path, tmp_working_dir, logger)) if not(d_files_to_add): msg = _("Error: Empty dictionnary to build the archive!\n") diff --git a/src/debug.py b/src/debug.py new file mode 100644 index 0000000..dbf7e67 --- /dev/null +++ b/src/debug.py @@ -0,0 +1,179 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- + +# Copyright (C) 2010-2018 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 + +""" +This file assume DEBUG functionalities use +- print debug messages in sys.stderr for salomeTools +- show pretty print debug representation from instances of SAT classes + (pretty print src.pyconf.Config) + +WARNING: supposedly show messages in SAT development phase, not production + +usage: +>> import debug as DBG +>> DBG.write("aTitle", aVariable) # not shown in production +>> DBG.write("aTitle", aVariable, True) # unconditionaly shown +""" + +import os +import sys +import StringIO as SIO +import pprint as PP + +_debug = [False] #support push/pop for temporary activate debug outputs + +def indent(text, amount=2, ch=' '): + """indent multi lines message""" + padding = amount * ch + return ''.join(padding + line for line in text.splitlines(True)) + +def write(title, var="", force=None, fmt="\n#### DEBUG: %s:\n%s\n"): + """write sys.stderr a message if _debug[-1]==True or optionaly force=True""" + if _debug[-1] or force: + if 'src.pyconf.Config' in str(type(var)): + sys.stderr.write(fmt % (title, indent(getStrConfigDbg(var)))) + elif type(var) is not str: + sys.stderr.write(fmt % (title, indent(PP.pformat(var)))) + else: + sys.stderr.write(fmt % (title, indent(var))) + return + +def tofix(title, var="", force=None): + """ + write sys.stderr a message if _debug[-1]==True or optionaly force=True + use this only if no logger accessible for classic logger.warning(message) + """ + fmt = "\n#### TOFIX: %s:\n%s\n" + write(title, var, force, fmt) + +def push_debug(aBool): + """set debug outputs activated, or not""" + _debug.append(aBool) + +def pop_debug(): + """restore previous debug outputs status""" + if len(_debug) > 1: + return _debug.pop() + else: + sys.stderr.write("\nERROR: pop_debug: too much pop.") + return None + +############################################### +# utilitaires divers pour debug +############################################### + +class OutStream(SIO.StringIO): + """utility class for pyconf.Config output iostream""" + def close(self): + """because Config.__save__ calls close() stream as file + keep value before lost as self.value + """ + self.value = self.getvalue() + SIO.StringIO.close(self) + +class InStream(SIO.StringIO): + """utility class for pyconf.Config input iostream""" + pass + +def getLocalEnv(): + """get string for environment variables representation""" + res = "" + for i in sorted(os.environ): + res += "%s : %s\n" % (i, os.environ[i]) + return res + +# save as initial Config.save() moved as Config.__save__() +def saveConfigStd(config, aStream): + """returns as file .pyconf""" + indent = 0 + config.__save__(aStream, indent) + +def getStrConfigStd(config): + """set string as saveConfigStd, + as file .pyconf""" + outStream = OutStream() + saveConfigStd(config, outStream) + return outStream.value + +def getStrConfigDbg(config): + """set string as saveConfigDbg, + as (path expression evaluation) for debug""" + outStream = OutStream() + saveConfigDbg(config, outStream) + return outStream.value + +def saveConfigDbg(config, aStream, indent=0, path=""): + """pyconf returns multilines (path expression evaluation) for debug""" + _saveConfigRecursiveDbg(config, aStream, indent, path) + aStream.close() # as config.__save__() + +def _saveConfigRecursiveDbg(config, aStream, indent, path): + """pyconf inspired from Mapping.__save__""" + debug = False + if indent <= 0: + indentp = 0 + else: + indentp = indentp + 2 + indstr = indent * ' ' # '':no indent, ' ':indent + strType = str(type(config)) + if "Sequence" in strType: + for i in range(len(config)): + _saveConfigRecursiveDbg(config[i], aStream, indentp, path+"[%i]" % i) + return + try: + order = object.__getattribute__(config, 'order') + data = object.__getattribute__(config, 'data') + except: + aStream.write("%s%s : '%s'\n" % (indstr, path, str(config))) + return + for key in sorted(order): + value = data[key] + strType = str(type(value)) + if debug: print indstr + 'strType = %s' % strType, key + if "Config" in strType: + _saveConfigRecursiveDbg(value, aStream, indentp, path+"."+key) + continue + if "Mapping" in strType: + _saveConfigRecursiveDbg(value, aStream, indentp, path+"."+key) + continue + if "Sequence" in strType: + for i in range(len(value)): + _saveConfigRecursiveDbg(value[i], aStream, indentp, path+"."+key+"[%i]" % i) + continue + if "Expression" in strType: + try: + evaluate = value.evaluate(config) + aStream.write("%s%s.%s : %s --> '%s'\n" % (indstr, path, key, str(value), evaluate)) + except Exception as e: + aStream.write("%s%s.%s : !!! ERROR: %s !!!\n" % (indstr, path, key, e.message)) + continue + if "Reference" in strType: + try: + evaluate = value.resolve(config) + aStream.write("%s%s.%s : %s --> '%s'\n" % (indstr, path, key, str(value), evaluate)) + except Exception as e: + aStream.write("%s%s.%s : !!! ERROR: %s !!!\n" % (indstr, path, key, e.message)) + continue + if type(value) in [str, bool, int, type(None), unicode]: + aStream.write("%s%s.%s : '%s'\n" % (indstr, path, key, str(value))) + continue + try: + aStream.write("!!! TODO fix that %s %s%s.%s : %s\n" % (type(value), indstr, path, key, str(value))) + except Exception as e: + aStream.write("%s%s.%s : !!! %s\n" % (indstr, path, key, e.message)) -- 2.39.2