# SPDX-FileCopyrightText: Huawei Inc. # # SPDX-License-Identifier: Apache-2.0 # # Utils functions for upgrade_oniro.py def get_manifest_projects(): """ Create a list of dict containing all the properties of the projects in Oniro's manifest. Returns: A new list of dict with all the projects' properties. """ import xml.etree.ElementTree as ET tree = ET.parse("oniro/manifests/default.xml") root = tree.getroot() return [project.attrib for project in root.findall("project")] def find_latest_backup(): """ Find the latest backup of Oniro. This will search only in the current directory. Returns: The latest backup name if found, None otherwise. """ from pathlib import Path this_dir = Path(".") backup_info_list = [] for item in this_dir.iterdir(): if "upgrade_oniro_backup" in item.name: backup_info = { "name": item.name, "timestamp": item.name.split("-")[1].split(".")[:2] } print(backup_info) backup_info_list.append(backup_info) return max(backup_info_list, key=lambda x: int(f'{x["timestamp"][0]}{x["timestamp"][1]}'))["name"]