From e89e6ca32ec07079f8d68d00b42f46e3e9493830 Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 4 Dec 2018 17:19:51 +0100 Subject: [PATCH] build: add script for fetching required release versions --- helper-scripts/bump-required-fw-versions.py | 57 +++++++++++++++++++++ trezorlib/__init__.py | 4 +- 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100755 helper-scripts/bump-required-fw-versions.py diff --git a/helper-scripts/bump-required-fw-versions.py b/helper-scripts/bump-required-fw-versions.py new file mode 100755 index 000000000..f968f1a53 --- /dev/null +++ b/helper-scripts/bump-required-fw-versions.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +import os +import requests + +RELEASES_URL = "https://beta-wallet.trezor.io/data/firmware/{}/releases.json" +MODELS = ("1", "T") + +FILENAME = os.path.join(os.path.dirname(__file__), "..", "trezorlib", "__init__.py") +START_LINE = "MINIMUM_FIRMWARE_VERSION = {\n" +END_LINE = "}\n" + + +def version_str(vtuple): + return ".".join(map(str, vtuple)) + + +def fetch_releases(model): + version = model + if model == "T": + version = "2" + + url = RELEASES_URL.format(version) + releases = requests.get(url).json() + releases.sort(key=lambda r: r["version"], reverse=True) + return releases + + +def find_latest_required(model): + releases = fetch_releases(model) + return next(r for r in releases if r["required"]) + + +with open(FILENAME, "r+") as f: + output = [] + line = None + # copy up to & incl START_LINE + while line != START_LINE: + line = next(f) + output.append(line) + # throw away until END_LINE + while line != END_LINE: + line = next(f) + # append models + for model in MODELS: + rel = find_latest_required(model) + version_tuple = tuple(rel["version"]) + line = f' "{model}": {version_tuple!r},\n' + output.append(line) + output.append(END_LINE) + # finish reading file + for line in f: + output.append(line) + + f.seek(0) + f.truncate(0) + for line in output: + f.write(line) diff --git a/trezorlib/__init__.py b/trezorlib/__init__.py index 3cf120afa..2fe5fe7fc 100644 --- a/trezorlib/__init__.py +++ b/trezorlib/__init__.py @@ -2,7 +2,7 @@ __version__ = "0.11.0" # fmt: off MINIMUM_FIRMWARE_VERSION = { - "1": (1, 6, 3), - "T": (2, 0, 10), + "1": (1, 6, 1), + "T": (2, 0, 5), } # fmt: on