From: Gbkng Date: Wed, 14 Feb 2024 22:40:56 +0000 (+0100) Subject: feat(all): fix common issues (exept Exception, missing import for gettext.gettext... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=48e95e53a4f130c61b81470f1c974858ac24d401;p=tools%2Fsat.git feat(all): fix common issues (exept Exception, missing import for gettext.gettext as _) --- diff --git a/AllTestLauncherSat.py b/AllTestLauncherSat.py index eaa1a96..cf8319d 100755 --- a/AllTestLauncherSat.py +++ b/AllTestLauncherSat.py @@ -86,7 +86,7 @@ def errPrint(aStr): try: import unittestpy.HTMLTestRunner as HTST -except: +except Exception: HTST = None errPrint(""" WARNING: no HTML output available. @@ -96,7 +96,7 @@ WARNING: no HTML output available. try: import xmlrunner as XTST -except: +except Exception: XTST = None errPrint(""" WARNING: no XML output available for unittest. diff --git a/commands/application.py b/commands/application.py index 025baf3..1620b64 100644 --- a/commands/application.py +++ b/commands/application.py @@ -17,11 +17,11 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os -import stat import sys import shutil import subprocess import getpass +from gettext import gettext as _ from src import ElementTree as etree import src @@ -155,7 +155,7 @@ def customize_app(config, appli_dir, logger): if text is not None: try: n.text = text.strip("\n\t").decode("UTF-8") - except: + except Exception: sys.stderr.write("################ %s %s\n" % (node_name, text)) n.text = "?" parent.append(n) diff --git a/commands/check.py b/commands/check.py index 366a137..2cfd29f 100644 --- a/commands/check.py +++ b/commands/check.py @@ -17,8 +17,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os - import src +from gettext import gettext as _ # Define all possible option for the check command : sat check parser = src.options.Options() diff --git a/commands/clean.py b/commands/clean.py index 070b875..4cd38d2 100644 --- a/commands/clean.py +++ b/commands/clean.py @@ -16,10 +16,9 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import re import os - import src +from gettext import gettext as _ # Compatibility python 2/3 for input function # input stays input for python 3 and input = raw_input for python 2 diff --git a/commands/compile.py b/commands/compile.py index ded2297..4308bdd 100644 --- a/commands/compile.py +++ b/commands/compile.py @@ -17,10 +17,10 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os -import re import subprocess import src import src.debug as DBG +from gettext import gettext as _ # Compatibility python 2/3 for input function # input stays input for python 3 and input = raw_input for python 2 @@ -229,7 +229,7 @@ def compile_all_products(sat, config, options, products_infos, all_products_dict batch=True, verbose=0, logger_add_link = logger) - except: + except Exception: pass if check_salome_configuration: @@ -546,7 +546,7 @@ def compile_product_pip(sat, env=build_environ.environ.environ, stderr=subprocess.STDOUT).strip() pip_build_options=int(res_pip_version.split('.')[0]) < 21 - except: + except Exception: pip_build_options= True # d- install (in python or in separate product directory) if src.appli_test_property(config,"pip_install_dir", "python"): diff --git a/commands/config.py b/commands/config.py index a5997bb..4e8836b 100644 --- a/commands/config.py +++ b/commands/config.py @@ -23,10 +23,11 @@ import datetime import shutil import gettext import pprint as PP +from gettext import gettext as _ import src import src.logger as LOG -import src.debug as DBG +import src.debug as debug import src.callerName as CALN logger = LOG.getDefaultLogger() @@ -1068,7 +1069,7 @@ def get_config_children(config, args): if dir(a).__contains__('keys'): vals = map(lambda x: head + '.' + x, [m for m in a.keys() if m.startswith(tail)]) - except: + except Exception: pass for v in sorted(vals): @@ -1110,7 +1111,7 @@ def run(args, runner, logger): if options.debug: if options.debug == ".": # if argument is ".", print all the config - res = DBG.indent(DBG.getStrConfigDbg(runner.cfg)) + res = debug.indent(debug.getStrConfigDbg(runner.cfg)) logger.write("\nConfig of application %s:\n\n%s\n" % (runner.cfg.VARS.application, res)) else: if options.debug[0] == ".": # accept ".PRODUCT.etc" as "PRODUCT.etc" @@ -1124,7 +1125,7 @@ def run(args, runner, logger): exec(aCode, globals(), aDict) # DBG.write("globals()", globals(), True) # DBG.write("aDict", aDict, True) - res = DBG.indent(DBG.getStrConfigDbg(aDict["a"])) + res = debug.indent(debug.getStrConfigDbg(aDict["a"])) logger.write("\nConfig.%s of application %s:\n\n%s\n" % (od, runner.cfg.VARS.application, res)) except Exception as e: msg = "\nConfig.%s of application %s: Unknown pyconf key\n" % (od, runner.cfg.VARS.application) @@ -1160,7 +1161,7 @@ def run(args, runner, logger): # DBG.write("products", sorted(runner.cfg.APPLICATION.products.keys()), True) src.check_config_has_application(runner.cfg) taggedProducts = src.getProductNames(runner.cfg, options.info, logger) - DBG.write("tagged products", sorted(taggedProducts)) + debug.write("tagged products", sorted(taggedProducts)) for prod in sorted(taggedProducts): if prod in runner.cfg.APPLICATION.products: try: diff --git a/commands/configure.py b/commands/configure.py index 876e928..ac1ac26 100644 --- a/commands/configure.py +++ b/commands/configure.py @@ -17,8 +17,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os - import src +from gettext import gettext as _ # Define all possible option for configure command : sat configure parser = src.options.Options() diff --git a/commands/doc.py b/commands/doc.py index 0c9b448..a776785 100644 --- a/commands/doc.py +++ b/commands/doc.py @@ -18,6 +18,7 @@ import os import src +from gettext import gettext as _ # Define all possible option for log command : sat doc parser = src.options.Options() diff --git a/commands/environ.py b/commands/environ.py index 7b26763..41f8817 100644 --- a/commands/environ.py +++ b/commands/environ.py @@ -17,6 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os +from gettext import gettext as _ import src diff --git a/commands/find_duplicates.py b/commands/find_duplicates.py index 56e7143..e271f54 100644 --- a/commands/find_duplicates.py +++ b/commands/find_duplicates.py @@ -17,6 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os +from gettext import gettext as _ import src diff --git a/commands/generate.py b/commands/generate.py index fbd08aa..bbea5f7 100644 --- a/commands/generate.py +++ b/commands/generate.py @@ -21,10 +21,11 @@ import sys import shutil import imp import subprocess +from gettext import gettext as _ import src from src.versionMinorMajorPatch import MinorMajorPatch as MMP -import src.debug as DBG +import src.debug as debug parser = src.options.Options() parser.add_option('p', 'products', 'list2', 'products', @@ -147,7 +148,7 @@ def generate_component(config, compo, product_name, product_info, context, heade # get files to build a template GUI try: # try new yacsgen api gui_files = salome_compo.getGUIfilesTemplate(compo) - except: # use old yacsgen api + except Exception: # use old yacsgen api gui_files = salome_compo.getGUIfilesTemplate() else: gui_files = None diff --git a/commands/init.py b/commands/init.py index 592843a..7cea38a 100644 --- a/commands/init.py +++ b/commands/init.py @@ -17,6 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os +from gettext import gettext as _ import src diff --git a/commands/install.py b/commands/install.py index 2811a6a..ce056c6 100644 --- a/commands/install.py +++ b/commands/install.py @@ -18,12 +18,10 @@ import os import shutil -import re -import subprocess +from gettext import gettext as _ import src -import prepare -import src.debug as DBG +import src.debug as debug PACKAGE_EXT=".tar.gz" # the extension we use for the packages @@ -219,7 +217,7 @@ def description(): def run(args, runner, logger): '''method that is called when salomeTools is called with install parameter. ''' - DBG.write("install.run()", args) + debug.write("install.run()", args) # Parse the options (options, args) = parser.parse_args(args) @@ -240,7 +238,7 @@ def run(args, runner, logger): from compile import get_dependencies_graph,depth_search_graph all_products_graph=get_dependencies_graph(all_products_infos) #logger.write("Dependency graph of all application products : %s\n" % all_products_graph, 6) - DBG.write("Dependency graph of all application products : ", all_products_graph) + debug.write("Dependency graph of all application products : ", all_products_graph) products_infos=[] if options.products is None: diff --git a/commands/job.py b/commands/job.py index f5805fe..27980ec 100644 --- a/commands/job.py +++ b/commands/job.py @@ -17,6 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os +from gettext import gettext as _ import src import src.salomeTools diff --git a/commands/jobs.py b/commands/jobs.py index c043d70..1e7ec65 100644 --- a/commands/jobs.py +++ b/commands/jobs.py @@ -26,11 +26,12 @@ import csv import shutil import itertools import re +from gettext import gettext as _ # generate problem try: import paramiko -except: +except Exception: paramiko = "import paramiko impossible" pass @@ -114,7 +115,7 @@ class Machine(object): except paramiko.SSHException: message = ( _("SSHException error connecting or " "establishing an SSH session")) - except: + except Exception: message = ( _("Error connecting or establishing an SSH session")) else: self._connection_successful = True @@ -215,7 +216,7 @@ class Machine(object): ": the server failed to execute the command\n") logger.write( src.printcolors.printcError(message)) return (None, None, None) - except: + except Exception: logger.write( src.printcolors.printcError(src.KO_STATUS + '\n')) return (None, None, None) else: @@ -327,7 +328,7 @@ class Job(object): ''' try: pids = self.get_pids() - except: + except Exception: return ("Unable to get the pid of the command.", "") cmd_kill = " ; ".join([("kill -2 " + pid) for pid in pids]) diff --git a/commands/launcher.py b/commands/launcher.py index ea7cc82..1dac9a4 100644 --- a/commands/launcher.py +++ b/commands/launcher.py @@ -17,14 +17,13 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os -import platform import shutil import getpass import subprocess import stat +from gettext import gettext as _ import src -import src.debug as DBG parser = src.options.Options() diff --git a/commands/log.py b/commands/log.py index 22a7885..0fe9785 100644 --- a/commands/log.py +++ b/commands/log.py @@ -22,6 +22,7 @@ import re import glob import datetime import stat +from gettext import gettext as _ # Compatibility python 2/3 for input function # input stays input for python 3 and input = raw_input for python 2 @@ -181,7 +182,7 @@ def ask_value(nb): x = int(rep) if x > nb: x = -1 - except: + except Exception: x = -1 return x @@ -269,7 +270,7 @@ def run(args, runner, logger): src.ensure_path_exists(os.path.join(logDir, "TEST")) shutil.copy(xsltest, os.path.join(logDir, "TEST")) shutil.copy(imgLogo, logDir) - except: + except Exception: # we are here if an user make sat log in jenkins LOGS without write rights # Make a warning and do nothing logger.warning("problem for writing in directory '%s', may be not owner." % logDir) @@ -338,7 +339,7 @@ def run(args, runner, logger): notShownCommands = notShownCommands) logger.write(src.printcolors.printc("OK"), 3) - except: + except Exception: logger.write(src.printcolors.printc("KO"), 3) logger.write(" problem update hat.xml", 3) diff --git a/commands/make.py b/commands/make.py index 39f562a..c1fa8b3 100644 --- a/commands/make.py +++ b/commands/make.py @@ -18,6 +18,7 @@ import os import re +from gettext import gettext as _ import src diff --git a/commands/makeinstall.py b/commands/makeinstall.py index eea3f85..69efa09 100644 --- a/commands/makeinstall.py +++ b/commands/makeinstall.py @@ -17,6 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os +from gettext import gettext as _ import src diff --git a/commands/package.py b/commands/package.py index f91476e..2bfbef3 100644 --- a/commands/package.py +++ b/commands/package.py @@ -24,13 +24,15 @@ import tarfile import codecs import string import glob -import pprint as PP import sys +from gettext import gettext as _ + +import pprint as PP import src -from application import get_SALOME_modules from src.versionMinorMajorPatch import MinorMajorPatch as MMP -import src.debug as DBG +import src.debug as debug +from commands.application import get_SALOME_modules old_python = sys.version_info[0] == 2 and sys.version_info[1] <= 6 @@ -166,7 +168,7 @@ def add_files(tar, name_archive, d_content, logger, f_exclude=None): success = 0 # loop over each directory or file stored in the d_content dictionary names = sorted(d_content.keys()) - DBG.write("add tar names", names) + debug.write("add tar names", names) # used to avoid duplications (for pip install in python, or single_install_dir cases) already_added=set() @@ -385,7 +387,7 @@ def hack_for_distene_licence(filepath, licence_file): import imp distene = imp.load_source('distene_licence', distene_licence_file) distene.set_distene_variables(context) - except: + except Exception: pass\n""" % licence_file text.insert(num_line + 1, text_to_insert) for line in text: @@ -948,7 +950,7 @@ def source_package(sat, config, logger, options, tmp_working_dir): if not src.architecture.is_windows(): try: t = os.getcwd() - except: + except Exception: # In the jobs, os.getcwd() can fail t = config.LOCAL.workdir os.chdir(tmp_working_dir) @@ -1326,7 +1328,7 @@ def find_product_scripts_and_pyconf(p_name, sections = [p_info.section] for section in sections: if section in product_pyconf_cfg and "get_source" in product_pyconf_cfg[section]: - DBG.write("sat package set archive mode to archive for product %s and section %s" %\ + debug.write("sat package set archive mode to archive for product %s and section %s" %\ (p_name,section)) product_pyconf_cfg[section].get_source = "archive" if not "archive_info" in product_pyconf_cfg[section]: @@ -1447,7 +1449,7 @@ def project_package(config, name_project, project_file_path, ftp_mode, tmp_worki try: project_pyconf_cfg = config.PROJECTS.projects.__getattr__(name_project) - except: + except Exception: 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) @@ -1846,7 +1848,7 @@ Please add it in file: options, logger)) if options.project: - DBG.write("config for package %s" % options.project, runner.cfg) + debug.write("config for package %s" % options.project, runner.cfg) d_files_to_add.update(project_package(runner.cfg, options.project, options.project_file_path, options.ftp, tmp_working_dir, options.sat, logger)) if not(d_files_to_add): @@ -1899,7 +1901,7 @@ Please add it in file: # case if no application, only package sat as 'sat package -t' try: app = runner.cfg.APPLICATION - except: + except Exception: app = None # unconditionaly remove the tmp_local_working_dir @@ -1909,7 +1911,7 @@ Please add it in file: shutil.rmtree(tmp_local_working_dir) # remove the tmp directory, unless user has registered as developer - if os.path.isdir(tmp_working_dir) and (not DBG.isDeveloper()): + if os.path.isdir(tmp_working_dir) and (not debug.isDeveloper()): shutil.rmtree(tmp_working_dir) # Print again the path of the package diff --git a/commands/patch.py b/commands/patch.py index ec43865..a42a718 100644 --- a/commands/patch.py +++ b/commands/patch.py @@ -18,10 +18,9 @@ import os import subprocess -import re +from gettext import gettext as _ import src -import prepare # Define all possible option for patch command : sat patch parser = src.options.Options() diff --git a/commands/prepare.py b/commands/prepare.py index 71a44a8..60f7f71 100644 --- a/commands/prepare.py +++ b/commands/prepare.py @@ -16,12 +16,10 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import re import os -import pprint as PP +from gettext import gettext as _ import src -import src.debug as DBG # Define all possible option for prepare command : sat prepare diff --git a/commands/run.py b/commands/run.py index c6138e5..c1bd847 100644 --- a/commands/run.py +++ b/commands/run.py @@ -18,6 +18,7 @@ import os import subprocess +from gettext import gettext as _ import src diff --git a/commands/script.py b/commands/script.py index 824a133..a2b4bda 100644 --- a/commands/script.py +++ b/commands/script.py @@ -17,6 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os +from gettext import gettext as _ import src diff --git a/commands/shell.py b/commands/shell.py index c213975..f8257d2 100644 --- a/commands/shell.py +++ b/commands/shell.py @@ -17,6 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import subprocess +from gettext import gettext as _ import src diff --git a/commands/source.py b/commands/source.py index 832e484..b558422 100644 --- a/commands/source.py +++ b/commands/source.py @@ -18,12 +18,10 @@ import os import shutil -import re -import subprocess +from gettext import gettext as _ import src -import prepare -import src.debug as DBG +import src.debug as debug # Define all possible option for patch command : sat patch parser = src.options.Options() @@ -554,7 +552,7 @@ def description(): def run(args, runner, logger): '''method that is called when salomeTools is called with source parameter. ''' - DBG.write("source.run()", args) + debug.write("source.run()", args) # Parse the options (options, args) = parser.parse_args(args) diff --git a/commands/template.py b/commands/template.py index e4ddc59..8883185 100644 --- a/commands/template.py +++ b/commands/template.py @@ -22,6 +22,7 @@ import shutil import subprocess import fnmatch import re +from gettext import gettext as _ import src @@ -35,7 +36,7 @@ except NameError: # Python 2/3 compatibility for execfile function try: execfile -except: +except Exception: def execfile(somefile, global_vars, local_vars): with open(somefile) as f: code = compile(f.read(), somefile, 'exec') diff --git a/commands/test.py b/commands/test.py index 62fd7fe..1085482 100644 --- a/commands/test.py +++ b/commands/test.py @@ -22,6 +22,7 @@ import shutil import subprocess import datetime import gzip +from gettext import gettext as _ # Compatibility python 2/3 for input function # input stays input for python 3 and input = raw_input for python 2 @@ -174,7 +175,7 @@ def move_test_results(in_dir, what, out_dir, logger): #shutil.rmtree(finalPath) os.makedirs(finalPath) pathIsOk = True - except: + except Exception: logger.error(_("%s cannot be created.") % finalPath) finalPath = ask_a_path() @@ -664,7 +665,7 @@ def run(args, runner, logger): if os.access(tmp_dir, os.F_OK): try: shutil.rmtree(tmp_dir) - except: + except Exception: logger.error(_("error removing TT_TMP_RESULT %s\n") % tmp_dir) diff --git a/data/local.pyconf b/data/local.pyconf index 24ee9eb..3a68b58 100644 --- a/data/local.pyconf +++ b/data/local.pyconf @@ -1,4 +1,3 @@ - LOCAL : { base : 'default' @@ -12,5 +11,6 @@ { project_file_paths : [ + '/home/catA/gb262689/cea-projects/salome/sat_salome_fork_gb262689/salome.pyconf' ] } diff --git a/data/templates/Application/config/splash_generator/splash2.py b/data/templates/Application/config/splash_generator/splash2.py index 1521075..8c9e3cd 100755 --- a/data/templates/Application/config/splash_generator/splash2.py +++ b/data/templates/Application/config/splash_generator/splash2.py @@ -9,7 +9,7 @@ import os, sys try: __LANG__ = os.environ["LANG"] # original locale -except: +except Exception: __LANG__ = "en_US.utf8" #default __FR__={ @@ -27,7 +27,7 @@ def _loc(text): if "FR" in __LANG__: try: return __FR__[text] - except: + except Exception: return text return text diff --git a/data/templates/PythonComponent/src/PYCMP/PYCMP_utils.py b/data/templates/PythonComponent/src/PYCMP/PYCMP_utils.py index 56e1557..da4f92b 100755 --- a/data/templates/PythonComponent/src/PYCMP/PYCMP_utils.py +++ b/data/templates/PythonComponent/src/PYCMP/PYCMP_utils.py @@ -88,7 +88,7 @@ def verbose(): if __verbose__ is None: try: __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) ) - except: + except Exception: __verbose__ = 0 pass pass @@ -177,7 +177,7 @@ def findOrCreateComponent( study ): try: builder.DefineComponentInstance( father, getEngine() ) pass - except: + except Exception: pass pass return father diff --git a/data/templates/PythonComponent8/src/PYCMP/PYCMP_utils.py b/data/templates/PythonComponent8/src/PYCMP/PYCMP_utils.py index 56e1557..da4f92b 100755 --- a/data/templates/PythonComponent8/src/PYCMP/PYCMP_utils.py +++ b/data/templates/PythonComponent8/src/PYCMP/PYCMP_utils.py @@ -88,7 +88,7 @@ def verbose(): if __verbose__ is None: try: __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) ) - except: + except Exception: __verbose__ = 0 pass pass @@ -177,7 +177,7 @@ def findOrCreateComponent( study ): try: builder.DefineComponentInstance( father, getEngine() ) pass - except: + except Exception: pass pass return father diff --git a/src/ElementTree.py b/src/ElementTree.py index b871200..d13441d 100644 --- a/src/ElementTree.py +++ b/src/ElementTree.py @@ -6,21 +6,21 @@ appending method tostring serialize 'pretty_xml' """ import sys -import debug as DBG +import src.debug as debug _versionPython = sys.version_info[0] if _versionPython < 3: # python2 previous historic mode import src.ElementTreePython2 as etree - DBG.write("ElementTree Python2 %s" % etree.VERSION, etree.__file__, DBG.isDeveloper()) + debug.write("ElementTree Python2 %s" % etree.VERSION, etree.__file__, debug.isDeveloper()) tostring = etree.tostring else: # python3 mode # import xml.etree.ElementTree as etree # native version import src.ElementTreePython3 as etree # VERSION 1.3.0 plus _serialize 'pretty_xml' - DBG.write("ElementTree Python3 %s" % etree.VERSION, etree.__file__, DBG.isDeveloper()) + debug.write("ElementTree Python3 %s" % etree.VERSION, etree.__file__, debug.isDeveloper()) def tostring(node, encoding='utf-8'): """ @@ -30,7 +30,7 @@ else: """ try: aStr = etree.tostring(node, encoding='unicode', method="pretty_xml") - except: + except Exception: print("*****************************\n problem node", node) # try no pretty aStr = etree.tostring(node, encoding='unicode') diff --git a/src/ElementTreePython2.py b/src/ElementTreePython2.py index d1ba909..4b31874 100644 --- a/src/ElementTreePython2.py +++ b/src/ElementTreePython2.py @@ -700,7 +700,7 @@ class ElementTree: if items or xmlns_items: try: items = sorted(items) # lexical order - except: + except Exception: print("*** problem sorting items", items) for k, v in items: try: @@ -1086,7 +1086,7 @@ class TreeBuilder: for item in self._data: try: text += item - except: + except Exception: text += item.decode() if self._tail: assert self._last.tail is None, "internal error (tail)" @@ -1292,7 +1292,7 @@ class XMLTreeBuilder: """ try: self._parser.Parse(data, 0) - except: + except Exception: print("*** problem feed:\n%s" % data.decode('utf-8')) ## diff --git a/src/ElementTreePython3.py b/src/ElementTreePython3.py index 68635ce..185828a 100644 --- a/src/ElementTreePython3.py +++ b/src/ElementTreePython3.py @@ -97,7 +97,7 @@ import warnings import io import contextlib -import ElementPath +from src import ElementPath class ParseError(SyntaxError): @@ -1266,7 +1266,7 @@ def iterparse(source, events=None, parser=None): close_source = True try: return _IterParseIterator(source, events, parser, close_source) - except: + except Exception: if close_source: source.close() raise @@ -1365,7 +1365,7 @@ class _IterParseIterator: else: self._root = self._parser._close_and_return_root() self.root = self._root - except: + except Exception: if self._close_file: self._file.close() raise diff --git a/src/architecture.py b/src/architecture.py index 6e83d0b..0d61421 100644 --- a/src/architecture.py +++ b/src/architecture.py @@ -21,23 +21,19 @@ In this file : all the stuff that can change with the architecture on which SAT is running ''' -import os, sys +import os +import sys +from gettext import gettext as _ 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) + from distro import distro +except Exception: + 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(): @@ -76,7 +72,7 @@ def get_distribution(codes): return "W" # else get linux distribution description from platform, and encode it with code - lin_distrib = linux_distribution()[0].lower() + lin_distrib = distro.id().lower() distrib="not found" for dist in codes: if dist in lin_distrib: @@ -95,7 +91,7 @@ def get_version_XY(): from a CentOS example, returns '7.6' extracted from platform.linux_distribution() """ - dist_version=linux_distribution()[1].split('.') + dist_version=distro.version().split('.') if len(dist_version)==1: version = dist_version[0] else: @@ -119,7 +115,7 @@ def get_distrib_version(distrib): return release() # get version from platform - dist_version=linux_distribution()[1].split('.') + dist_version=distro.version().split('.') # encode it (conform to src/internal_config/distrib.pyconf VERSIONS dist if distrib == "CO": diff --git a/src/callerName.py b/src/callerName.py index 9fd0308..439de55 100644 --- a/src/callerName.py +++ b/src/callerName.py @@ -8,8 +8,6 @@ import os import sys import inspect -import logging -import pprint as PP ############################################################################## @@ -116,7 +114,7 @@ def caller_name_stack(skip=1): if namesrc == "__main__": namesrc = os.path.basename(fr.f_globals["__file__"]) lineno.insert(0, (namesrc + "[%s]" % fr.f_lineno)) - except: + except Exception: lineno.insert(0, ("??", fr.f_lineno)) if codename != '': # top level usually diff --git a/src/compilation.py b/src/compilation.py index 751fe73..da79789 100644 --- a/src/compilation.py +++ b/src/compilation.py @@ -21,6 +21,7 @@ import subprocess import sys import shutil import glob +from gettext import gettext as _ import src @@ -440,7 +441,7 @@ CC=\\"hack_libtool\\"%g" libtool''' pymodule = imp.load_source(product + "_compile_script", script) self.nb_proc = nb_proc retcode = pymodule.compil(self.config, self, self.logger) - except: + except Exception: __, exceptionValue, exceptionTraceback = sys.exc_info() self.logger.write(str(exceptionValue), 1) import traceback diff --git a/src/debug.py b/src/debug.py index 330fb6d..a5292d2 100755 --- a/src/debug.py +++ b/src/debug.py @@ -56,12 +56,11 @@ import sys import traceback import pprint as PP import inspect -import src # Compatibility python 2/3 for unicode try: _test = unicode -except: +except Exception: unicode = str # Compatibility python 2/3 for StringIO @@ -272,7 +271,7 @@ def _saveConfigRecursiveDbg(config, aStream, indent, path, nb): try: #type config, mapping order = object.__getattribute__(config, 'order') data = object.__getattribute__(config, 'data') - except: + except Exception: aStream.write("%s%s : '%s'\n" % (indstr, path, str(config))) return for key in sorted(data): #order): # data as sort alphabetical, order as initial order diff --git a/src/environment.py b/src/environment.py index a706d5d..49c54b8 100644 --- a/src/environment.py +++ b/src/environment.py @@ -23,7 +23,7 @@ import sys import copy import src -import src.debug as DBG +import src.debug as debug import pprint as PP @@ -321,7 +321,7 @@ class SalomeEnviron: for k in self.environ.environ.keys(): try: value = self.get(k) - except: + except Exception: value = "?" out.write("%s=%s\n" % (k, value)) @@ -411,7 +411,7 @@ class SalomeEnviron: :param product_info Config: The product description :param logger Logger: The logger instance to display messages """ - DBG.write("set_salome_minimal_product_env", product_info) + debug.write("set_salome_minimal_product_env", product_info) # set root dir root_dir = product_info.name + "_ROOT_DIR" @@ -743,7 +743,7 @@ class SalomeEnviron: # not mandatory, if set_nativ_env not defined, we do nothing if "set_nativ_env" in dir(pyproduct): pyproduct.set_nativ_env(self) - except: + except Exception: __, exceptionValue, exceptionTraceback = sys.exc_info() print(exceptionValue) import traceback @@ -779,7 +779,7 @@ class SalomeEnviron: :param logger Logger: The logger instance to display messages :param env_info list: the list of products """ - DBG.write("set_full_environ for", env_info) + debug.write("set_full_environ for", env_info) # DBG.write("set_full_environ config", self.cfg.APPLICATION.environ, True) # set product environ self.set_application_env(logger) diff --git a/src/fileEnviron.py b/src/fileEnviron.py index 9e98b3f..438a2ef 100644 --- a/src/fileEnviron.py +++ b/src/fileEnviron.py @@ -18,7 +18,7 @@ import os import pprint as PP -import src.debug as DBG +import src.debug as debug import src.architecture import src.environment diff --git a/src/fork.py b/src/fork.py index aa239de..e4492f0 100644 --- a/src/fork.py +++ b/src/fork.py @@ -131,7 +131,7 @@ def batch_salome(cmd, logger, cwd, args, getTmpDir, try: statinfo = os.stat(os.path.join(tmp_dir, file_name)) currentTime = statinfo.st_mtime - except: + except Exception: pass if currentTime and currentTime > beginTime: diff --git a/src/i18n/i18nTest.py b/src/i18n/i18nTest.py index cf467da..7a2205d 100755 --- a/src/i18n/i18nTest.py +++ b/src/i18n/i18nTest.py @@ -25,6 +25,8 @@ import os import gettext import unittest +_ = gettext.gettext + verbose = False class TestCase(unittest.TestCase): diff --git a/src/logger.py b/src/logger.py index 545ac0b..fe232c0 100755 --- a/src/logger.py +++ b/src/logger.py @@ -27,12 +27,12 @@ import datetime import re import tempfile import shutil +from gettext import gettext as _ import src -import printcolors -import xmlManager - -import src.debug as DBG +import src.xmlManager as xmlManager +import src.printcolors as printcolors +import src.debug as debug log_macro_command_file_expression = "^[0-9]{8}_+[0-9]{6}_+.*\.xml$" log_all_command_file_expression = "^.*[0-9]{8}_+[0-9]{6}_+.*\.xml$" @@ -54,7 +54,7 @@ class Logger(object): :param silent_sysstd boolean: if True, do not write anything in terminal. """ - DBG.write("src.logger.Logger", id(self)) + debug.write("src.logger.Logger", id(self)) self.config = config self.default_level = 3 self.silentSysStd = silent_sysstd @@ -538,9 +538,8 @@ def setCurrentLogger(logger): logger.debug("set current logger as %s" % logger.name) else: if _currentLogger[0].name != logger.name: - # logger.debug("quit current logger as default %s" % _currentLogger[0].name) _currentLogger[0] = logger - logger.warning("change current logger as %s" % logger.name) + # logger.warning("change current logger as %s" % logger.name) return _currentLogger[0] def isCurrentLoggerUnittest(): diff --git a/src/loggingSimple.py b/src/loggingSimple.py index 177b342..4d20a2c 100755 --- a/src/loggingSimple.py +++ b/src/loggingSimple.py @@ -23,7 +23,7 @@ import logging as LOGI from logging.handlers import BufferingHandler import pprint as PP -import src.debug as DBG # Easy print stderr (for DEBUG only) +import src.debug as debug # Easy print stderr (for DEBUG only) _verbose = False _name = "loggingSimple" @@ -377,7 +377,7 @@ class StreamHandlerSimple(LOGI.StreamHandler, object): # object force new-style self.flush() except (KeyboardInterrupt, SystemExit): raise - except: + except Exception: self.handleError(record) diff --git a/src/options.py b/src/options.py index bbcf893..71885f4 100755 --- a/src/options.py +++ b/src/options.py @@ -25,11 +25,11 @@ import getopt import sys import re import pprint as PP +from gettext import gettext as _ from . import printcolors -import src -import src.debug as DBG # Easy print stderr (for DEBUG only) +import src.debug as debug class OptResult(object): """ @@ -196,7 +196,7 @@ class Options(object): if argList is None: argList = sys.argv[1:] - DBG.write("parse_args", argList) + debug.write("parse_args", argList) # DBG.write("options", self.options) # format shortNameOption and longNameOption # to make right arguments to getopt.getopt function @@ -260,19 +260,19 @@ class Options(object): option['result'] = None self.results = {"optlist": optlist, "optResult": optResult, "args": args, "argList": argList} - DBG.write("results", self.results) + debug.write("results", self.results) return optResult, args def filterLevel(self, aLevel): """filter level logging values""" - import src.loggingSimple as LOG + import src.loggingSimple as log aLev = aLevel.upper() - knownLevels = LOG._knownLevels + knownLevels = log._knownLevels maxLen = max([len(i) for i in knownLevels]) for i in range(maxLen): for lev in knownLevels: if aLev == lev[:i]: - DBG.write("filterLevel", "%s -> %s" % (aLevel, lev)) + debug.write("filterLevel", "%s -> %s" % (aLevel, lev)) return lev msg = "Unknown level '%s', accepted are:\n%s" % (aLev, ", ".join(knownLevels)) raise Exception(msg) @@ -323,6 +323,6 @@ class Options(object): return res def debug_write(self): - DBG.write("options and results", self, True) + debug.write("options and results", self, True) diff --git a/src/product.py b/src/product.py index a679e44..9ef9528 100644 --- a/src/product.py +++ b/src/product.py @@ -26,7 +26,7 @@ import re import pprint as PP import src -import src.debug as DBG +import src.debug as debug import src.versionMinorMajorPatch as VMMP AVAILABLE_VCS = ['git', 'svn', 'cvs'] @@ -304,14 +304,14 @@ Please provide a 'compil_script' key in its definition.""") % product_name script_path = src.find_file_in_lpath(script_name, config.PATHS.PRODUCTPATH, "compil_scripts") if not script_path: msg = _("Compilation script %s not found in") % script_name - DBG.tofix(msg, config.PATHS.PRODUCTPATH, True) # say where searched + debug.tofix(msg, config.PATHS.PRODUCTPATH, True) # say where searched script_path = "%s_(Not_Found_by_Sat!!)" % script_name prod_info.compil_script = script_path # Check that the script is executable if os.path.exists(prod_info.compil_script) and not os.access(prod_info.compil_script, os.X_OK): - DBG.tofix("Compilation script file is not in 'execute mode'", prod_info.compil_script, True) + debug.tofix("Compilation script file is not in 'execute mode'", prod_info.compil_script, True) # If the product has a post install script, check the script existence # and if it is executable @@ -328,14 +328,14 @@ Please provide a 'compil_script' key in its definition.""") % product_name script_path = src.find_file_in_lpath(script_name, config.PATHS.PRODUCTPATH, "post_scripts") if not script_path: msg = _("Post install script %s not found in") % script_name - DBG.tofix(msg, config.PATHS.PRODUCTPATH, True) # say where searched + debug.tofix(msg, config.PATHS.PRODUCTPATH, True) # say where searched script_path = "%s_(Not_Found_by_Sat!!)" % script_name prod_info.post_script = script_path # Check that the script is executable if os.path.exists(prod_info.post_script) and not os.access(prod_info.post_script, os.X_OK): - DBG.tofix("Post install script file is not in 'execute mode'", prod_info.post_script, True) + debug.tofix("Post install script file is not in 'execute mode'", prod_info.post_script, True) # Get the full paths of all the patches if product_has_patches(prod_info): @@ -355,8 +355,8 @@ Please provide a 'compil_script' key in its definition.""") % product_name "prod_name" : prod_info.name}) raise src.SatException(msg) patches.append(patch_path) - except: - DBG.tofix("problem in prod_info.patches", prod_info) + except Exception: + debug.tofix("problem in prod_info.patches", prod_info) prod_info.patches = patches # Get the full paths of the environment scripts @@ -425,7 +425,7 @@ def get_product_section(config, product_name, version, section=None): # decode version number try: versionMMP = VMMP.MinorMajorPatch(version) - except: # example setuptools raise "minor in major_minor_patch is not integer: '0_6c11'" + except Exception: # example setuptools raise "minor in major_minor_patch is not integer: '0_6c11'" versionMMP = None # if a section is explicitely specified we select it @@ -461,7 +461,7 @@ def get_product_section(config, product_name, version, section=None): tagged.append((name, [vmin, vmax])) if len(tagged) > 1: - DBG.write("multiple version ranges tagged for '%s', fix it" % version, + debug.write("multiple version ranges tagged for '%s', fix it" % version, PP.pformat(tagged)) pi=None elif len(tagged) == 1: # ok @@ -666,10 +666,10 @@ def add_compile_config_file(p_info, config): try: with open(aFile, 'w') as f: p_info.__save__(f, evaluated=True) # evaluated expressions mode - except: + except Exception: # sometime some information cannot be evaluated. # for example, in the context of non VCS archives, information on git server is not available. - DBG.write("Warning : sat was not able to evaluate and write down some information in file %s" % aFile) + debug.write("Warning : sat was not able to evaluate and write down some information in file %s" % aFile) def check_config_exists(config, prod_dir, prod_info, verbose=False): @@ -694,8 +694,8 @@ def check_config_exists(config, prod_dir, prod_info, verbose=False): else: raise Exception("Inexisting directory '%s'" % prod_dir) - DBG.write("check_config_exists 000", (prod_dir, l_dir_and_files), verbose) - DBG.write("check_config_exists 111", prod_info, verbose) + debug.write("check_config_exists 000", (prod_dir, l_dir_and_files), verbose) + debug.write("check_config_exists 111", prod_info, verbose) depend_all=[] if "depend" in prod_info: @@ -714,7 +714,7 @@ def check_config_exists(config, prod_dir, prod_info, verbose=False): # directory afilename = CONFIG_FILENAME + prod_info.name + ".pyconf" config_file = os.path.join(prod_dir, dir_or_file, afilename) - DBG.write("check_config_exists 222", config_file, verbose) + debug.write("check_config_exists 222", config_file, verbose) if not os.path.exists(config_file): continue @@ -741,7 +741,7 @@ def check_config_exists(config, prod_dir, prod_info, verbose=False): # assume new compatibility with prod_name in sat-config.pyconf files if prod_name == prod_info.name: if prod_info.version == compile_cfg[prod_name]: - DBG.write("check_config_exists OK 333", compile_cfg, verbose) + debug.write("check_config_exists OK 333", compile_cfg, verbose) pass else: # no correspondence with newer with prod_name sat-config.pyconf files config_corresponds = False @@ -754,7 +754,7 @@ def check_config_exists(config, prod_dir, prod_info, verbose=False): break if config_corresponds: # returns (and stops) at first correspondence found - DBG.write("check_config_exists OK 444", dir_or_file, verbose) + debug.write("check_config_exists OK 444", dir_or_file, verbose) return True, os.path.join(prod_dir, dir_or_file) # no correspondence found @@ -829,7 +829,7 @@ def get_products_list(options, cfg, logger): else: res.append((p_name, p_info)) ok.append(p_name) - except: + except Exception: res.append((p_name, p_info)) ok.append(p_name) else: @@ -840,7 +840,7 @@ def get_products_list(options, cfg, logger): ok.append(p_name) else: ko.append(p_name) - except: + except Exception: ko.append(p_name) if len(ok) != len(resAll): @@ -1003,7 +1003,7 @@ def product_is_dev(product_info): """ dev = product_info.dev res = (dev.lower() == 'yes') - DBG.write('product_is_dev %s' % product_info.name, res) + debug.write('product_is_dev %s' % product_info.name, res) # if product_info.name == "XDATA": return True #test #10569 return res diff --git a/src/pyconf.py b/src/pyconf.py index 5957d6d..d19b577 100644 --- a/src/pyconf.py +++ b/src/pyconf.py @@ -155,7 +155,7 @@ else: try: has_utf32 = True -except: +except Exception: has_utf32 = False class ConfigInputStream(object): @@ -951,7 +951,7 @@ class Reference(object): rv = eval(str(self)[1:-1], vars(ns)) found = True break - except: + except Exception: pass if found: break @@ -963,7 +963,7 @@ class Reference(object): key = item[1] rv = rv[key] break - except: + except Exception: rv = None pass current = object.__getattribute__(current, 'parent') @@ -1632,13 +1632,13 @@ class ConfigMerger(object): continue try: exec( 'map1.' + key + " = " + repr(overwrite_instruction[key])) - except: + except Exception: exec('map1.' + key + " = " + str(overwrite_instruction[key])) else: for key in overwrite_instruction.keys(): try: exec('map1.' + key + " = " + repr(overwrite_instruction[key])) - except: + except Exception: exec('map1.' + key + " = " + str(overwrite_instruction[key])) def mergeMapping(self, map1, map2): diff --git a/src/returnCode.py b/src/returnCode.py index 1af9116..240eb63 100644 --- a/src/returnCode.py +++ b/src/returnCode.py @@ -148,7 +148,7 @@ class ReturnCode(object): """return system return code as bash or bat""" try: return self._TOSYS[self._status] - except: + except Exception: return self._TOSYS[self.NA_STATUS] def toXmlPassed(self): diff --git a/src/salomeTools.py b/src/salomeTools.py index a49524b..04b7dea 100755 --- a/src/salomeTools.py +++ b/src/salomeTools.py @@ -16,6 +16,20 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +import sys +from gettext import gettext as _ +import os +import re +import tempfile +import imp +import types +import gettext + +import src +import src.debug as debug # Easy print stderr (for DEBUG only) +import src.returnCode as RCO # Easy (ok/ko, why) return methods code +import src.utilsSat as UTS + """ This file is the main API file for salomeTools @@ -25,8 +39,6 @@ This file is the main API file for salomeTools | Usage: see file ../sat """ -import sys - # exit OKSYS and KOSYS seems equal on linux or windows _OKSYS = 0 # OK _KOSYS = 1 # KO @@ -41,19 +53,6 @@ ERROR: 'salomeTools.py' is not main command entry (CLI) for salomeTools. sys.stderr.write(msg) sys.exit(_KOSYS) -# python imports -import os -import re -import tempfile -import imp -import types -import gettext -import traceback - -import src -import src.debug as DBG # Easy print stderr (for DEBUG only) -import src.returnCode as RCO # Easy (ok/ko, why) return methods code -import src.utilsSat as UTS # get path to salomeTools sources satdir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) @@ -67,7 +66,7 @@ gettext.install("salomeTools", os.path.join(srcdir, "i18n")) try: _LANG = os.environ["LANG"] # original locale -except: +except Exception: _LANG = "en_US.utf8" #default # The possible hooks : @@ -149,7 +148,7 @@ def setNotLocale(): """force english at any moment""" os.environ["LANG"] = '' gettext.install("salomeTools", os.path.join(srcdir, "i18n")) - DBG.write("setNotLocale", os.environ["LANG"]) + debug.write("setNotLocale", os.environ["LANG"]) def setLocale(): """ @@ -159,7 +158,7 @@ def setLocale(): """ os.environ["LANG"] = _LANG gettext.install("salomeTools", os.path.join(srcdir, "i18n")) - DBG.write("setLocale", os.environ["LANG"]) + debug.write("setLocale", os.environ["LANG"]) def getVersion(): """get version number as string""" @@ -235,13 +234,13 @@ class Sat(object): """set the commands by calling the dedicated function etc...""" options, remaindersArgs = parser.parse_args(opt) if options.debug_mode: - DBG.push_debug(True) + debug.push_debug(True) self.arguments = opt self.options = options # the generic options passed to salomeTools self.remaindersArgs = remaindersArgs # the command and their options self.datadir = datadir # default value will be /data self._setCommands(cmdsdir) - DBG.write("Sat.options", self.options, self.options.debug_mode) + debug.write("Sat.options", self.options, self.options.debug_mode) def getConfig(self): return self.cfg @@ -264,8 +263,8 @@ class Sat(object): self.mainLogger.info(get_help()) return RCO.ReturnCode("OK", "help done") - DBG.write("options", self.options) - DBG.write("remaindersArgs", self.remaindersArgs) + debug.write("options", self.options) + debug.write("remaindersArgs", self.remaindersArgs) if len(self.remaindersArgs) == 0: return RCO.ReturnCode("KO", "Nothing to do") @@ -285,7 +284,8 @@ class Sat(object): # Run the command using the arguments code = fun_command(self.remaindersArgs[1:]) - if code is None: code = 0 # what?! do not know why so respect history + if code is None: + code = 0 # return salomeTools command with the right message # code (0 if no errors, else 1) @@ -356,13 +356,14 @@ class Sat(object): sys.stderr = ff import paramiko sys.stderr = saveout - except: + except Exception: sys.stderr = saveout continue # load the module that has name nameCmd in dirPath (file_, pathname, description) = imp.find_module(nameCmd, [dirPath]) module = imp.load_module(nameCmd, file_, pathname, description) + file_.close() def run_command(args='', options=None, @@ -488,7 +489,7 @@ class Sat(object): logger_command.write(" *****\n", 1) print(e.message) if self.options.debug_mode: - logger_command.write("\n" + DBG.format_exception("") + "\n", 1) + logger_command.write("\n" + debug.format_exception("") + "\n", 1) except Exception as e: # here we print the stack in addition @@ -496,7 +497,7 @@ class Sat(object): logger_command.write(src.printcolors.printcError( "salomeTools ERROR: sat %s" % __nameCmd__), 1) - logger_command.write("\n" + DBG.format_exception("") + "\n", 1) + logger_command.write("\n" + debug.format_exception("") + "\n", 1) finally: @@ -678,6 +679,7 @@ class Sat(object): # load the module (file_, pathname, description) = imp.find_module(module, [cmdsdir]) module = imp.load_module(module, file_, pathname, description) + file_.close() return module ################################################################## diff --git a/src/system.py b/src/system.py index acb6fea..544e6c7 100644 --- a/src/system.py +++ b/src/system.py @@ -25,13 +25,12 @@ import os import subprocess as SP import time import tarfile -import time +from gettext import gettext as _ - -import debug as DBG -import utilsSat as UTS import src +from . import utilsSat as UTS +from . import debug from . import printcolors def show_in_editor(editor, filePath, logger): @@ -53,7 +52,7 @@ def show_in_editor(editor, filePath, logger): logger.write('Launched command:\n' + cmd + '\n', 5) p = SP.Popen(cmd, shell=True) p.communicate() - except: + except Exception: logger.write(printcolors.printcError(_("Unable to edit file %s\n") % filePath), 1) @@ -105,7 +104,7 @@ def git_describe(repo_path): '''Use git describe --tags command to return tag description of the git repository" :param repo_path str: The git repository to describe ''' - git_cmd="cd %s;git describe --tags" % repo_path + git_cmd=f"cd {repo_path};git describe --tags" p = SP.Popen(git_cmd, shell=True, stdin=SP.PIPE, stdout=SP.PIPE, stderr=SP.PIPE) p.wait() if p.returncode != 0: @@ -130,7 +129,7 @@ def git_extract(from_what, tag, git_options, where, logger, environment=None): :return: True if the extraction is successful :rtype: boolean ''' - DBG.write("git_extract", [from_what, tag, str(where)]) + debug.write("git_extract", [from_what, tag, str(where)]) if not where.exists(): where.make() where_git = os.path.join(str(where), ".git") @@ -178,7 +177,7 @@ exit $res logger.logTxtFile.write("\n" + cmd + "\n") logger.logTxtFile.flush() - DBG.write("cmd", cmd) + debug.write("cmd", cmd) # git commands may fail sometimes for various raisons # (big module, network troubles, tuleap maintenance) # therefore we give several tries @@ -227,7 +226,7 @@ def git_extract_sub_dir(from_what, tag, git_options, where, sub_dir, logger, env 'parentWhere': parentWhere, 'tmpWhere': tmpWhere, } - DBG.write("git_extract_sub_dir", aDict) + debug.write("git_extract_sub_dir", aDict) if not src.architecture.is_windows(): cmd = r""" set -x @@ -253,7 +252,7 @@ git log -1 > %(where)s/README_git_log.txt && \ rm -rf $tmpDir """ % aDict - DBG.write("cmd", cmd) + debug.write("cmd", cmd) for nbtry in range(0,3): # retries case of network problem rc = UTS.Popen(cmd, cwd=parentWhere, env=environment.environ.environ, logger=logger) @@ -444,7 +443,7 @@ def check_system_pkg(check_cmd,pkg): try: output = SP.check_output(['grep', pkg], stdin=p.stdout) msg_status=src.printcolors.printcSuccess("OK") - except: + except Exception: msg_status=src.printcolors.printcError("KO") msg_status+=" (package is not installed!)\n" elif check_cmd[0] == "dpkg-query": diff --git a/src/test_module.py b/src/test_module.py index 03c7b58..218ba18 100644 --- a/src/test_module.py +++ b/src/test_module.py @@ -19,7 +19,7 @@ # Python 2/3 compatibility for execfile function try: execfile -except: +except Exception: def execfile(somefile, global_vars, local_vars): with open(somefile) as f: code = compile(f.read(), somefile, 'exec') @@ -354,12 +354,12 @@ class Test: if 'time' in ldic: try: exec_time = float(ldic['time']) - except: + except Exception: pass results[test] = [status, exec_time, callback, expected] - except: + except Exception: results[test] = ["?", -1, "", []] # results[test] = [src.O_STATUS, -1, open(resfile, 'r').read(), []] @@ -484,7 +484,7 @@ echo -e 'import os\nprint(os.environ[\"KERNEL_ROOT_DIR\"])' > tmpscript.py try: grid = imp.load_module(sal_uts, file_, pathname, description) return grid.getLogDir - except: + except Exception: grid = imp.load_module(sal_uts, file_, pathname, description) return grid.getTmpDir finally: diff --git a/src/versionMinorMajorPatch.py b/src/versionMinorMajorPatch.py index a8df954..e7d8731 100755 --- a/src/versionMinorMajorPatch.py +++ b/src/versionMinorMajorPatch.py @@ -90,7 +90,7 @@ def toList_majorMinorPatch(aStr, verbose=False): try: ii = int(res[0]) - except: + except Exception: msg = "major in major_minor_patch is not integer: '%s'" % aStr raise Exception(msg) if ii < 0: @@ -99,7 +99,7 @@ def toList_majorMinorPatch(aStr, verbose=False): try: ii = int(res[1]) - except: + except Exception: msg = "minor in major_minor_patch is not integer: '%s'" % aStr raise Exception(msg) if ii < 0: @@ -108,7 +108,7 @@ def toList_majorMinorPatch(aStr, verbose=False): try: ii = int(res[2]) - except: + except Exception: msg = "patch in major_minor_patch is not integer: '%s'" % aStr raise Exception(msg) if ii < 0: @@ -186,7 +186,7 @@ def getRange_majorMinorPatch(aStr, verbose=False): try: rMin = MinorMajorPatch(aMin) rMax = MinorMajorPatch(aMax) - except: + except Exception: msg = "problem version range in '%s'" % aStr raise Exception(msg) """if verbose: diff --git a/src/xmlManager.py b/src/xmlManager.py index 6a4bb66..8f7f28e 100644 --- a/src/xmlManager.py +++ b/src/xmlManager.py @@ -23,7 +23,7 @@ try: # For python2 import sys reload(sys) sys.setdefaultencoding('utf8') -except: +except Exception: pass import src