4 from pathlib import Path
5 from typing import List
6 from git import Repo # type: ignore
7 from debian.changelog import Version
9 LOG_FORMAT = "%(levelname)s %(message)s"
10 log = logging.getLogger()
12 UDFS_DIR = Path("wiki/src/upgrade/v2/Tails")
15 def dirs_to_delete(before_version: str, tags: List[str]) -> list:
19 child for child in UDFS_DIR.iterdir() if child.is_dir()
21 version = version_dir.name
22 tag = version.replace('~', '-')
23 log.debug("Looking at %s (version = %s, tag = %s)",
24 version_dir, version, tag)
26 # Skip all the UDFs we have reasons to keep
27 if Version(version) >= Version(before_version):
28 log.debug("Version %s newer than %s, skipping",
29 version, before_version)
32 log.debug("Version %s was already released, skipping", version)
35 log.debug("Version %s is needed for QA/CI, skipping", version)
38 # Flag what's left for deletion
39 log.info("Flagging UDFs for version %s for deletion", version)
40 to_delete.append(str(version_dir))
45 if __name__ == '__main__':
47 parser = argparse.ArgumentParser()
48 parser.add_argument("--before-version", required=True)
49 parser.add_argument("--debug", action="store_true", help="debug output")
50 args = parser.parse_args()
53 logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
55 logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
57 repo = Repo(Path.cwd())
60 log.debug("Tags:\n%s", tags)
62 to_delete = dirs_to_delete(args.before_version, tags)
64 log.info("Deleting %s", to_delete)
65 repo.git.rm('-r', to_delete)
66 repo.index.commit("Remove UDFs for versions we'll never release")
68 log.info("Nothing to delete")