mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 18:47:53 -06:00
refactor: hash fields and digests read in core
This commit is contained in:
1 parent
238f70c7a7
commit
f371790dc6
4 files changed
+20
-13
No files matched your search
@@ -27,13 +27,13 @@ import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from core.hashing import file_digest
|
||||
from model.registry import list_release_pack_platforms
|
||||
from core.cli import require_directory
|
||||
from model.releaserecord import RECORD, load_record
|
||||
from release.check import (
|
||||
SIGNATURE,
|
||||
SUMS,
|
||||
_sha256,
|
||||
compare_release,
|
||||
fetch_assets,
|
||||
fetch_sums,
|
||||
@@ -74,10 +74,10 @@ def main() -> int:
|
||||
if args.sums:
|
||||
sums_path = Path(args.sums)
|
||||
sums_text = sums_path.read_text(encoding="utf-8")
|
||||
local_files = {SUMS: _sha256(sums_path)}
|
||||
local_files = {SUMS: file_digest(sums_path, "sha256")}
|
||||
signature = sums_path.with_name(SIGNATURE)
|
||||
if signature.is_file():
|
||||
local_files[SIGNATURE] = _sha256(signature)
|
||||
local_files[SIGNATURE] = file_digest(signature, "sha256")
|
||||
else:
|
||||
sums_text = fetch_sums(tag)
|
||||
local_files = {}
|
||||
|
||||
@@ -5,9 +5,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import subprocess
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from core.hashing import file_digest
|
||||
from release.assets import digests_of
|
||||
from model.largefiles import LARGE_FILES_REPO
|
||||
|
||||
@@ -113,10 +111,6 @@ def compare_release(
|
||||
return findings
|
||||
|
||||
|
||||
def _sha256(path: Path) -> str:
|
||||
return file_digest(path, "sha256")
|
||||
|
||||
|
||||
def fetch_assets(tag: str) -> tuple[dict[str, Asset], bool]:
|
||||
"""Name, size and sha256 of every asset of *tag*, and whether it is a draft."""
|
||||
result = subprocess.run(
|
||||
|
||||
@@ -9,6 +9,7 @@ import urllib.parse
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
from core.hashing import parse_hash_list
|
||||
from model import siteinputs
|
||||
from model.collection import _slug
|
||||
from model.systemnames import system_name
|
||||
@@ -28,10 +29,7 @@ def _hash_values(value: object) -> list[str]:
|
||||
A field holds one value, a list of accepted revisions, or (Recalbox) a
|
||||
comma-joined string: an exact lookup missed all but the first form.
|
||||
"""
|
||||
if value is None:
|
||||
return []
|
||||
items = value if isinstance(value, (list, tuple)) else str(value).split(",")
|
||||
return sorted({str(item).strip().lower() for item in items if str(item).strip()})
|
||||
return sorted(parse_hash_list(value))
|
||||
|
||||
|
||||
def _site_path(markdown_target: str) -> str:
|
||||
|
||||
@@ -82,5 +82,20 @@ class OneDigestLoopForFilesAndStreams(unittest.TestCase):
|
||||
self.assertEqual(hashing.md5sum(io.BytesIO(self.DATA)), hashlib.md5(self.DATA).hexdigest())
|
||||
|
||||
|
||||
class TheSiteReadsAHashFieldTheResolversWay(unittest.TestCase):
|
||||
"""The file lookup indexes the values the resolver accepts, sorted."""
|
||||
|
||||
def test_every_shape_of_a_field(self):
|
||||
from sitegen import lookup
|
||||
|
||||
for raw, expected in (
|
||||
(None, []), ("", []), ("B2, a1,b2", ["a1", "b2"]), (["C3", " a1 "], ["a1", "c3"]),
|
||||
("0xDEADBEEF", ["deadbeef"]), (12345678, ["12345678"]),
|
||||
):
|
||||
with self.subTest(raw=raw):
|
||||
self.assertEqual(lookup._hash_values(raw), expected)
|
||||
self.assertEqual(lookup._hash_values(raw), sorted(hashing.parse_hash_list(raw)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user