mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-12 04:53:52 -06:00
feat: validate every file of a folder
This commit is contained in:
1 parent
7b6b22351a
commit
f285c32d67
5 files changed
+43
-5
No files matched your search
+27
-2
@@ -23,6 +23,7 @@ import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from common import (
|
||||
@@ -301,8 +302,12 @@ def validate_file(
|
||||
"changed under bios/")
|
||||
return result
|
||||
|
||||
if os.path.isdir(filepath):
|
||||
result.add_check(False, "Folder with no file in it")
|
||||
return result
|
||||
|
||||
if not os.path.isfile(filepath):
|
||||
result.add_check(False, "Not a regular file")
|
||||
result.add_check(False, "Not a regular file: a device, a pipe or a socket")
|
||||
return result
|
||||
|
||||
result.size = os.path.getsize(filepath)
|
||||
@@ -561,6 +566,26 @@ def get_changed_files() -> list[str]:
|
||||
]
|
||||
|
||||
|
||||
def expand_folders(paths: list[str]) -> list[str]:
|
||||
"""Each folder named replaced by the files under it, subfolders included.
|
||||
|
||||
A card's BIOS folder was refused as "Not a regular file", and the
|
||||
contributor had to list its files by hand. A link inside the folder
|
||||
stays listed, so it is refused like a named one, and an empty folder
|
||||
stays as itself to be reported.
|
||||
"""
|
||||
out: list[str] = []
|
||||
for path in paths:
|
||||
if not os.path.isdir(path) or os.path.islink(path):
|
||||
out.append(path)
|
||||
continue
|
||||
found = sorted(
|
||||
str(f) for f in Path(path).rglob("*") if f.is_symlink() or f.is_file()
|
||||
)
|
||||
out.extend(found or [path])
|
||||
return out
|
||||
|
||||
|
||||
def _files_to_validate(
|
||||
args: argparse.Namespace, parser: argparse.ArgumentParser
|
||||
) -> list:
|
||||
@@ -572,7 +597,7 @@ def _files_to_validate(
|
||||
if not args.changed:
|
||||
if not args.files:
|
||||
parser.error("No files specified. Use --changed or provide file paths.")
|
||||
return args.files
|
||||
return expand_folders(args.files)
|
||||
try:
|
||||
files = get_changed_files()
|
||||
except (RuntimeError, OSError) as exc:
|
||||
|
||||
Reference in new issue
Block a user