def test_load(self): self.maxDiff = None data = { "branch": "stable", "date": "2020-05-04 22:25:45+02:00", "priority": "1", "body": """8devices-carambola2-board 2020.1.2-242-testing c8a7d3db620e91ad4d935bfc3df59f1a60bb3a2f11aa19a24b2f3d965cb88d06 4259844 gluon-ffsh-2020.1.2-242-testing-8devices-carambola2-board-sysupgrade.bin 8devices-carambola2-board 2020.1.2-242-testing c8a7d3db620e91ad4d935bfc3df59f1a60bb3a2f11aa19a24b2f3d965cb88d06 gluon-ffsh-2020.1.2-242-testing-8devices-carambola2-board-sysupgrade.bin 8devices-carambola2-board 2020.1.2-242-testing cffca7ec6dee0f4e1cb95fe79275a34cf791b92f76ba74e4d3e74c113e7eed40e5ae576c7f8da1e9cdc4dec71f14f8457111870647aafc5f41b048749d34b671 gluon-ffsh-2020.1.2-242-testing-8devices-carambola2-board-sysupgrade.bin alfa-network-ap121f 2020.1.2-242-testing a21015a1cc0c46201e09fcdb87a9b03d9ecd0169ff1f8cab97a7e8b39767b87e 4326145 gluon-ffsh-2020.1.2-242-testing-alfa-network-ap121f-sysupgrade.bin""", "signature": "4b93f300b95e89342b2d49dc5fe4fbf1d89028ad48e00a09ecc2af86beb6380fea1cd8aa9f9f05a740dfa18589e7223a138920b7eb0639914b473cf4f37e7b04" } manifest = Manifest(data["branch"], data["date"], data["priority"], data["body"], data["signature"]) manifest.export("stable.manifest") with open("stable.manifest", "r") as manifest_file: self.assertTrue(manifest_file.readlines()) manifest2 = Manifest() manifest2.load("stable.manifest") manifest2.export("stable2.manifest") self.assertEqual(manifest2.branch, data["branch"]) self.assertEqual(manifest2.date, data["date"]) self.assertEqual(manifest2.priority, data["priority"]) self.assertEqual(manifest2.body, data["body"]) self.assertEqual(manifest2.signature, data["signature"])
def manifest(self, version, branch): version_pattern = re.compile(r'(\d{4}.\d.\d).(\d)') if version_pattern.match(version) and branch is not None: manifest = Manifest() manifest_path = Path(self.config["firmware_path"] ) / version / "sysupgrade" / "stable.manifest" manifest.load(manifest_path) manifest.set_branch(branch) manifest.export(manifest_path.parent / "{}.{}".format(branch, "manifest"))
def save(self, artifact_file): filename = Path(artifact_file).name filename_parsed = re.match(r'(\d{4}.\d.\d).(\d)_(.*)+_(\w+).zip', filename) release_name = "{}.{}".format(filename_parsed.group(1), filename_parsed.group(2)) release_dir = self.storage_path / (release_name) if not release_dir.exists(): release_dir.mkdir() with zipfile.ZipFile(artifact_file, 'r') as zip_ref: for file in zip_ref.infolist(): if file.filename.endswith("stable.manifest"): file.filename = Path(file.filename).name manifest_path = release_dir / "sysupgrade" / "stable.manifest" if manifest_path.exists(): zip_ref.extract(file, "/tmp") manifest = Manifest() manifest.load(manifest_path) manifest_part = Manifest() manifest_part.load(Path("/tmp") / "stable.manifest") manifest.merge(manifest_part) manifest.export(manifest_path) else: zip_ref.extract(file, manifest_path.parent) if file.filename.startswith('images/factory/'): file.filename = Path(file.filename).name if file.filename != "factory": zip_ref.extract(file, release_dir / "factory") elif file.filename.startswith('images/sysupgrade/'): file.filename = Path(file.filename).name if file.filename != "sysupgrade": zip_ref.extract(file, release_dir / "sysupgrade") elif file.filename.startswith('images/other/'): file.filename = Path(file.filename).name if file.filename != "other": zip_ref.extract(file, release_dir / "other")