Skip to content

Commit

Permalink
Experimental script for scrubbing everything
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Feb 22, 2024
1 parent fc1f7d4 commit c0ddd1d
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mock/mock.spec
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ install -d %{buildroot}%{_bindir}
install -d %{buildroot}%{_libexecdir}/mock
install mockchain %{buildroot}%{_bindir}/mockchain
install py/mock-parse-buildlog.py %{buildroot}%{_bindir}/mock-parse-buildlog
install py/mock-scrub-everything.py %{buildroot}%{_bindir}/mock-scrub-everything
install py/mock.py %{buildroot}%{_libexecdir}/mock/mock
ln -s consolehelper %{buildroot}%{_bindir}/mock
install create_default_route_in_container.sh %{buildroot}%{_libexecdir}/mock/
Expand Down Expand Up @@ -243,6 +244,7 @@ pylint-3 py/mockbuild/ py/*.py py/mockbuild/plugins/* || :
# executables
%{_bindir}/mock
%{_bindir}/mockchain
%{_bindir}/mock-scrub-everything
%{_bindir}/mock-parse-buildlog
%{_libexecdir}/mock

Expand Down
103 changes: 103 additions & 0 deletions mock/py/mock-scrub-everything.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#! /bin/python3

Check warning

Code scanning / vcs-diff-lint

Missing module docstring Warning

Missing module docstring

Check warning

Code scanning / vcs-diff-lint

Module name "mock-scrub-everything" doesn't conform to '([a-zA-Z_][a-zA-Z0-9_]+)$' pattern Warning

Module name "mock-scrub-everything" doesn't conform to '([a-zA-Z_][a-zA-Z0-9_]+)$' pattern

import os
from glob import glob
import sys
import subprocess


def _do_scrub(configs, weird, chroot, suffix=None):
if suffix and chroot + "-" + suffix in weird:
print(f"skipping weird scrub: {chroot} {suffix}")
return

base_cmd = ["mock", "--scrub=all", "-r"]
cmd = base_cmd + ["eol/" + chroot if configs[chroot] == "eol" else chroot]
if suffix is not None:
cmd += ["--uniqueext", suffix]
subprocess.call(cmd)


def _main():

Check warning

Code scanning / vcs-diff-lint

_main: Too many branches (20/12) Warning

_main: Too many branches (20/12)
configs = {}
scrub = set()
scrub_bootstrap = set()
scrub_uniqueext = set()
scrub_uniqueext_bootstrap = set()
scrub_weird = set()
guessing_suffix = {}

for item in glob("/etc/mock/*.cfg"):
configs[os.path.basename(item)[:-4]] = "normal"
for item in glob("/etc/mock/eol/*.cfg"):
configs[os.path.basename(item)[:-4]] = "eol"

for directory in glob("/var/lib/mock/*") + glob("/var/cache/mock/*"):
if not os.path.isdir(directory):
continue

directory = os.path.basename(directory)

if directory in configs:
scrub.add(directory)
continue

if directory.endswith("-bootstrap"):
directory_no_bootstrap = directory[:-10]
if directory_no_bootstrap in configs:
scrub_bootstrap.add(directory_no_bootstrap)
continue

guessing_suffix[directory] = None

for config, config_type in configs.items():

Check warning

Code scanning / vcs-diff-lint

_main: Unused variable 'config_type' Warning

_main: Unused variable 'config_type'
for directory in list(guessing_suffix.keys()):
if guessing_suffix[directory]:
# already found the cleaning thing
continue

if directory.startswith(config):

suffix = directory[len(config)+1:]
if suffix.endswith("-bootstrap"):
# See this:
# 1. alma+epel-8-x86_64-php-bootstrap
# 2. alma+epel-8-x86_64-bootstrap-php
# The 1. is weird, and we miss the corresponding
# configuration. The second could be a "php" uniqueext.
weird_chroot = directory[:-10]
scrub_weird.add(weird_chroot)
continue

start = "bootstrap-"
if suffix.startswith(start):
suffix = suffix[len(start):]
scrub_uniqueext_bootstrap.add((config, suffix))
else:
scrub_uniqueext.add((config, suffix))

guessing_suffix[directory] = "uniqueext"



for sc, suffix in scrub_uniqueext_bootstrap - scrub_uniqueext:
_do_scrub(configs, scrub_weird, sc, suffix)


for sc, suffix in scrub_uniqueext:
_do_scrub(configs, scrub_weird, sc, suffix)

for only_bootstrap in scrub_bootstrap - scrub:
_do_scrub(configs, scrub_weird, only_bootstrap)

for sc in scrub:
_do_scrub(configs, scrub_weird, sc)

for directory, found in guessing_suffix.items():
if found:
continue
print(f"Unknown directory: {directory}")


if __name__ == "__main__":
sys.exit(_main())

0 comments on commit c0ddd1d

Please sign in to comment.