From dc9822d7bebf75f9e1215008c8c69cbc896dad05 Mon Sep 17 00:00:00 2001 From: Christian Van Wambeke Date: Tue, 29 May 2018 16:46:12 +0200 Subject: [PATCH] sat prepare salome840 ok --- commands/compile.py | 57 ++++----- commands/generate.py | 8 +- commands/patch.py | 7 +- commands/prepare.py | 13 +- commands/source.py | 72 +++++------ data/local.pyconf | 7 +- sat | 25 ++-- src/compilation.py | 282 ++++++++++++++++--------------------------- src/configManager.py | 21 ++-- src/loggingSat.py | 2 +- src/options.py | 3 +- src/returnCode.py | 3 + src/salomeTools.py | 2 +- src/utilsSat.py | 22 ++++ 14 files changed, 239 insertions(+), 285 deletions(-) diff --git a/commands/compile.py b/commands/compile.py index 3a02514..4eec34d 100644 --- a/commands/compile.py +++ b/commands/compile.py @@ -130,8 +130,8 @@ class Command(_BaseCommand): msg = _("Application %s, executing compile commands in build directories of products.\n") logger.info(msg % UTS.label(nameApp)) - info = [ (_("SOURCE directory"), srcDir), - (_("BUILD directory"),buildDir) ] + info = [ (_("SOURCE directory"), UTS.info(srcDir)), + (_("BUILD directory"), UTS.info(buildDir)) ] UTS.logger_info_tuples(logger, info) # Get the list of products to treat @@ -147,7 +147,6 @@ class Command(_BaseCommand): # Sort the list regarding the dependencies of the products products_infos = sort_products(config, products_infos) - # Call the function that will loop over all the products and execute # the right command(s) @@ -155,20 +154,14 @@ class Command(_BaseCommand): # Print the final state nb_products = len(products_infos) - if res == 0: - final_status = "" - else: - final_status = "" - - logger.info(_("\nCompilation: %(status)s (%(1)d/%(2)d)\n") % \ - { 'status': final_status, - '1': nb_products - res, - '2': nb_products }) + nb_ok = res.getValue() + + logger.info(_("\nCompilation: <%(0)s> (%(1)d/%(2)d)\n") % \ + { '0': res.getStatus(), + '1': nb_products - nb_ok, + '2': nb_products } ) - code = res - if code != 0: - code = 1 - return code + return res def get_children(config, p_name_p_info): l_res = [] @@ -256,10 +249,10 @@ def get_recursive_fathers(config, p_name_p_info, without_native_fixed=False): if father_name not in l_fathers_name: if father_name not in config.APPLICATION.products: msg = _("The product %(father_name)s that is in %(product_nam" - "e)s dependencies is not present in application " - "%(appli_name)s" % {"father_name" : father_name, - "product_name" : p_name, - "appli_name" : config.VARS.application}) + "e)s dependencies is not present in application %(appli_name)s" % \ + {"father_name" : father_name, + "product_name" : p_name, + "appli_name" : config.VARS.application}) raise Exception(msg) prod_info_father = PROD.get_product_config(config, father_name) pname_pinfo_father = (prod_info_father.name, prod_info_father) @@ -345,7 +338,7 @@ def compile_all_products(sat, config, options, products_infos, logger): List of (str, Config) => (product_name, product_info) :param logger: (Logger) The logger instance to use for the display and logging - :return: (int) the number of failing commands. + :return: (RCO.ReturnCode) with value as the number of failing commands. """ res = 0 for p_name_info in products_infos: @@ -361,16 +354,13 @@ def compile_all_products(sat, config, options, products_infos, logger): # Do nothing if the product is not compilable if ("properties" in p_info and \ "compilation" in p_info.properties and \ - p_info.properties.compilation == "no"): - + p_info.properties.compilation == "no"): UTS.log_step(logger, header, "ignored") - logger.info("\n") continue # Do nothing if the product is native if PROD.product_is_native(p_info): UTS.log_step(logger, header, "native") - logger.info("\n") continue # Clean the build and the install directories @@ -401,12 +391,12 @@ def compile_all_products(sat, config, options, products_infos, logger): # Check if it was already successfully installed if PROD.check_installation(p_info): - logger.info(_("Already installed\n")) + logger.info(_("Already installed")) continue # If the show option was called, do not launch the compilation if options.no_compile: - logger.info(_("Not installed\n")) + logger.info(_("Not installed")) continue # Check if the dependencies are installed @@ -463,13 +453,15 @@ def compile_all_products(sat, config, options, products_infos, logger): logger.info("\r" + header + "") logger.info(_("\nINSTALL directory = %s") % p_info.install_dir) logger.debug("\n==== in compile of %s\n" % p_name) - logger.info("\n") if res_prod != 0 and options.stop_first_fail: break - return res + if res == 0: # no failing commands + return RCO.ReturnCode("OK", "no failing compile commands", res) + else: + return RCO.ReturnCode("KO", "existing %i failing compile commands" % res, res) def compile_product(sat, p_name_info, config, options, logger, header, len_end): """ @@ -482,7 +474,7 @@ def compile_product(sat, p_name_info, config, options, logger, header, len_end): The logger instance to use for the display and logging :param header: (str) the header to display when logging :param len_end: (int) the length of the the end of line (used in display) - :return: (int) 1 if it fails, else 0. + :return: (RCO.ReturnCode) KO if it fails. """ p_name, p_info = p_name_info @@ -512,11 +504,10 @@ def compile_product(sat, p_name_info, config, options, logger, header, len_end): # Check that the install directory exists if res==0 and not(os.path.exists(p_info.install_dir)): - res = 1 error_step = "NO INSTALL DIR" - msg = _("despite all the steps ended successfully, no install directory was found\n") + msg = _("All steps ended successfully, but install directory not found") logger.error(msg) - return res, len_end, error_step + return RCO.ReturnCode("KO", "Install directory not found", (error_step, p_name, p_info.install_dir)) # Add the config file corresponding to the dependencies/versions of the # product that have been successfully compiled diff --git a/commands/generate.py b/commands/generate.py index 04becef..1d62199 100644 --- a/commands/generate.py +++ b/commands/generate.py @@ -218,13 +218,13 @@ def generate_component(config, compo, product_info, context, header, logger): VersionSalome = UTS.get_salome_version(config) if VersionSalome >= 750 : use_autotools=False - builder.log('USE CMAKE', 3) + logger.info('USE CMAKE') else: use_autotools=True - builder.log('USE AUTOTOOLS', 3) + logger.info('USE AUTOTOOLS') result = "GENERATE" - builder.log('GENERATE', 3) + logger.info('GENERATE') prevstdout = sys.stdout prevstderr = sys.stderr @@ -255,7 +255,7 @@ def generate_component(config, compo, product_info, context, header, logger): if use_autotools: result = "BUID_CONFIGURE" - builder.log('BUID_CONFIGURE (no bootstrap)', 3) + logger.info('BUID_CONFIGURE (no bootstrap)') g.bootstrap(compo_info.source_dir, logger.logTxtFile) result = RCO._OK_STATUS diff --git a/commands/patch.py b/commands/patch.py index 3b3c2ab..92173d4 100644 --- a/commands/patch.py +++ b/commands/patch.py @@ -104,9 +104,12 @@ class Command(_BaseCommand): # write results msg = ("Patching sources of the application: <%s> (%d/%d)") % \ (status, good_result, len(products_infos)) - logger.info(msg) + logger.info("\n" + msg) + + msg = ("Patching sources of the application (%d/%d)") % \ + (good_result, len(products_infos)) + return RCO.ReturnCode(status, msg) - def apply_patch(config, product_info, max_product_name_len, logger): """The method called to apply patches on a product diff --git a/commands/prepare.py b/commands/prepare.py index 6d7adde..836ca9f 100644 --- a/commands/prepare.py +++ b/commands/prepare.py @@ -19,6 +19,7 @@ import os import re +import pprint as PP import src.debug as DBG import src.returnCode as RCO @@ -58,12 +59,7 @@ class Command(_BaseCommand): def run(self, cmd_arguments): """method called for command 'sat prepare '""" argList = self.assumeAsList(cmd_arguments) - - # print general help and returns - if len(argList) == 0: - self.print_help() - return RCO.ReturnCode("OK", "No arguments, as 'sat %s --help'" % self.name) - + self._options, remaindersArgs = self.parseArguments(argList) if self._options.help: @@ -85,8 +81,11 @@ class Command(_BaseCommand): args_appli = config.VARS.application if options.products: listProd = list(options.products) - else: + else: # no product interpeted as all products listProd = [name for name, tmp in products_infos] + logger.warning("prepare all products:\n%s" % PP.pformat(sorted(listProd))) + + # DBG.write("prepare products", sorted(listProd)) args_product_opt = '--products ' + ",".join(listProd) do_source = (len(listProd) > 0) diff --git a/commands/source.py b/commands/source.py index 7756f58..55b9065 100644 --- a/commands/source.py +++ b/commands/source.py @@ -19,6 +19,7 @@ import os import shutil +import pprint as PP import src.debug as DBG import src.returnCode as RCO @@ -97,11 +98,9 @@ class Command(_BaseCommand): else: status = "KO" msg = _("Some sources haven't been get") - details = [p for p in results if (results[product] == 0 or results[product] is None)] - details = ",".join(details) - logger.info("\n%s %s: <%s>.\n%s\n" % (msg, msgCount, status, details)) + logger.info("\n%s %s: <%s>.\n" % (msg, msgCount, status)) - return RCO.ReturnCode(status, "%s get sources: %s" % (msg, msgCount)) + return RCO.ReturnCode(status, "%s %s" % (msg, msgCount)) def get_source_for_dev(config, product_info, source_dir, logger, pad): @@ -116,7 +115,7 @@ def get_source_for_dev(config, product_info, source_dir, logger, pad): :param logger: (Logger) The logger instance to use for the display and logging :param pad: (int) The gap to apply for the terminal display - :return: (bool) True if it succeed, else False + :return: (RCO.ReturnCode) OK if it succeed """ # Call the function corresponding to get the sources with True checkout @@ -153,7 +152,7 @@ def get_source_from_git(product_info, :param is_dev: (bool) True if the product is in development mode :param environ: (src.environment.Environ) The environment to source when extracting. - :return: (bool) True if it succeed, else False + :return: (RCO.ReturnCode) OK if it succeed """ # The str to display coflag = 'git' @@ -185,7 +184,7 @@ def get_source_from_archive(product_info, source_dir, logger): where to put the sources :param logger: (Logger) The logger instance to use for the display and logging - :return: (bool) True if it succeed, else False + :return: (RCO.ReturnCode) OK if it succeed """ # check archive exists archName = product_info.archive_info.archive_name @@ -208,27 +207,29 @@ def get_source_from_archive(product_info, source_dir, logger): def get_source_from_dir(product_info, source_dir, logger): if "dir_info" not in product_info: - msg = _("You must put a dir_info section in the file %s.pyconf") % \ - product_info.name + msg = _("You must put a dir_info section in the file %s.pyconf") % product_info.name logger.error(msg) - return False + return RCO.ReturnCode("KO", msg) if "dir" not in product_info.dir_info: msg = _("Error: you must put a dir in the dir_info section in the file %s.pyconf") % \ product_info.name logger.error(msg) - return False + return RCO.ReturnCode("KO", msg) # check that source exists if not os.path.exists(product_info.dir_info.dir): msg = _("The dir %s defined in the file %s.pyconf does not exists") % \ (product_info.dir_info.dir, product_info.name) logger.error(msg) - return False + return RCO.ReturnCode("KO", msg) logger.info(' DIR: %s ...' % UTS.info(product_info.dir_info.dir)) retcode = UTS.Path(product_info.dir_info.dir).copy(source_dir) - return retcode + if retcode: + RCO.ReturnCode("OK", "for copy directory s'" % product_info.dir_info.dir) + else: + RCO.ReturnCode("KO", "for copy directory s'" % product_info.dir_info.dir) def get_source_from_cvs(user, product_info, @@ -252,7 +253,7 @@ def get_source_from_cvs(user, :param pad: (int) The gap to apply for the terminal display :param environ: (src.environment.Environ) The environment to source when extracting. - :return: (bool) True if it succeed, else False + :return: (RCO.ReturnCode) OK if it succeed """ # Get the protocol to use in the command if "protocol" in product_info.cvs_info: @@ -270,7 +271,8 @@ def get_source_from_cvs(user, product_info.cvs_info.product_base) coflag = 'cvs' - if checkout: coflag = coflag.upper() + if checkout: + coflag = coflag.upper() msg = " %s:%s" % (coflag, cvs_line) msg += " src:%s" % product_info.cvs_info.source @@ -281,11 +283,11 @@ def get_source_from_cvs(user, logger.info(msg) # Call the system function that do the extraction in cvs mode retcode = SYSS.cvs_extract(protocol, user, - product_info.cvs_info.server, - product_info.cvs_info.product_base, - product_info.cvs_info.tag, - product_info.cvs_info.source, - source_dir, logger, checkout, environ) + product_info.cvs_info.server, + product_info.cvs_info.product_base, + product_info.cvs_info.tag, + product_info.cvs_info.source, + source_dir, logger, checkout, environ) return retcode def get_source_from_svn(user, @@ -308,7 +310,7 @@ def get_source_from_svn(user, The logger instance to use for the display and logging :param environ: (src.environment.Environ) The environment to source when extracting. - :return: (bool) True if it succeed, else False + :return: (RCO.ReturnCode) OK if it succeed """ coflag = 'svn' if checkout: coflag = coflag.upper() @@ -344,7 +346,7 @@ def get_product_sources(config, The logger instance to use for the display and logging :param pad: (int) The gap to apply for the terminal display :param checkout: (bool) If True, get the source in checkout mode - :return: (bool) True if it succeed, else False + :return: (RCO.ReturnCode) OK if it succeed """ # Get the application environment @@ -375,21 +377,21 @@ def get_product_sources(config, if product_info.get_source == "native": # skip - msg = "" + _("\ndo nothing because the product is of type 'native'.\n") - logger.info(msg) - return True + msg = _("Do nothing because the product is of type 'native'") + logger.info(" " + msg) + return RCO.ReturnCode("OK", msg) if product_info.get_source == "fixed": # skip - msg = "" + _("\ndo nothing because the product is of type 'fixed'.\n") - logger.info(msg) - return True + msg = _("Do nothing because the product is of type 'fixed'") + logger.info(" " + msg) + return RCO.ReturnCode("OK", msg) # if the get_source is not in [git, archive, cvs, svn, fixed, native] msg = _("Unknown get source method '%s' for product %s") % \ ( product_info.get_source, product_info.name) - logger.info("%s ... " % msg) - return False + logger.warning(" " + msg) + return RCO.ReturnCode("KO", msg) def get_all_product_sources(config, products, logger): """Get all the product sources. @@ -432,7 +434,7 @@ def get_all_product_sources(config, products, logger): if source_dir.exists(): msg = _("Do nothing because source directory existing yet.") logger.warning(msg) - logger.info("") + logger.info(" "+ msg) good_result = good_result + 1 # Do not get the sources and go to next product continue @@ -454,7 +456,7 @@ def get_all_product_sources(config, products, logger): # Check that the sources are correctly get using the files to be tested # in product information - if retcode: + if retcode.isOk(): rc = check_sources(product_info, logger) if not rc.isOk(): # Print the missing file path @@ -465,7 +467,7 @@ def get_all_product_sources(config, products, logger): # show results results[product_name] = retcode - if retcode: + if retcode.isOk(): # The case where it succeed res = "" good_result = good_result + 1 @@ -506,7 +508,7 @@ def check_sources(product_info, logger): else: logger.debug("%s " % msg) if len(filesKo) != 0: - return RCO.ReturnCode("KO", "check_sources, missing files") + return RCO.ReturnCode("KO", "check_sources, missing files", filesKo) else: - return RCO.ReturnCode("OK", "check_sources, no missing file") + return RCO.ReturnCode("OK", "check_sources, no missing file", l_files_to_be_tested) diff --git a/data/local.pyconf b/data/local.pyconf index c91da53..e62c609 100644 --- a/data/local.pyconf +++ b/data/local.pyconf @@ -12,7 +12,10 @@ { project_file_paths : [ - "/home/christian/SAT_SALOME/salome.pyconf" - "/home/christian/SAT_MATIX/matix.pyconf" + "/volatile/wambeke/SAT5/SAT5_S840_MATIX24/SAT_SALOME/salome.pyconf", + # "/home/uranietm/proJET/saTJOBS/saT5/uranie.pyconf", + # cloned 2017/12 for matix + # "/home/matix/GitRepo/uranie/saT5/uranie.pyconf", + # "/volatile/wambeke/SAT5/SAT_MATIX/matix.pyconf" ] } diff --git a/sat b/sat index fec31e2..b75272f 100755 --- a/sat +++ b/sat @@ -54,26 +54,29 @@ if __name__ == "__main__": try: returnCode = sat.execute_cli(args) - DBG.write("execute_cli return code", returnCode) - if returnCode.isOk(): - logger.debug("sat exit code: %s" % returnCode) # OK no trace - else: - # warning as known problem - logger.warning("sat exit code: %s" % returnCode) # KO have to say why - logger.close() - sys.exit(returnCode.toSys()) - except Exception as e: # error as may be unknown problem # verbose debug message with traceback if developers msg = "Exception raised for execute_cli (%s):\n" % " ".join(args) logger.critical(DBG.format_color_exception(msg)) - logger.close() + logger.close() # important to close logger sys.exit(KOSYS) + # no Exception but may be known problem + DBG.write("execute_cli return code", returnCode) + if returnCode.isOk(): + # OK no trace + logger.debug("sat exit code: %s" % returnCode) + else: + # KO warning as known problem have to say why + logger.warning("sat exit code: %s" % returnCode) + logger.close() # important to close logger + sys.exit(returnCode.toSys()) + + else: logger.critical("forbidden/unexpected mode for __name__ '%s'" % __name__) - logger.close() + logger.close() # important to close logger sys.exit(KOSYS) diff --git a/src/compilation.py b/src/compilation.py index 69a635f..f204920 100644 --- a/src/compilation.py +++ b/src/compilation.py @@ -29,6 +29,7 @@ import shutil import subprocess as SP from src.options import OptResult +import returnCode as RCO import src.utilsSat as UTS import src.product as PROD import src.environment as ENVI @@ -59,15 +60,6 @@ class Builder: if "debug" in self.product_info and self.product_info.debug == "yes": self.debug_mode = True - def log(self, text, level, showInfo=True): - """Shortcut method to log in log file.""" - self.logger.info(text) - self.logger.logTxtFile.write(UTS.cleancolor(text)) - - def log_command(self, command): - """Shortcut method to log a command.""" - self.log("> %s\n" % command, 5) - def prepare(self): """ Prepares the environment. @@ -87,7 +79,7 @@ class Builder: # create build environment self.build_environ = ENVI.SalomeEnviron(self.config, ENVI.Environ(dict(os.environ)), True) - self.build_environ.silent = (self.config.USER.output_verbose_level < 5) + self.build_environ.silent = UTS.isSilent(self.config.USER.output_verbose_level) self.build_environ.set_full_environ(self.logger, environ_info) # create runtime environment @@ -102,7 +94,6 @@ class Builder: return 0 - def cmake(self, options=""): """Runs cmake with the given options.""" cmake_option = options @@ -123,22 +114,19 @@ class Builder: cmake_option += " -DCMAKE_GENERATOR=%s" \ % self.config.APPLICATION.cmake_generator - command = ("cmake %s -DCMAKE_INSTALL_PREFIX=%s %s" % - (cmake_option, self.install_dir, self.source_dir)) - - self.log_command(command) - # for key in sorted(self.build_environ.environ.environ.keys()): - # print key, " ", self.build_environ.environ.environ[key] - res = SP.call(command, shell=True, cwd=str(self.build_dir), - env=self.build_environ.environ.environ, - stdout=self.logger.logTxtFile, - stderr=SP.STDOUT) - - self.put_txt_log_in_appli_log_dir("cmake") - if res == 0: - return res - else: - return 1 + cmd = """ +# CMAKE +set -x +cmake %s -DCMAKE_INSTALL_PREFIX=%s %s +""" % (cmake_option, self.install_dir, self.source_dir) + + """ + for key in sorted(self.build_environ.environ.environ.keys()): + print key, " ", self.build_environ.environ.environ[key] + """ + env = self.build_environ.environ.environ + res = UTS.Popen(cmd, cwd=str(self.build_dir),env=env) + return res def build_configure(self, options=""): @@ -146,21 +134,15 @@ class Builder: if 'buildconfigure_options' in self.product_info: options += " %s " % self.product_info.buildconfigure_options - command = str('%s/build_configure') % (self.source_dir) - command = command + " " + options - self.log_command(command) - - res = SP.call(command, - shell=True, - cwd=str(self.build_dir), - env=self.build_environ.environ.environ, - stdout=self.logger.logTxtFile, - stderr=SP.STDOUT) - self.put_txt_log_in_appli_log_dir("build_configure") - if res == 0: - return res - else: - return 1 + bconf = os.path.join(self.source_dir, "build_configure") + cmd = """ +set -x +%s %s +""" % (bconf, options) + + env = self.build_environ.environ.environ + res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env) + return res def configure(self, options=""): @@ -168,36 +150,31 @@ class Builder: if 'configure_options' in self.product_info: options += " %s " % self.product_info.configure_options - command = "%s/configure --prefix=%s" % (self.source_dir, - str(self.install_dir)) - - command = command + " " + options - self.log_command(command) + conf = os.path.join(self.source_dir, "configure") + cmd = """ +set -x +%s --prefix=%s %s +""" % (conf, self.install_dir, options) - res = SP.call(command, - shell=True, - cwd=str(self.build_dir), - env=self.build_environ.environ.environ, - stdout=self.logger.logTxtFile, - stderr=SP.STDOUT) - - self.put_txt_log_in_appli_log_dir("configure") - if res == 0: - return res - else: - return 1 + env = self.build_environ.environ.environ + res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env) + return res def hack_libtool(self): - if not os.path.exists(str(self.build_dir + 'libtool')): - return + libtool = os.path.join(str(self.build_dir), "libtool") + if not os.path.exists(libtool): + return RCO.ReturnCode("OK", "file libtool not existing '%s'" % libtool) - lf = open(os.path.join(str(self.build_dir), "libtool"), 'r') - for line in lf.readlines(): + with open(libtool, 'r') as lf: + for line in lf.readlines(): if 'hack_libtool' in line: - return + return RCO.ReturnCode("OK", "existing 'hack_libtool' in '%s'" % libtool) # fix libtool by replacing CC="" with hack_libtool function - hack_command='''sed -i "s%^CC=\\"\(.*\)\\"%hack_libtool() { \\n\\ + # TODO rewrite that horreur + obsolete_hack_cmd=''' +set -x +sed -i "s%^CC=\\"\(.*\)\\"%hack_libtool() { \\n\\ if test \\"\$(echo \$@ | grep -E '\\\\\\-L/usr/lib(/../lib)?(64)? ')\\" == \\\"\\\" \\n\\ then\\n\\ cmd=\\"\\1 \$@\\"\\n\\ @@ -208,96 +185,75 @@ if test \\"\$(echo \$@ | grep -E '\\\\\\-L/usr/lib(/../lib)?(64)? ')\\" == \\\"\ }\\n\\ CC=\\"hack_libtool\\"%g" libtool''' - self.log_command(hack_command) - SP.call(hack_command, - shell=True, - cwd=str(self.build_dir), - env=self.build_environ.environ.environ, - stdout=self.logger.logTxtFile, - stderr=SP.STDOUT) + hack_cmd=r''' +set -x +sed -i "s%^CC=\"\(.*\)\"%hack_libtool() { \n\ +if test \"\$(echo \$@ | grep -E '\\\-L/usr/lib(/../lib)?(64)? ')\" == \"\" \n\ + then\n\ + cmd=\"\1 \$@\"\n\ + else\n\ + cmd=\"\1 \"\`echo \$@ | sed -r -e 's|(.*)-L/usr/lib(/../lib)?(64)? (.*)|\\\1\\\4 -L/usr/lib\\\3|g'\`\n\ + fi\n\ + \$cmd\n\ +}\n\ +CC=\"hack_libtool\"%g" libtool +''' + + env = self.build_environ.environ.environ + res = UTS.Popen(hack_cmd, cwd=str(self.build_dir), env=env) + return res - ## - # Runs make to build the module. def make(self, nb_proc, make_opt=""): - + """Runs make to build the module.""" # make - command = 'make' - command = command + " -j" + str(nb_proc) - command = command + " " + make_opt - self.log_command(command) - res = SP.call(command, - shell=True, - cwd=str(self.build_dir), - env=self.build_environ.environ.environ, - stdout=self.logger.logTxtFile, - stderr=SP.STDOUT) - self.put_txt_log_in_appli_log_dir("make") - if res == 0: - return res - else: - return 1 + cmd = """ +set -x +make -j %s %s +""" % (nb_proc, make_opt) + + env = self.build_environ.environ.environ + res = SP.call(cmd, cwd=str(self.build_dir), env=env) + return res + - def wmake(self,nb_proc, opt_nb_proc = None): + def wmake(self, nb_proc, opt_nb_proc = None): """Runs msbuild to build the module.""" hh = 'MSBUILD /m:%s' % str(nb_proc) if self.debug_mode: hh += " " + UTS.red("DEBUG") # make - command = 'msbuild' - command = command + " /maxcpucount:" + str(nb_proc) + cmd = "msbuild /maxcpucount:%s" % nb_proc if self.debug_mode: - command = command + " /p:Configuration=Debug" + cmd += " /p:Configuration=Debug" else: - command = command + " /p:Configuration=Release" - command = command + " ALL_BUILD.vcxproj" - - self.log_command(command) - res = SP.call(command, - shell=True, - cwd=str(self.build_dir), - env=self.build_environ.environ.environ, - stdout=self.logger.logTxtFile, - stderr=SP.STDOUT) - - self.put_txt_log_in_appli_log_dir("make") - if res == 0: - return res - else: - return 1 + cmd += " /p:Configuration=Release" + cmd += cmd + " ALL_BUILD.vcxproj" + env = self.build_environ.environ.environ + res = SP.Popen(command, cwd=str(self.build_dir), env=env) + return res + def install(self): """Runs 'make install'.""" if self.config.VARS.dist_name=="Win": - command = 'msbuild INSTALL.vcxproj' + cmd = "msbuild INSTALL.vcxproj" if self.debug_mode: - command = command + " /p:Configuration=Debug" + cmd += " /p:Configuration=Debug" else: - command = command + " /p:Configuration=Release" + cmd += " /p:Configuration=Release" else : - command = 'make install' - - self.log_command(command) - - res = SP.call(command, - shell=True, - cwd=str(self.build_dir), - env=self.build_environ.environ.environ, - stdout=self.logger.logTxtFile, - stderr=SP.STDOUT) - - self.put_txt_log_in_appli_log_dir("makeinstall") - if res == 0: - return res - else: - return 1 + cmd = 'make install' + env = self.build_environ.environ.environ + res = SP.Popen(command, cwd=str(self.build_dir), env=env) + return res def check(self, command=""): """Runs 'make_check'.""" if ARCH.is_windows(): - cmd = 'msbuild RUN_TESTS.vcxproj' + cmd = "msbuild RUN_TESTS.vcxproj" else : if self.product_info.build_source=="autotools" : cmd = 'make check' @@ -307,19 +263,10 @@ CC=\\"hack_libtool\\"%g" libtool''' if command: cmd = command - self.log_command(cmd) - - res = SP.call(cmd, - shell=True, - cwd=str(self.build_dir), - env=self.launch_environ.environ.environ, - stdout=self.logger.logTxtFile, - stderr=SP.STDOUT) + env = self.build_environ.environ.environ + res = SP.Popen(command, cwd=str(self.build_dir), env=env) + return res - if res == 0: - return res - else: - return 1 def do_default_build(self, build_conf_options="", @@ -425,21 +372,19 @@ CC=\\"hack_libtool\\"%g" libtool''' else : make_options = "-j%s" % nb_proc - self.log_command(" " + _("Run build script %s\n") % script) + self.logger.info(_("Run build script '%s'") % script) self.complete_environment(make_options) - res = SP.call(script, - shell=True, - stdout=self.logger.logTxtFile, - stderr=SP.STDOUT, - cwd=str(self.build_dir), - env=self.build_environ.environ.environ) - - self.put_txt_log_in_appli_log_dir("script") - if res == 0: - return res - else: - return 1 + # linux or win compatible, have to be chmod +x ? + cmd = """ +# Run build script +%s +""" % script + + + env = self.build_environ.environ.environ + res = SP.Popen(cmd, cwd=str(self.build_dir), env=env) + return res def do_script_build(self, script, number_of_proc=0): # define make options (may not be used by the script) @@ -450,31 +395,12 @@ CC=\\"hack_libtool\\"%g" libtool''' else: nb_proc = min(number_of_proc, self.config.VARS.nb_proc) - extension = script.split('.')[-1] - if extension in ["bat","sh"]: + extension = os.path.splitext(script)[-1] + if extension in [".bat", ".sh", ".bash"]: return self.do_batch_script_build(script, nb_proc) - if extension == "py": + if extension == ".py": return self.do_python_script_build(script, nb_proc) - msg = _("The script %s must have .sh, .bat or .py extension.") % script + msg = _("The script %s must have extension as .sh, .bat or .py.") % script raise Exception(msg) - - def put_txt_log_in_appli_log_dir(self, file_name): - """ - Put the txt log (that contain the system logs, like make command output) - in the directory /LOGS// - - :param file_name: (str) The name of the file to write - """ - if self.logger.logTxtFile == sys.__stdout__: - return - dir_where_to_put = os.path.join(self.config.APPLICATION.workdir, "LOGS", self.product_info.name) - file_path = os.path.join(dir_where_to_put, file_name) - UTS.ensure_path_exists(dir_where_to_put) - # write the logTxtFile copy it to the destination, and then recreate - # it as it was - self.logger.logTxtFile.close() - shutil.move(self.logger.txtFilePath, file_path) - self.logger.logTxtFile = open(str(self.logger.txtFilePath), 'w') - self.logger.logTxtFile.write(open(file_path, "r").read()) diff --git a/src/configManager.py b/src/configManager.py index 1a5c42c..2bca0a2 100644 --- a/src/configManager.py +++ b/src/configManager.py @@ -435,11 +435,12 @@ class ConfigManager: """ # get the expected name and path of the file self.config_file_name = 'SAT.pyconf' - self.user_config_file_path = os.path.join(config.VARS.personalDir, - self.config_file_name) + cfg_name = os.path.join(config.VARS.personalDir, self.config_file_name) + self.user_config_file_path = cfg_name # if pyconf does not exist, create it from scratch - if not os.path.isfile(self.user_config_file_path): + DBG.write("user config file", cfg_name) + if not os.path.isfile(cfg_name): self.create_config_file(config) def create_config_file(self, config): @@ -461,8 +462,9 @@ class ConfigManager: "This is the user name used to access salome cvs base.\n") USER.addMapping('svn_user', config.VARS.user, "This is the user name used to access salome svn base.\n") - USER.addMapping('output_verbose_level', 3, - "This is the default output_verbose_level you want. 0=>no output, 5=>debug.\n") + # TODO set output_verbose_level sat5.1 as "CRITICAL->DEBUG" but not sat5.0 "0->5" + USER.addMapping('output_verbose_level', "3", + "This is the default sat5 output_verbose_level you want. 0=>warning, 3=>info, 5=>debug.\n") USER.addMapping('publish_dir', os.path.join(os.path.expanduser('~'), 'websupport', 'satreport'), "") USER.addMapping('editor', 'vi', "This is the editor used to modify configuration files\n") @@ -471,7 +473,8 @@ class ConfigManager: UTS.ensure_path_exists(config.VARS.personalDir) UTS.ensure_path_exists(os.path.join(config.VARS.personalDir, 'Applications')) - + + self.logger.warning("Create user config file %s" % UTS.info(cfg_name)) with open(cfg_name, 'w') as f: cfg.__save__(f) return cfg @@ -797,12 +800,10 @@ def _getConfig(self, appliToLoad): batch_save = self.options.batch self.options.__setattr__("batch", True) - # set output level + # set output level, TODO useless sat5.1? if self.runner.options.output_verbose_level is not None: config.USER.output_verbose_level = self.runner.options.output_verbose_level - if config.USER.output_verbose_level < 1: - config.USER.output_verbose_level = 0 - silent = (config.USER.output_verbose_level == 0) + silent = config.USER.output_verbose_level in ["WARNING", "ERROR", "CRITICAL"] # create log file micro_command = False diff --git a/src/loggingSat.py b/src/loggingSat.py index 87cab85..6a7f5d6 100755 --- a/src/loggingSat.py +++ b/src/loggingSat.py @@ -228,7 +228,7 @@ class LoggerSat(LOGI.Logger): # todo etc self.isClosed = True # done at end sat, flushed closed xml files. return - + def __repr__(self): """one line string representation""" msg = "%s(name=%s, dateLogger=%s, handlers=%s)" diff --git a/src/options.py b/src/options.py index 48da2fd..9e0f21d 100644 --- a/src/options.py +++ b/src/options.py @@ -34,7 +34,8 @@ class OptResult(object): in code of all salomeTools commands The aim of this class is to have an elegant syntax to manipulate the options. - | Example: + | Example: + | >> options, remainderArgs = command.parseArguments(args) | >> print(options.output_verbose_level) | >> 'INFO' """ diff --git a/src/returnCode.py b/src/returnCode.py index c2441b3..1af9116 100644 --- a/src/returnCode.py +++ b/src/returnCode.py @@ -191,6 +191,9 @@ class ReturnCode(object): self._value = value else: self._value = self._DEFAULT_VALUE + + def getStatus(self): + return self._status def isOk(self): """ diff --git a/src/salomeTools.py b/src/salomeTools.py index 46cd314..5ad7ae5 100755 --- a/src/salomeTools.py +++ b/src/salomeTools.py @@ -618,7 +618,7 @@ development mode (more verbose error/exception messages) LKXML.setAttribLinkForCommand(cmdInstance, "full_launched_cmd", strArgs) LKXML.setAttribLinkForCommand(cmdInstance, "cmd_res", returnCode.toXmlPassed()) - logger.closeFileHandlerForCommand(cmdInstance) + # close logger/main handler have to be caller stuff... return returnCode diff --git a/src/utilsSat.py b/src/utilsSat.py index 158367f..aab6049 100644 --- a/src/utilsSat.py +++ b/src/utilsSat.py @@ -445,6 +445,28 @@ def log_res_step(logger, res): else: logger.info("\n") +def isSilent(output_verbose_level): + """is silent fort self.build_environ""" + lev = levelToSat5p1(output_verbose_level) + if lev in ["TRACE", "DEBUG"]: + return False # as verbose if debug + return True # as silent if not debug + +def levelToSat5p1(output_verbose_level): + """ + convert sat5 output_verbose_level integer 0=>no output, 5=>debug + to string sat5.1 compatible ('INFO', 'DEBUG' etc) + """ + try: + aInt = int(output_verbose_level) + if aInt < 0: return "INFO" # not set + if aInt < 3: return "WARNING" + if aInt == 3: return "INFO" + if aInt == 4: return "TRACE" + return "DEBUG" + except: + return str(output_verbose_level) # suppose sat5.1 'DEBUG' to 'CRITICAL' + ############################################################################## # color utilities, for convenience ############################################################################## -- 2.39.2