MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / process_file

Function process_file

scripts/update_license_headers.py:267–291  ·  view source on GitHub ↗

Process a single file. Returns True if the file is compliant.

(path: Path, root: Path, *, check: bool, verbose: bool)

Source from the content-addressed store, hash-verified

265
266
267def process_file(path: Path, root: Path, *, check: bool, verbose: bool) -> bool:
268 """Process a single file. Returns True if the file is compliant."""
269 rel = path.relative_to(root)
270 comment = get_comment_style(rel)
271 if comment is None:
272 return True
273
274 content = path.read_text(encoding="utf-8")
275 lines = content.splitlines()
276
277 if has_header(lines):
278 if verbose:
279 print(f" ok: {rel}")
280 return True
281
282 if check:
283 print(f" MISSING: {rel}")
284 return False
285
286 # Insert the header.
287 new_content = insert_header(content, comment, rel)
288 path.write_text(new_content, encoding="utf-8")
289 if verbose:
290 print(f" added: {rel}")
291 return True
292
293
294def main() -> int:

Callers 1

mainFunction · 0.85

Calls 3

get_comment_styleFunction · 0.85
has_headerFunction · 0.85
insert_headerFunction · 0.85

Tested by

no test coverage detected