1
0
Fork 0
mirror of https://github.com/YunoHost/apps.git synced 2024-09-03 20:06:07 +02:00

save_added_date: use get_apps_repo

This commit is contained in:
Félix Piédallu 2024-08-13 09:11:50 +02:00 committed by Félix Piédallu
parent 597bd6c390
commit 03a160b7bf

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse
import tomlkit import tomlkit
import json import json
from datetime import datetime from datetime import datetime
@ -7,6 +8,7 @@ from git import Repo, Commit
from pathlib import Path from pathlib import Path
import logging import logging
from typing import TYPE_CHECKING, Callable from typing import TYPE_CHECKING, Callable
import appslib.get_apps_repo as get_apps_repo
if TYPE_CHECKING: if TYPE_CHECKING:
REPO_APPS_ROOT = Path() REPO_APPS_ROOT = Path()
@ -14,9 +16,7 @@ else:
from appslib.utils import REPO_APPS_ROOT from appslib.utils import REPO_APPS_ROOT
def git_bisect(repo_path: Path, is_newer: Callable[[Commit], bool]) -> Commit | None: def git_bisect(repo: Repo, is_newer: Callable[[Commit], bool]) -> Commit | None:
repo = Repo(repo_path)
# Start with whole repo # Start with whole repo
first_commit = repo.git.rev_list("HEAD", reverse=True, max_parents=0) first_commit = repo.git.rev_list("HEAD", reverse=True, max_parents=0)
repo.git.bisect("reset") repo.git.bisect("reset")
@ -69,19 +69,19 @@ def app_is_deprecated(commit: Commit, name: str) -> bool:
return "deprecated-software" in antifeatures return "deprecated-software" in antifeatures
def date_added(name: str) -> int | None: def date_added(repo: Repo, name: str) -> int | None:
result = git_bisect(REPO_APPS_ROOT, lambda x: app_is_present(x, name)) result = git_bisect(repo, lambda x: app_is_present(x, name))
print(result) print(result)
return None if result is None else result.committed_date return None if result is None else result.committed_date
def date_deprecated(name: str) -> int | None: def date_deprecated(repo: Repo, name: str) -> int | None:
result = git_bisect(REPO_APPS_ROOT, lambda x: app_is_deprecated(x, name)) result = git_bisect(repo, lambda x: app_is_deprecated(x, name))
print(result) print(result)
return None if result is None else result.committed_date return None if result is None else result.committed_date
def add_deprecation_dates(file: Path) -> None: def add_deprecation_dates(repo: Repo, file: Path) -> None:
key = "deprecated_date" key = "deprecated_date"
document = tomlkit.load(file.open("r", encoding="utf-8")) document = tomlkit.load(file.open("r", encoding="utf-8"))
for app, info in document.items(): for app, info in document.items():
@ -89,7 +89,7 @@ def add_deprecation_dates(file: Path) -> None:
continue continue
if "deprecated-software" not in info.get("antifeatures", []): if "deprecated-software" not in info.get("antifeatures", []):
continue continue
date = date_deprecated(app) date = date_deprecated(repo, app)
if date is None: if date is None:
continue continue
info[key] = date info[key] = date
@ -98,10 +98,9 @@ def add_deprecation_dates(file: Path) -> None:
tomlkit.dump(document, file.open("w")) tomlkit.dump(document, file.open("w"))
def date_added_to(match: str, file: Path) -> int | None: def date_added_to(repo: Repo, match: str, file: Path) -> int | None:
commits = ( commits = (
Repo(REPO_APPS_ROOT) repo.git.log(
.git.log(
"-S", "-S",
match, match,
"--first-parent", "--first-parent",
@ -120,12 +119,12 @@ def date_added_to(match: str, file: Path) -> int | None:
return int(first_commit) return int(first_commit)
def add_apparition_dates(file: Path, key: str) -> None: def add_apparition_dates(repo: Repo, file: Path, key: str) -> None:
document = tomlkit.load(file.open("r", encoding="utf-8")) document = tomlkit.load(file.open("r", encoding="utf-8"))
for app, info in document.items(): for app, info in document.items():
if key in info.keys(): if key in info.keys():
continue continue
date = date_added_to(f"[{app}]", file) date = date_added_to(repo, f"[{app}]", file)
assert date is not None assert date is not None
info[key] = date info[key] = date
info[key].comment(datetime.fromtimestamp(info[key]).strftime("%Y/%m/%d")) info[key].comment(datetime.fromtimestamp(info[key]).strftime("%Y/%m/%d"))
@ -134,14 +133,21 @@ def add_apparition_dates(file: Path, key: str) -> None:
def main() -> None: def main() -> None:
parser = argparse.ArgumentParser()
get_apps_repo.add_args(parser, allow_temp=False)
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
add_apparition_dates(REPO_APPS_ROOT / "apps.toml", key="added_date") apps_repo_dir = get_apps_repo.from_args(args)
add_apparition_dates(REPO_APPS_ROOT / "wishlist.toml", key="added_date") apps_repo = Repo(apps_repo_dir)
add_apparition_dates(REPO_APPS_ROOT / "graveyard.toml", key="killed_date")
add_deprecation_dates(REPO_APPS_ROOT / "apps.toml") add_apparition_dates(apps_repo, apps_repo_dir / "apps.toml", key="added_date")
add_deprecation_dates(REPO_APPS_ROOT / "graveyard.toml") add_apparition_dates(apps_repo, apps_repo_dir / "wishlist.toml", key="added_date")
add_apparition_dates(apps_repo, apps_repo_dir / "graveyard.toml", key="killed_date")
add_deprecation_dates(apps_repo, apps_repo_dir / "apps.toml")
add_deprecation_dates(apps_repo, apps_repo_dir / "graveyard.toml")
if __name__ == "__main__": if __name__ == "__main__":