Created
January 19, 2024 11:43
-
-
Save praiskup/0ef34bd73f8ee3b19cab12d36f7a17d7 to your computer and use it in GitHub Desktop.
Find file-deps in spec-files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python3 | |
import time | |
from glob import glob | |
from specfile import Specfile | |
OK_MACRO_DEPS = [ | |
'__make', | |
'__perl', | |
] | |
OK_MACRO_START = [ | |
'_bindir', | |
'_sbindir', | |
] | |
MACRO_WRAPPERS = [ | |
'py3_dist', | |
] | |
def get_build_requires_from_line(line): | |
items = line.split(",") | |
if len(items) <= 1: | |
for c in "<=>": | |
if c in line: | |
return [x.strip() for x in items if x] | |
items = line.split(" ") | |
return [x.strip() for x in items if x] | |
def detect_bad_dep(spec, dep): | |
if not dep.startswith("/") and not dep.startswith("%"): | |
return | |
for allowed in ["/usr/bin", "/usr/sbin", "/etc"]: | |
if dep.startswith(allowed): | |
return | |
for ok in OK_MACRO_DEPS: | |
if dep == f"%{ok}": # %__perl variant | |
return | |
if dep == f"%{{{ok}}}": # %{__perl} variant | |
return | |
for ok in OK_MACRO_START: | |
if dep.startswith(f"%{ok}/"): # %_bindir variant | |
return | |
if dep.startswith(f"%{{{ok}}}/"): # %{_bindir} variant | |
return | |
for ok in MACRO_WRAPPERS: | |
if dep.startswith(f"%{{{ok} "): # %_bindir variant | |
return | |
print(f"{spec}:{dep}") | |
start = time.time() | |
counter = 0 | |
for spec in glob('*.spec'): | |
counter += 1 | |
if counter % 50 == 0: | |
print(f" ===> counter: {counter} ({time.time() - start} seconds") | |
try: | |
parsed = Specfile(spec) | |
tags = parsed.tags(parsed.parsed_sections.package).content | |
for tag in tags: | |
if tag.normalized_name == "Buildrequires": | |
for dep in get_build_requires_from_line(tag.expanded_value): | |
detect_bad_dep(spec, dep) | |
except KeyboardInterrupt: | |
print("interrupting") | |
break | |
except Exception as e: | |
print(f"Can't parse {spec}") | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment