maintainers/scripts/sha-to-sri: accept directories as input
Doesn't skip files passed as CLI arguments based on their name anymore, since bulk changes can now be done without resorting to `xargs` or equivalent.
This commit is contained in:
parent
915799a2b9
commit
bf6b5f7f85
@ -7,7 +7,7 @@ from pathlib import Path
|
||||
from structlog.contextvars import bound_contextvars as log_context
|
||||
from typing import ClassVar, List, Tuple
|
||||
|
||||
import hashlib, re, structlog
|
||||
import hashlib, logging, re, structlog
|
||||
|
||||
|
||||
logger = structlog.getLogger("sha-to-SRI")
|
||||
@ -208,24 +208,20 @@ if __name__ == "__main__":
|
||||
|
||||
logger.info("Starting!")
|
||||
|
||||
for arg in argv[1:]:
|
||||
p = Path(arg)
|
||||
with log_context(path = str(p)):
|
||||
def handleFile(p: Path, skipLevel = logging.INFO):
|
||||
with log_context(file = str(p)):
|
||||
try:
|
||||
if p.name == "yarn.nix" or p.name.find("generated") != -1:
|
||||
logger.warning("File looks autogenerated, skipping!")
|
||||
continue
|
||||
|
||||
with p.open() as f:
|
||||
for line in f:
|
||||
if line.strip():
|
||||
break
|
||||
|
||||
if _SKIP_RE.search(line):
|
||||
logger.warning("File looks autogenerated, skipping!")
|
||||
continue
|
||||
logger.log(skipLevel, "File looks autogenerated, skipping!")
|
||||
return
|
||||
|
||||
fileToSRI(p)
|
||||
|
||||
except Exception as exn:
|
||||
logger.error(
|
||||
"Unhandled exception, skipping file!",
|
||||
@ -233,3 +229,19 @@ if __name__ == "__main__":
|
||||
)
|
||||
else:
|
||||
logger.info("Finished processing file")
|
||||
|
||||
for arg in argv[1:]:
|
||||
p = Path(arg)
|
||||
with log_context(arg = arg):
|
||||
if p.is_file():
|
||||
handleFile(p, skipLevel = logging.WARNING)
|
||||
|
||||
elif p.is_dir():
|
||||
logger.info("Recursing into directory")
|
||||
for q in p.glob("**/*.nix"):
|
||||
if q.is_file():
|
||||
if q.name == "yarn.nix" or q.name.find("generated") != -1:
|
||||
logger.info("File looks autogenerated, skipping!")
|
||||
continue
|
||||
|
||||
handleFile(q)
|
||||
|
Loading…
Reference in New Issue
Block a user