Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/evidence/MAX-INTEROP/G1/license_inventory.py # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / evidence / MAX-INTEROP / G1 / license_inventory.py` 62 lines · 2732 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """File-level licence inventory of a git tree (from git objects, not the 3 working tree, which may be sparse). Throwaway diagnostic. 4 usage: license_inventory.py REPO REV OUT_TSV""" 5 import collections, hashlib, os, re, subprocess, sys 6 7 repo, rev, out = sys.argv[1:4] 8 spdx = re.compile(r"SPDX-License-Identifier:\s*([^\n*#]+)") 9 tree = subprocess.run(["git", "-C", repo, "ls-tree", "-r", "--format=%(objectmode) %(objectname) %(path)", rev], 10 capture_output=True, text=True, check=True).stdout.splitlines() 11 entries = [l.split(" ", 2) for l in tree] 12 lic = [p for _, _, p in entries if re.search(r"(^|/)(LICENSE|LICENCE|COPYING|MAX_LICENSE|NOTICE)[^/]*$", p)] 13 lic_dirs = collections.defaultdict(list) 14 for p in lic: 15 lic_dirs[os.path.dirname(p)].append(p) 16 17 def nearest(p): 18 d = os.path.dirname(p) 19 while True: 20 if d in lic_dirs: 21 return ",".join(lic_dirs[d]) 22 if not d: 23 return "" 24 d = os.path.dirname(d) 25 26 def classify(b): 27 if b.startswith(b"version https://git-lfs"): 28 return "LFS-POINTER", "" 29 t = b[:4096].decode("utf-8", "replace") 30 m = spdx.search(t) 31 if m: 32 return "SPDX", m.group(1).strip().rstrip("-*/ ").strip() 33 if "Apache License" in t and "LLVM" in t: 34 return "HEADER", "Apache-2.0 WITH LLVM-exception" 35 if re.search(r"MAX (Community )?License|MAX Platform", t): 36 return "HEADER", "MAX License" 37 if "Apache License" in t: 38 return "HEADER", "Apache-2.0" 39 if "MIT License" in t or "Permission is hereby granted, free of charge" in t: 40 return "HEADER", "MIT" 41 if b"\0" in b[:4096]: 42 return "NONE", "binary" 43 return "NONE", "no-header" 44 45 cat = subprocess.Popen(["git", "-C", repo, "cat-file", "--batch"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) 46 counts = collections.Counter() 47 with open(out, "w") as fo: 48 fo.write("path\tmode\tblob_sha256\tkind\tlicence\tgoverning_licence_file\n") 49 for mode, obj, path in entries: 50 if mode == "160000": # submodule 51 fo.write(f"{path}\t{mode}\t\tSUBMODULE\t\t\n"); counts[("SUBMODULE", "", "")] += 1; continue 52 cat.stdin.write((obj + "\n").encode()); cat.stdin.flush() 53 hdr = cat.stdout.readline().split() 54 n = int(hdr[2]); b = cat.stdout.read(n); cat.stdout.read(1) 55 kind, l = classify(b) 56 gov = nearest(path) if kind in ("NONE", "LFS-POINTER") else "" 57 fo.write(f"{path}\t{mode}\t{hashlib.sha256(b).hexdigest()}\t{kind}\t{l}\t{gov}\n") 58 counts[(kind, l, gov)] += 1 59 cat.stdin.close(); cat.wait() 60 print(f"repo={repo} rev={rev} files={len(entries)} licence_files={lic}") 61 for (k, l, g), c in counts.most_common(): 62 print(f"{c}\t{k}\t{l}\t{g}")