mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-30 13:28:51 -06:00
refactor: read old branches through acquire
migrate --include-branches and the acquisition search list the legacy platform branches with acquire.fetch.legacy_branch_files and read them with legacy_branch_blob: one branch list (migrate lacked libretro), git run from the repository root wherever the command started.
This commit is contained in:
1 parent
e636614ae3
commit
83b1976903
2 files changed
+33
-53
No files matched your search
+27
-29
@@ -13,7 +13,7 @@ from pathlib import Path
|
||||
|
||||
from core import upstream
|
||||
from core.hashing import parse_hash_list, parse_md5_list
|
||||
from core.paths import EMULATORS_DIR, PLATFORMS_DIR
|
||||
from core.paths import EMULATORS_DIR, PLATFORMS_DIR, REPO_ROOT
|
||||
from resolve.localfile import held_record_for
|
||||
from resolve.review import load_platform_hashes, load_profile_hashes, placement
|
||||
|
||||
@@ -21,6 +21,28 @@ MAX_DOWNLOAD = 100 * 1024 * 1024 # 100MB per file
|
||||
|
||||
LEGACY_BRANCHES = ["libretro", "RetroArch", "RetroPie", "Recalbox", "batocera", "Other"]
|
||||
|
||||
|
||||
def legacy_branch_files(branch: str) -> list[str] | None:
|
||||
"""Every path origin/<branch> holds, None when the remote has no such branch."""
|
||||
ref = f"origin/{branch}"
|
||||
try:
|
||||
subprocess.run(["git", "rev-parse", "--verify", ref], capture_output=True, check=True,
|
||||
cwd=REPO_ROOT)
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
result = subprocess.run(["git", "ls-tree", "-r", "--name-only", ref], capture_output=True,
|
||||
text=True, check=False, cwd=REPO_ROOT)
|
||||
return [path for path in result.stdout.split("\n") if path]
|
||||
|
||||
|
||||
def legacy_branch_blob(branch: str, path: str) -> bytes | None:
|
||||
"""The bytes origin/<branch> holds at a path, None when git cannot show them."""
|
||||
try:
|
||||
return subprocess.run(["git", "show", f"origin/{branch}:{path}"], capture_output=True,
|
||||
check=True, cwd=REPO_ROOT).stdout
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
|
||||
PUBLIC_REPOS = [
|
||||
# archtaurus/RetroPieBIOS - most complete verified collection
|
||||
"https://raw.githubusercontent.com/archtaurus/RetroPieBIOS/master/BIOS/{name}",
|
||||
@@ -152,35 +174,11 @@ def step2_scan_branches(entry: dict) -> bytes | None:
|
||||
name = entry["name"]
|
||||
|
||||
for branch in LEGACY_BRANCHES:
|
||||
ref = f"origin/{branch}"
|
||||
try:
|
||||
subprocess.run(
|
||||
["git", "rev-parse", "--verify", ref],
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
continue
|
||||
|
||||
result = subprocess.run(
|
||||
["git", "ls-tree", "-r", "--name-only", ref],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
for filepath in result.stdout.strip().split("\n"):
|
||||
for filepath in legacy_branch_files(branch) or ():
|
||||
if os.path.basename(filepath) == name:
|
||||
try:
|
||||
blob = subprocess.run(
|
||||
["git", "show", f"{ref}:{filepath}"],
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
if verify_content(blob.stdout, entry):
|
||||
return blob.stdout
|
||||
except subprocess.CalledProcessError:
|
||||
continue
|
||||
content = legacy_branch_blob(branch, filepath)
|
||||
if content is not None and verify_content(content, entry):
|
||||
return content
|
||||
|
||||
return None
|
||||
|
||||
|
||||
+6
-24
@@ -15,11 +15,11 @@ import argparse
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from acquire.fetch import LEGACY_BRANCHES, legacy_branch_blob, legacy_branch_files
|
||||
from core.hashing import compute_hashes
|
||||
|
||||
SYSTEM_MAP = {
|
||||
@@ -235,8 +235,6 @@ TOS_PATTERN_MAP = {
|
||||
|
||||
SKIP_LARGE_ROM_DIRS = {"roms/"}
|
||||
|
||||
BRANCHES = ["RetroArch", "RetroPie", "Recalbox", "batocera", "Other"]
|
||||
|
||||
SKIP_FILES = {
|
||||
"README.md",
|
||||
".gitignore",
|
||||
@@ -350,21 +348,11 @@ def extract_from_branches(target: Path, dry_run: bool, existing_hashes: set) ->
|
||||
"""Extract BIOS files from all branches into the target structure."""
|
||||
extracted = 0
|
||||
|
||||
for branch in BRANCHES:
|
||||
ref = f"origin/{branch}"
|
||||
|
||||
try:
|
||||
subprocess.run(
|
||||
["git", "rev-parse", "--verify", ref], capture_output=True, check=True
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
for branch in LEGACY_BRANCHES:
|
||||
files = legacy_branch_files(branch)
|
||||
if files is None:
|
||||
print(f" Branch {branch} not found, skipping")
|
||||
continue
|
||||
|
||||
result = subprocess.run(
|
||||
["git", "ls-tree", "-r", "--name-only", ref], capture_output=True, text=True, check=False
|
||||
)
|
||||
files = result.stdout.strip().split("\n")
|
||||
print(f"\n Branch '{branch}': {len(files)} files")
|
||||
|
||||
branch_extracted = 0
|
||||
@@ -378,14 +366,8 @@ def extract_from_branches(target: Path, dry_run: bool, existing_hashes: set) ->
|
||||
dest_dir = target / manufacturer / console
|
||||
dest = dest_dir / subpath
|
||||
|
||||
try:
|
||||
blob = subprocess.run(
|
||||
["git", "show", f"{ref}:{filepath}"],
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
content = blob.stdout
|
||||
except subprocess.CalledProcessError:
|
||||
content = legacy_branch_blob(branch, filepath)
|
||||
if content is None:
|
||||
continue
|
||||
|
||||
file_hash = sha1_blob(content)
|
||||
|
||||
Reference in new issue
Block a user