diff --git a/Tools/autotest/logger_metadata/enum_parse.py b/Tools/autotest/logger_metadata/enum_parse.py index 99227a211e..93a713cf3a 100755 --- a/Tools/autotest/logger_metadata/enum_parse.py +++ b/Tools/autotest/logger_metadata/enum_parse.py @@ -1,5 +1,9 @@ #!/usr/bin/env python +''' +AP_FLAKE8_CLEAN +''' + from __future__ import print_function import argparse @@ -10,6 +14,7 @@ import sys topdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../') topdir = os.path.realpath(topdir) + class EnumDocco(object): vehicle_map = { @@ -35,35 +40,35 @@ class EnumDocco(object): # attempts to extract name, value and comment from line. # Match: " FRED, // optional comment" - m = re.match("\s*([A-Z0-9_a-z]+)\s*,? *(?://[/>]* *(.*) *)?$", line) + m = re.match(r"\s*([A-Z0-9_a-z]+)\s*,? *(?://[/>]* *(.*) *)?$", line) if m is not None: return (m.group(1), None, m.group(2)) # Match: " FRED, /* optional comment */" - m = re.match("\s*([A-Z0-9_a-z]+)\s*,? *(?:/[*] *(.*) *[*]/ *)?$", line) + m = re.match(r"\s*([A-Z0-9_a-z]+)\s*,? *(?:/[*] *(.*) *[*]/ *)?$", line) if m is not None: return (m.group(1), None, m.group(2)) # Match: " FRED = 17, // optional comment" - m = re.match("\s*([A-Z0-9_a-z]+)\s*=\s*([-0-9]+)\s*,?(?:\s*//[/<]*\s*(.*) *)?$", + m = re.match(r"\s*([A-Z0-9_a-z]+)\s*=\s*([-0-9]+)\s*,?(?:\s*//[/<]*\s*(.*) *)?$", line) if m is not None: return (m.group(1), m.group(2), m.group(3)) # Match: " FRED = 17, // optional comment" - m = re.match("\s*([A-Z0-9_a-z]+) *= *([-0-9]+) *,?(?: */* *(.*) *)? *[*]/ *$", + m = re.match(r"\s*([A-Z0-9_a-z]+) *= *([-0-9]+) *,?(?: */* *(.*) *)? *[*]/ *$", line) if m is not None: return (m.group(1), m.group(2), m.group(3)) # Match: " FRED = 1U<<0, // optional comment" - m = re.match("\s*([A-Z0-9_a-z]+) *= *[(]?1U? *[<][<] *(\d+)(?:, *// *(.*) *)?", + m = re.match(r"\s*([A-Z0-9_a-z]+) *= *[(]?1U? *[<][<] *(\d+)(?:, *// *(.*) *)?", line) if m is not None: return (m.group(1), 1 << int(m.group(2)), m.group(3)) # Match: " FRED = 0xabc, // optional comment" - m = re.match("\s*([A-Z0-9_a-z]+) *= *(?:0[xX]([0-9A-Fa-f]+))(?:, *// *(.*) *)?", + m = re.match(r"\s*([A-Z0-9_a-z]+) *= *(?:0[xX]([0-9A-Fa-f]+))(?:, *// *(.*) *)?", line) if m is not None: return (m.group(1), int(m.group(2), 16), m.group(3)) @@ -71,19 +76,18 @@ class EnumDocco(object): '''start discarded matches - lines we understand but can't do anything with:''' # Match: " FRED = 17, // optional comment" - m = re.match("\s*([A-Z0-9_a-z]+) *= *(\w+) *,?(?: *// *(.*) *)?$", + m = re.match(r"\s*([A-Z0-9_a-z]+) *= *(\w+) *,?(?: *// *(.*) *)?$", line) if m is not None: return (None, None, None) # Match: " FRED = FOO(17), // optional comment" - m = re.match("\s*([A-Z0-9_a-z]+) *= *(\w+) *\\( *(\w+) *\\) *,?(?: *// *(.*) *)?$", + m = re.match(r"\s*([A-Z0-9_a-z]+) *= *(\w+) *\\( *(\w+) *\\) *,?(?: *// *(.*) *)?$", line) if m is not None: return (None, None, None) - - # Match: " FRED = 1U<<0, // optional comment" - m = re.match("\s*([A-Z0-9_a-z]+) *= *[(]?3U? *[<][<] *(\d+)(?:, *// *(.*) *)?", + # Match: " FRED = 1U<<0, // optional comment" + m = re.match(r"\s*([A-Z0-9_a-z]+) *= *[(]?3U? *[<][<] *(\d+)(?:, *// *(.*) *)?", line) if m is not None: return (m.group(1), 1 << int(m.group(2)), m.group(3)) @@ -112,21 +116,21 @@ class EnumDocco(object): break line = line.rstrip() # print("state=%s line: %s" % (state, line)) - if re.match("\s*//.*", line): + if re.match(r"\s*//.*", line): continue if state == "outside": if re.match("class .*;", line) is not None: # forward-declaration of a class continue - m = re.match("class *([:\w]+)", line) + m = re.match(r"class *([:\w]+)", line) if m is not None: in_class = m.group(1) continue - m = re.match("namespace *(\w+)", line) + m = re.match(r"namespace *(\w+)", line) if m is not None: in_class = m.group(1) continue - m = re.match(".*enum\s*(class)? *([\w]+)\s*(?::.*_t)? *{(.*)};", line) + m = re.match(r".*enum\s*(class)? *([\w]+)\s*(?::.*_t)? *{(.*)};", line) if m is not None: # all one one line! Thanks! enum_name = m.group(2) @@ -142,7 +146,7 @@ class EnumDocco(object): enumerations.append(new_enumeration) continue - m = re.match(".*enum\s*(class)? *([\w]+)\s*(?::.*_t)? *{", line) + m = re.match(r".*enum\s*(class)? *([\w]+)\s*(?::.*_t)? *{", line) if m is not None: enum_name = m.group(2) debug("%s: %s" % (source_file, enum_name)) @@ -152,15 +156,15 @@ class EnumDocco(object): skip_enumeration = False continue if state == "inside": - if re.match("\s*$", line): + if re.match(r"\s*$", line): continue - if re.match("#if", line): + if re.match(r"#if", line): continue - if re.match("#endif", line): + if re.match(r"#endif", line): continue - if re.match("#else", line): + if re.match(r"#else", line): continue - if re.match(".*}\s*\w*(\s*=\s*[\w:]+)?;", line): + if re.match(r".*}\s*\w*(\s*=\s*[\w:]+)?;", line): # potential end of enumeration if not skip_enumeration: if enum_name is None: @@ -189,7 +193,7 @@ class EnumDocco(object): else: value = int(value) last_value = value -# print("entry=%s value=%s comment=%s" % (name, value, comment)) + # print("entry=%s value=%s comment=%s" % (name, value, comment)) entries.append(EnumDocco.EnumEntry(name, value, comment)) return enumerations @@ -253,4 +257,3 @@ if __name__ == '__main__': sys.exit(1) s.run() -# print("Enumerations: %s" % s.enumerations) diff --git a/Tools/autotest/logger_metadata/parse.py b/Tools/autotest/logger_metadata/parse.py index 2f7517d218..20bac7be3c 100755 --- a/Tools/autotest/logger_metadata/parse.py +++ b/Tools/autotest/logger_metadata/parse.py @@ -1,5 +1,9 @@ #!/usr/bin/env python +''' +AP_FLAKE8_CLEAN +''' + from __future__ import print_function import argparse @@ -33,7 +37,11 @@ re_vehicles = re.compile(r"\s*//\s*@Vehicles\s*:\s*(.*)") # Regular expressions for finding message definitions in structure format re_start_messagedef = re.compile(r"^\s*{?\s*LOG_[A-Z0-9_]+_[MSGTA]+[A-Z0-9_]*\s*,") re_deffield = r'[\s\\]*"?([\w\-#?%]+)"?\s*' -re_full_messagedef = re.compile(r'\s*LOG_\w+\s*,\s*\w+\([^)]+\)[\s\\]*,' + f'{re_deffield},{re_deffield},' + r'[\s\\]*"?([\w,]+)"?[\s\\]*,' + f'{re_deffield},{re_deffield}' , re.MULTILINE) +re_full_messagedef = re.compile(r'\s*LOG_\w+\s*,\s*\w+\([^)]+\)[\s\\]*,' + + f'{re_deffield},{re_deffield},' + + r'[\s\\]*"?([\w,]+)"?[\s\\]*,' + + f'{re_deffield},{re_deffield}', + re.MULTILINE) re_fmt_define = re.compile(r'#define\s+(\w+_FMT)\s+"([\w\-#?%]+)"') re_units_define = re.compile(r'#define\s+(\w+_UNITS)\s+"([\w\-#?%]+)"') re_mults_define = re.compile(r'#define\s+(\w+_MULTS)\s+"([\w\-#?%]+)"') @@ -41,7 +49,9 @@ re_mults_define = re.compile(r'#define\s+(\w+_MULTS)\s+"([\w\-#?%]+)"') # Regular expressions for finding message definitions in Write calls re_start_writecall = re.compile(r"\s*[AP:]*logger[\(\)]*.Write[StreamingCrcl]*\(") re_writefield = r'\s*"([\w\-#?%,]+)"\s*' -re_full_writecall = re.compile(r'\s*[AP:]*logger[\(\)]*.Write[StreamingCrcl]*\(' + f'{re_writefield},{re_writefield},{re_writefield},({re_writefield},{re_writefield})?' , re.MULTILINE) +re_full_writecall = re.compile(r'\s*[AP:]*logger[\(\)]*.Write[StreamingCrcl]*\(' + + f'{re_writefield},{re_writefield},{re_writefield},({re_writefield},{re_writefield})?', + re.MULTILINE) # Regular expression for extracting unit and multipliers from structure re_units_mults_struct = re.compile(r"^\s*{\s*'([\w\-#?%!/])',"+r'\s*"?([\w\-#?%./]*)"?\s*}') @@ -64,6 +74,7 @@ mult_prefix_lookup = { 1e-9: "n" # nano- } + class LoggerDocco(object): vehicle_map = { @@ -93,7 +104,7 @@ class LoggerDocco(object): def __init__(self, name): self.name = name self.url = None - if isinstance(name,list): + if isinstance(name, list): self.description = [None] * len(name) else: self.description = None @@ -104,15 +115,15 @@ class LoggerDocco(object): def add_name(self, name): # If self.name/description aren't lists, convert them - if isinstance(self.name,str): + if isinstance(self.name, str): self.name = [self.name] self.description = [self.description] # Replace any existing empty descriptions with empty strings - for i in range(0,len(self.description)): + for i in range(0, len(self.description)): if self.description[i] is None: self.description[i] = "" # Extend the name and description lists - if isinstance(name,list): + if isinstance(name, list): self.name.extend(name) self.description.extend([None] * len(name)) else: @@ -120,8 +131,8 @@ class LoggerDocco(object): self.description.append(None) def set_description(self, desc): - if isinstance(self.description,list): - for i in range(0,len(self.description)): + if isinstance(self.description, list): + for i in range(0, len(self.description)): if self.description[i] is None: self.description[i] = desc else: @@ -147,7 +158,7 @@ class LoggerDocco(object): count = 0 entries = [] for bit in bits: - entries.append(EnumDocco.EnumEntry(bit, 1<