Combine author_tag and log_translation_hint regexes
author_tag_re and log_translation_hints were lists of regexes, where each member was then separately matched against each input line. This change combines each of these lists into an a|b regex and removes the unnecessary loop. Change-Id: I8db76862d3f7ef030e31e2e1e6f2fcd8dbd00888
This commit is contained in:
parent
2b378162f3
commit
a7a9c74c80
|
@ -28,9 +28,8 @@ import pep8
|
|||
# - Add test cases for each new rule to
|
||||
# neutron/tests/unit/test_hacking.py
|
||||
|
||||
author_tag_re = (re.compile("^\s*#\s*@?(a|A)uthor"),
|
||||
re.compile("^\.\.\s+moduleauthor::"))
|
||||
_all_hints = set(['_', '_LI', '_LE', '_LW', '_LC'])
|
||||
author_tag_re = re.compile(r"^\s*#\s*@?[aA]uthor|^\.\.\s+moduleauthor::")
|
||||
|
||||
_all_log_levels = {
|
||||
# NOTE(yamamoto): Following nova which uses _() for audit.
|
||||
'audit': '_',
|
||||
|
@ -41,13 +40,19 @@ _all_log_levels = {
|
|||
'critical': '_LC',
|
||||
'exception': '_LE',
|
||||
}
|
||||
log_translation_hints = []
|
||||
for level, hint in _all_log_levels.iteritems():
|
||||
r = "(.)*LOG\.%(level)s\(\s*((%(wrong_hints)s)\(|'|\")" % {
|
||||
_all_hints = set(_all_log_levels.values())
|
||||
|
||||
|
||||
def _regex_for_level(level, hint):
|
||||
return r".*LOG\.%(level)s\(\s*((%(wrong_hints)s)\(|'|\")" % {
|
||||
'level': level,
|
||||
'wrong_hints': '|'.join(_all_hints - set([hint])),
|
||||
}
|
||||
log_translation_hints.append(re.compile(r))
|
||||
|
||||
|
||||
log_translation_hint = re.compile(
|
||||
'|'.join('(?:%s)' % _regex_for_level(level, hint)
|
||||
for level, hint in _all_log_levels.iteritems()))
|
||||
|
||||
|
||||
def validate_log_translations(logical_line, physical_line, filename):
|
||||
|
@ -58,9 +63,8 @@ def validate_log_translations(logical_line, physical_line, filename):
|
|||
return
|
||||
|
||||
msg = "N320: Log messages require translation hints!"
|
||||
for log_translation_hint in log_translation_hints:
|
||||
if log_translation_hint.match(logical_line):
|
||||
yield (0, msg)
|
||||
if log_translation_hint.match(logical_line):
|
||||
yield (0, msg)
|
||||
|
||||
|
||||
def use_jsonutils(logical_line, filename):
|
||||
|
@ -85,13 +89,12 @@ def use_jsonutils(logical_line, filename):
|
|||
|
||||
|
||||
def no_author_tags(physical_line):
|
||||
for regex in author_tag_re:
|
||||
if regex.match(physical_line):
|
||||
physical_line = physical_line.lower()
|
||||
pos = physical_line.find('moduleauthor')
|
||||
if pos < 0:
|
||||
pos = physical_line.find('author')
|
||||
return pos, "N322: Don't use author tags"
|
||||
if author_tag_re.match(physical_line):
|
||||
physical_line = physical_line.lower()
|
||||
pos = physical_line.find('moduleauthor')
|
||||
if pos < 0:
|
||||
pos = physical_line.find('author')
|
||||
return pos, "N322: Don't use author tags"
|
||||
|
||||
|
||||
def no_translate_debug_logs(logical_line, filename):
|
||||
|
|
Loading…
Reference in New Issue