From 1c772b94cde50614e1ccd937d0cbfd32910a19f2 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 20 Jul 2020 12:54:19 +1000 Subject: [PATCH] Tools: build-binaries and generate-manifest py3 fixes --- Tools/scripts/build_binaries.py | 10 ++++++++++ Tools/scripts/generate_manifest.py | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Tools/scripts/build_binaries.py b/Tools/scripts/build_binaries.py index 99a2f9cefa..66a81f43dd 100755 --- a/Tools/scripts/build_binaries.py +++ b/Tools/scripts/build_binaries.py @@ -22,6 +22,12 @@ import gzip import generate_manifest, gen_stable import build_binaries_history +if sys.version_info[0] < 3: + running_python3 = False +else: + running_python3 = True + + class build_binaries(object): def __init__(self, tags): self.tags = tags @@ -77,6 +83,8 @@ class build_binaries(object): # select not available on Windows... probably... time.sleep(0.1) continue + if running_python3: + x = x.decode('ascii') output += x x = x.rstrip() if show_output: @@ -702,6 +710,8 @@ is bob we will attempt to checkout bob-AVR''' new_json_filepath_gz = os.path.join(self.binaries, "manifest.json.gz.new") with gzip.open(new_json_filepath_gz, 'wb') as gf: + if running_python3: + content = bytes(content, 'ascii') gf.write(content) json_filepath = os.path.join(self.binaries, "manifest.json") json_filepath_gz = os.path.join(self.binaries, "manifest.json.gz") diff --git a/Tools/scripts/generate_manifest.py b/Tools/scripts/generate_manifest.py index 2f957c14ad..4c04af4111 100755 --- a/Tools/scripts/generate_manifest.py +++ b/Tools/scripts/generate_manifest.py @@ -10,6 +10,11 @@ import fnmatch import gen_stable import subprocess +if sys.version_info[0] < 3: + running_python3 = False +else: + running_python3 = True + FIRMWARE_TYPES = ["AntennaTracker", "Copter", "Plane", "Rover", "Sub", "AP_Periph"] RELEASE_TYPES = ["beta", "latest", "stable", "stable-*", "dirty"] @@ -251,6 +256,9 @@ class ManifestGenerator(): return "".join(filename.split(".")[-1:]) # no extension; ensure this is an elf: text = subprocess.check_output(["file", "-b", filepath]) + if running_python3: + text = text.decode('ascii') + if re.match("^ELF", text): return "ELF" print("Unknown file type (%s)" % filepath) @@ -507,5 +515,8 @@ if __name__ == "__main__": print(generator.json()) else: f = open(args.outfile, "w") - f.write(generator.json()) + content = generator.json() + if running_python3: + content = bytes(content, 'ascii') + f.write(content) f.close()