Tools: generate_manifest.py: make flake8 clean

This commit is contained in:
Peter Barker 2022-09-07 13:51:10 +10:00 committed by Peter Barker
parent 4008df1314
commit 3f5cde4bb1

View File

@ -1,6 +1,9 @@
#!/usr/bin/env python
import copy
'''
AP_FLAKE8_CLEAN
'''
import fnmatch
import gen_stable
import gzip
@ -107,10 +110,11 @@ brand_map = {
"MicoAir743" : ("MicoAir H743 v1.3", "MicoAir"),
"MicoAir743-AIO" : ("MicoAir H743 AIO", "MicoAir"),
"MicoAir743v2" : ("MicoAir H743 v2.0", "MicoAir"),
"GEPRCF745BTHD": ("TAKER F745 BT","GEPRC"),
"GEPRC_TAKER_H743": ("TAKER H743 BT","GEPRC"),
"GEPRCF745BTHD": ("TAKER F745 BT", "GEPRC"),
"GEPRC_TAKER_H743": ("TAKER H743 BT", "GEPRC"),
}
class Firmware():
def __init__(self,
date=None,
@ -198,13 +202,13 @@ class ManifestGenerator():
'''parses get-version.txt (as emitted by build_binaries.py, returns
git sha from it'''
content = open(filepath).read()
sha_regex = re.compile("APMVERSION: \S+\s+(\S+)")
sha_regex = re.compile(r"APMVERSION: \S+\s+(\S+)")
m = sha_regex.search(content)
if m is None:
raise Exception(
"filepath (%s) does not contain an APMVERSION" % (filepath,))
return m.group(1)
def add_USB_IDs_PX4(self, firmware):
'''add USB IDs to a .px4 firmware'''
url = firmware['url']
@ -306,14 +310,14 @@ class ManifestGenerator():
# special case for 6C, they always get the px4 bootloader IDs as an option
firmware['bootloader_str'].append('PX4 BL FMU v6C.x')
firmware['USBID'].append('0x3185/0x0038')
if platform in brand_map:
(brand_name, manufacturer) = brand_map[platform]
firmware['brand_name'] = brand_name
firmware['manufacturer'] = manufacturer
# copy over some extra information if available
extra_tags = [ 'image_size', 'brand_name', 'manufacturer' ]
extra_tags = ['image_size', 'brand_name', 'manufacturer']
for tag in extra_tags:
if tag in apj_json:
firmware[tag] = apj_json[tag]
@ -349,7 +353,7 @@ class ManifestGenerator():
vehicletype,
releasetype="dev"):
'''accumulate additional information about firmwares from directory'''
variant_firmware_regex = re.compile("[^-]+-(?P<variant>v\d+)[.px4]")
variant_firmware_regex = re.compile(r"[^-]+-(?P<variant>v\d+)[.px4]")
if not os.path.isdir(dir):
return
try:
@ -393,7 +397,7 @@ class ManifestGenerator():
except ValueError:
print("malformed firmware-version.txt at (%s)" % (firmware_version_file,), file=sys.stderr)
continue
except Exception as ex:
except Exception:
print("bad file %s" % firmware_version_file, file=sys.stderr)
# this exception is swallowed.... the current archive
# is incomplete.
@ -436,7 +440,7 @@ class ManifestGenerator():
filepath = os.path.join(some_dir, filename)
firmware_format = self.firmware_format_for_filepath(filepath)
if firmware_format not in [ "elf", "ELF", "abin", "apj", "hex", "px4", "bin" ]:
if firmware_format not in ["elf", "ELF", "abin", "apj", "hex", "px4", "bin"]:
print("Unknown firmware format (%s)" % firmware_format)
firmware = Firmware()
@ -488,7 +492,7 @@ class ManifestGenerator():
def walk_directory(self, basedir):
'''walks directory structure created by build_binaries, returns Python
structure representing releases in that structure'''
year_month_regex = re.compile("(?P<year>\d{4})-(?P<month>\d{2})")
year_month_regex = re.compile(r"(?P<year>\d{4})-(?P<month>\d{2})")
firmwares = []
@ -568,7 +572,6 @@ class ManifestGenerator():
self.add_USB_IDs(some_json)
#print(some_json['url'])
firmware_json.append(some_json)
# now the features the firmware supports...
@ -576,8 +579,8 @@ class ManifestGenerator():
features = firmware["features"]
# check apj here in case we're creating bin and apj etc:
if (firmware["format"] == "apj" and
features is not None and
bool(firmware["latest"])):
features is not None and
bool(firmware["latest"])):
x = dict({
"vehicletype": firmware["vehicletype"],
"platform": firmware["platform"],
@ -649,6 +652,7 @@ class ManifestGenerator():
'''write generated features JSON content to path'''
self.write_json(self.json_features(), path)
def usage():
return '''Usage:
generate-manifest.py basedir'''