#2346 backend: resultdir cleaner
Closed 2 years ago by praiskup. Opened 2 years ago by praiskup.
Unknown source resultdircleaner  into  main

@@ -0,0 +1,132 @@

+ #! /usr/bin/python3

+ 

+ """

+ Cleanup the old chroot_scan folders

+ """

+ 

+ import logging

+ import os

+ import sys

+ import pwd

+ import argparse

+ 

+ from copr_common.tree import walk_limited

+ from copr_backend.helpers import BackendConfigReader

+ 

+ 

+ logging.basicConfig(level=logging.DEBUG)

+ LOG = logging.getLogger()

+ 

+ parser = argparse.ArgumentParser(

+     description=("TBD")

+ )

+ parser.add_argument(

+     "--real-run",

+     action='store_true',

+     help=("Also perform the changes, not just checks"))

+ 

+ def script_requires_user(username):

+     """

+     TODO: being moved to copr common

+     """

+     actual_username = pwd.getpwuid(os.getuid())[0]

+     if actual_username != username:

+         msg = (

+             "This script should be executed "

+             "as '{0}' user, not '{1}'\n"

+         ).format(

+             username,

+             actual_username,

+         )

+         sys.stderr.write(msg)

+         sys.exit(1)

+ 

+ 

+ def clean_in(resultdir, dry_run=True):

+     """

+     Perform a cleanup of the 'chroot_scan' directories.

+     """

+     # walk through all build directories like:

+     # praiskup/ping/fedora-rawhide-x86_64/02149226-friday

+     # in:

+     # /var/lib/copr/public_html/results (resultdir)

+     # and remove old 'chroot_scan' directories

+     for chroot_dir, subdirs, _ in walk_limited(resultdir, mindepth=3, maxdepth=3):

+ 

+         if os.path.basename(chroot_dir) == "srpm-builds":

+             continue

+ 

+         # if os.path.basename(build_dir) in ["tmp", "cache"]:

+         #     continue

+         for subdir in subdirs:

+             if subdir in ["repodata", "devel"]:

+                 # Keep those

+                 continue

+             if subdir.startswith("repodata.old"):

+                 # TODO: ???

+                 continue

+             if subdir == "appdata":

+                 # TODO: what to do with this???

+                 continue

+             if subdir in ["tmp", "cache"]:

+                 continue

+ 

+             parts = subdir.split("-")

+             if len(parts) <= 1:

+                 # Report those, these dirs shouldn't exist

+                 print(chroot_dir)

+                 print(subdir)

+                 continue

+             else:

+                 number = parts[0]

+                 if len(number) != 8 or any(not c.isdigit() for c in number):

+                     # TODO: This deserves a future cleanup???

+                     # Stuff like:

+                     # /var/lib/copr/public_html/results/idm/asterisk/epel-7-x86_64/dahdi-tools-2.10.0-6.fc24/

+                     #print(chroot_dir)

+                     #print(subdir)

+                     continue

+ 

+             # We have the 00000000-XXXXXXX patern now in chroot_dir

+             build_dir = os.path.join(chroot_dir, subdir)

+             for builddir, subdirs, _ in walk_limited(build_dir, mindepth=0, maxdepth=0):

+                 for sub_builddir in subdirs:

+                     if sub_builddir == "configs":

+                         # TODO: tar --delete-files those

+                         # E.g. /var/lib/copr/public_html/results/markvnl/loolwsd/epel-7-x86_64/00802191-nodejs-brace-expansion/configs

+                         continue

+                     if sub_builddir == "chroot_scan":

+                         # TODO: remove those

+                         continue

+ 

+                     if sub_builddir in ["fedora-review", "prev_build_backup"]:

+                         # These are expected subdirs.

+                         continue

+ 

+                     # TODO: detect a fedora-review failure dirs, like:

+                     # https://download.copr.fedorainfracloud.org/results/throup/VisualVM/fedora-35-x86_64/04899225-VisualVM/VisualVM/

+ 

+                     subdir_path = os.path.join(builddir, sub_builddir)

+                     items = os.listdir(subdir_path)

+                     if "srpm-unpacked" in items and "upstream-unpacked" in items:

+                         # Fedora review failure

+                         continue

+ 

+                     # Nothing should remain!

+                     print(builddir)

+                     print(sub_builddir)

+ 

+ 

+ def _main():

+     args = parser.parse_args()

+     if not args.real_run:

+         LOG.warning("Just doing dry run, run with --real-run")

+ 

+     config_file = os.environ.get("BACKEND_CONFIG", "/etc/copr/copr-be.conf")

+     opts = BackendConfigReader(config_file).read()

+ 

+     clean_in(opts.destdir)

+ 

+ if __name__ == "__main__":

+     script_requires_user("copr")

+     _main()

no initial comment

Pull-Request has been closed by praiskup

2 years ago

rebased onto 180709e

2 years ago
Metadata