krz/nfogen

A scene-style ASCII .nfo generator. ascii cli generator nfo

Commit 445461a363

445461a363a844db704e2f19decce256d12aca77

parent: 3d2fb0c76b

Verified · cmc

cmc <hello@cleberg.net> · 2026-08-08 06:33 UTC

drop NOSONAR suppressions

Layout: unified · split

nfogen.py +8 −8
@@ -96,7 +96,7 @@ def load_config(explicit: str | None) -> dict:
9696 """Load defaults from a TOML or JSON file. Returns {} if none found."""
9797 path = None
9898 if explicit:
99 path = Path(explicit) # NOSONAR local CLI: the user's own path, no trust boundary
99 path = Path(explicit)
100100 if not path.exists():
101101 sys.exit(f"nfogen: config not found: {explicit}")
102102 else:
@@ -104,7 +104,7 @@ def load_config(explicit: str | None) -> dict:
104104 if path is None:
105105 return {}
106106
107 text = path.read_text(encoding="utf-8") # NOSONAR local CLI: the user's own path
107 text = path.read_text(encoding="utf-8")
108108 if path.suffix == ".json":
109109 return json.loads(text)
110110 try:
@@ -121,12 +121,12 @@ _MI_TYPE = "@type" # mediainfo track-type key
121121def load_mediainfo(path: str) -> dict:
122122 """Read a `mediainfo --Output=JSON` dump (or run mediainfo on a media file)
123123 and return values for the video/audio/resolution/size/runtime/format keys."""
124 p = Path(path) # NOSONAR local CLI: the user's own path, no trust boundary
124 p = Path(path)
125125 if p.suffix.lower() == ".json":
126 raw = p.read_text(encoding="utf-8") # NOSONAR local CLI: the user's own path
126 raw = p.read_text(encoding="utf-8")
127127 else:
128128 try:
129 proc = subprocess.run(["mediainfo", "--Output=JSON", str(p)], # NOSONAR local CLI: the user's own file
129 proc = subprocess.run(["mediainfo", "--Output=JSON", str(p)],
130130 capture_output=True, text=True, check=True)
131131 except FileNotFoundError:
132132 sys.exit("nfogen: mediainfo not installed; pass a JSON dump to --mediainfo")
@@ -633,7 +633,7 @@ def _resolve_logo(args, config: dict, group: str) -> str | None:
633633 if logo_path:
634634 enc = args.logo_encoding or config.get("logo_encoding") or "cp437"
635635 try:
636 return Path(logo_path).read_text(encoding=enc, errors="replace") # NOSONAR local CLI: the user's own path
636 return Path(logo_path).read_text(encoding=enc, errors="replace")
637637 except FileNotFoundError:
638638 sys.exit(f"nfogen: logo not found: {logo_path}")
639639 if _resolve(args.banner, config, "banner", False):
@@ -666,11 +666,11 @@ def _write_output(text: str, args) -> None:
666666 if args.encoding == "cp437":
667667 raw = text.encode("cp437", errors="replace")
668668 if args.output:
669 Path(args.output).write_bytes(raw) # NOSONAR local CLI: the user's own path
669 Path(args.output).write_bytes(raw)
670670 else:
671671 sys.stdout.buffer.write(raw)
672672 elif args.output:
673 Path(args.output).write_text(text, encoding="utf-8") # NOSONAR local CLI: the user's own path
673 Path(args.output).write_text(text, encoding="utf-8")
674674 else:
675675 sys.stdout.write(text)
676676