mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-27 11:58:53 -06:00
refactor: move recipes and acquisition to packages
This commit is contained in:
1 parent
664776ae91
commit
0e4e5f450d
35 files changed
+2186
-2071
No files matched your search
@@ -15,57 +15,12 @@ each until one matches.
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import sys
|
||||
import urllib.parse
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from core import upstream
|
||||
|
||||
# Commits listed per page and the most pages walked: a data file older than
|
||||
# 2 000 commits on its own path is not one a platform list still pins.
|
||||
PER_PAGE = 100
|
||||
MAX_PAGES = 20
|
||||
|
||||
|
||||
def _history_url(repo: upstream.Repo, path: str, page: int) -> str:
|
||||
quoted = urllib.parse.quote(path)
|
||||
if repo.family == "gitlab":
|
||||
project = urllib.parse.quote(repo.slug, safe="")
|
||||
return (f"{repo.api_base}/projects/{project}/repository/commits"
|
||||
f"?path={quoted}&per_page={PER_PAGE}&page={page}")
|
||||
if repo.family == "github":
|
||||
return (f"{repo.api_base}/repos/{repo.slug}/commits"
|
||||
f"?path={quoted}&per_page={PER_PAGE}&page={page}")
|
||||
return (f"{repo.api_base}/repos/{repo.slug}/commits"
|
||||
f"?path={quoted}&limit={PER_PAGE}&page={page}")
|
||||
|
||||
|
||||
def path_history(repo: upstream.Repo, path: str, cache_dir: str) -> list[str]:
|
||||
"""Commits that touched a path, newest first."""
|
||||
shas: list[str] = []
|
||||
for page in range(1, MAX_PAGES + 1):
|
||||
payload = upstream._api(_history_url(repo, path, page), cache_dir, False,
|
||||
max_age=upstream.MOVING_TTL)
|
||||
if not isinstance(payload, list) or not payload:
|
||||
break
|
||||
shas += [str(entry.get("sha") or entry.get("id")) for entry in payload]
|
||||
if len(payload) < PER_PAGE:
|
||||
break
|
||||
return shas
|
||||
|
||||
|
||||
def find_revision(
|
||||
repo: upstream.Repo, path: str, md5: str, cache_dir: str,
|
||||
) -> tuple[str, bytes] | None:
|
||||
"""The newest revision whose copy of the path has this md5, and its bytes."""
|
||||
wanted = md5.lower()
|
||||
for sha in path_history(repo, path, cache_dir):
|
||||
data = upstream._fetch(upstream.content_url(repo, sha, path))
|
||||
if data is not None and hashlib.md5(data).hexdigest() == wanted:
|
||||
return sha, data
|
||||
return None
|
||||
from acquire.history import find_revision
|
||||
|
||||
|
||||
def main() -> int:
|
||||
|
||||
Reference in new issue
Block a user