diff --git a/lib/aslint/base_checkers.py b/lib/aslint/base_checkers.py index 873cf50f0417a957281b8e356ea8fa4534151439..881589a15aaf356c50b12a5e2b71b74bc31b3d75 100644 --- a/lib/aslint/base_checkers.py +++ b/lib/aslint/base_checkers.py @@ -417,8 +417,17 @@ def checkers_from_context(dict_objects, typm): return msg -def search_msg(expr): - """Convenient wrapper to search 'expr' with relevant re flags.""" +def search_msg(expr, ignore_case=True): + """Convenient wrapper to search 'expr' with relevant re flags. + + Arguments: + expr (str): Regular expression to search. + ignore_case (bool, optional): If *True* (the default) a case-insensitive + search is performed. + """ + flag = re.M + if ignore_case: + flag |= re.I return re.compile(expr, re.M | re.I).finditer # categories of checkers to filter checklist diff --git a/lib/aslint/common_checkers.py b/lib/aslint/common_checkers.py index db7534db716e2859eba33c7dce529082220d2d4c..c2695990403c418d4c7aaf37bc04aebf6cc9e5c5 100644 --- a/lib/aslint/common_checkers.py +++ b/lib/aslint/common_checkers.py @@ -5,6 +5,7 @@ They may be included together using CHECK_LIST or individually.""" import os +import os.path as osp import stat import re import time @@ -50,10 +51,12 @@ class IncorrectPermission(FilenameCat, GenericMsg): def search(self, fname): """Check for file mode""" result = [] + if not osp.isfile(fname): + return [] if set([re.search(expr, fname) for expr in SCRIPTS]) != set([None]): return result mode = os.stat(fname).st_mode - if mode & self._req != self._req or mode & (self._bad) != 0: + if mode & self._req != self._req or mode & self._bad != 0: result.append(' not %s' % (oct(mode)[-3:])) return result @@ -153,7 +156,7 @@ class InvalidEncoding(FilenameCat, GenericMsg): def search(self, fname): """Check for file encoding""" result = [] - if fname == "waf.engine" or is_binary(fname): + if not osp.isfile(fname) or fname == "waf.engine" or is_binary(fname): return result if not check_encoding(open(fname, 'rb').read(), 'utf-8'): result.append('') diff --git a/lib/aslint/other/cxx_checkers.py b/lib/aslint/other/cxx_checkers.py index b88f9d3aabaa646c0827f9c718c2f5b08332bc00..29adfb758eed88c96164202222e7c3e3fca9e9d0 100644 --- a/lib/aslint/other/cxx_checkers.py +++ b/lib/aslint/other/cxx_checkers.py @@ -2,6 +2,7 @@ """Checkers for CXX source files""" +import os.path as osp import re import aslint.common_checkers as COMM @@ -23,7 +24,7 @@ class MissingConstructor(FilenameCat, GenericMsg): def search(self, filename): """Check that at least two constructors exist for each class.""" error = [] - if not filename.endswith("Interface.cxx"): + if not filename.endswith("Interface.cxx") or not osp.isfile(filename): return error with open(filename, "r") as fobj: diff --git a/lib/aslint/python/python_checkers.py b/lib/aslint/python/python_checkers.py index 37ba0f17d8e7c151e249dc917c4869c02bf6a7fa..ee612b58e752244ae2168730e54031b28146183c 100644 --- a/lib/aslint/python/python_checkers.py +++ b/lib/aslint/python/python_checkers.py @@ -65,7 +65,7 @@ class ExecUsed(FileContentCat, TextMsg): """Using 'exec()' is discouraged""" id = "C4007" - search = search_msg(r"\b(?P<main>exec *\(.*)") + search = search_msg(r"\b(?P<main>exec *\(.*)", ignore_case=False) CHECK_LIST = checkers_from_context(globals(), TextMsg) diff --git a/lib/aslint/test/test_checkers.py b/lib/aslint/test/test_checkers.py index e2bd9db2fb63bd2156c70ac370350b8942a69e99..f0035855b0f6b8eec05dad2fe6cf4bed77a3d889 100644 --- a/lib/aslint/test/test_checkers.py +++ b/lib/aslint/test/test_checkers.py @@ -21,14 +21,20 @@ REG_EXT = ("com[m0-9]", "py", "data", "datg", "export", "[0-9]{1,2}", "mail", "mgib", "med", "mmed", "msh", "msup", "mfront") -class UnsupportedExtension(FilenameCat, TextMsgNotFound): +class UnsupportedExtension(FilenameCat, TextMsg): """Unsupported extension Only these extensions are allowed for testcases: .comm, .com[0-9], .py, .data, .datg, .export, .mail, .mgib, .mmed, .msh, .msup, .[0-9]+""" id = "C9002" fmt = "%(id)s: %(label)s" - search = search_msg(r"(?P<ext>\.(" + "|".join(REG_EXT) + "))$") + _search = search_msg(r"(?P<ext>\.(" + "|".join(REG_EXT) + "))$") + + def search(self, fname): + """Check for unsupported extension.""" + if not osp.isfile(fname) or self._search(fname): + return [] + return [fname] class InvalidFilename(FilenameCat, TextMsgNotFound): @@ -105,13 +111,13 @@ class InvalidFilenameXX(FilenameCat, TextMsgNotFound): # - mac3c needs the '3' # accept aaaaNNNm + a suffix starting with '_' # accept 'xx*' - _expr1 = re.compile(r"/(?P<root>[a-z3]{3,5}[0-9]{2,3}[a-z]{1})" + _expr1 = re.compile(r"/(?P<root>[a-z3]{3,16}[0-9]{2,3}[a-z]{1})" r"(?P<ext>\.(" + "|".join(REG_EXT) + "))$") - _expr2 = re.compile(r"/(?P<root>[a-z3]{3,5}[0-9]{2,3}[a-z]{1}" + _expr2 = re.compile(r"/(?P<root>[a-z3]{3,16}[0-9]{2,3}[a-z]{1}" r"_\w{1,16})" r"(?P<ext>\.(comm|py))$") _expr3 = re.compile(r"/(?P<root>xx\w+)" - r"(?P<ext>\.(export|py))$") + r"(?P<ext>(|\.(" + "|".join(REG_EXT) + ")))$") _expr4 = re.compile(r"/(?P<root>[0-9]+)" r"(?P<ext>\.med)$") found = (_expr1.findall(txt) or @@ -207,6 +213,8 @@ class DatafileTooBig(FilenameCat, GenericMsg): def search(self, txt): """Check size of files""" + if not osp.isfile(txt): + return [] check_asrun() from asrun.profil import AsterProfil if osp.basename(txt) in ['perf011a.export', 'perf011b.export']: @@ -370,6 +378,8 @@ class ResourcesTooBig(FilenameCat, GenericMsg): def search(self, txt): """Check a .export""" + if not osp.isfile(txt): + return [] check_asrun() from asrun.profil import AsterProfil pexp = AsterProfil(txt) @@ -537,6 +547,8 @@ class RequiredKeyword(FileContentCat, GenericMsg): elif self._pours.search(txt): if not self._poucod.search(txt): err.append(": %s not found in POURSUITE" % self._pouerr) + elif "asterxx" in self.ctxt.branch: + pass else: err.append(": neither DEBUT or POURSUITE found") return err