diff --git a/scripts/upgrade_oniro/upgrade_oniro_utils.py b/scripts/upgrade_oniro/upgrade_oniro_utils.py index d3ecb7c95fbf2f9270dfb5af1fcb65bc395a062f..c25fc111b3e742d72b5570341b15e176602a9d80 100644 --- a/scripts/upgrade_oniro/upgrade_oniro_utils.py +++ b/scripts/upgrade_oniro/upgrade_oniro_utils.py @@ -11,10 +11,34 @@ def get_manifest_projects(): projects in Oniro's manifest. Returns: - A new list of dict with all the projects' properties + 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"]