From 0819c447bc8ac213a8038acc0b1a27647c66b998 Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Fri, 2 Oct 2020 21:50:41 +0200 Subject: cleanup: actually make it work --- mgagnome | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/mgagnome b/mgagnome index 2a04350..7db0aa7 100755 --- a/mgagnome +++ b/mgagnome @@ -1864,22 +1864,47 @@ def cmd_cleanup(_): # dirs = dirs - packages import pysvn # pylint: disable=import-outside-toplevel - dirs = [path for path in dirs if path.joinpath('SOURCES', 'sha1.lst').exists()] + dirs = [path for path in dirs if path.joinpath('SOURCES', 'sha1.lst').exists() + and path.joinpath('SPECS', '%s.spec' % path.name).exists()] + + curtime = time.time() + curtime_recent = curtime - (36 * 60 * 60) + curtime_ancient = curtime - (180 * 24 * 60 * 60) for path in dirs: + # Only select the packages which have not been modified for 36 hours + mtime = path.joinpath('SPECS', '%s.spec' % path.name).stat().st_mtime + if mtime > curtime_recent: + print('INFO: Package was too recently modified: %s' % path.name) + continue + + # Remove any packages not touched for 180 days + if mtime < curtime_ancient: + print('INFO: Package is ancient, removing: %s' % path.name) + shutil.rmtree(path) + continue + + + # Cleanup BUILD and BUILDROOT directories + for cleanup_dir in ('BUILD', 'BUILDROOT'): + for cleanup_path in ((cleanup_path for cleanup_path in path.joinpath(cleanup_dir).glob('*') \ + if cleanup_path.is_dir() \ + and cleanup_path.stat().st_mtime < curtime_recent)): + shutil.rmtree(cleanup_path) + try: binaries = set((l.split(' ', 1)[1] for l in path.joinpath('SOURCES', 'sha1.lst').open().read().splitlines())) except IndexError: - print('ERROR: Problem parsing the sha1.lst of package %s' % path.basename(), file=sys.stderr) + print('ERROR: Problem parsing the sha1.lst of package %s' % path.name, file=sys.stderr) # shutil.rmtree(path) # Downstream.package(path).checkout() continue vcs = pysvn.Client() - stats = [stat for stat in vcs.status(path.joinpath('SOURCES'), depth=pysvn.depth.immediates) # pylint: disable=no-member + stats = [stat for stat in vcs.status(str(path.joinpath('SOURCES')), depth=pysvn.depth.immediates) # pylint: disable=no-member if stat.text_status == pysvn.wc_status_kind.unversioned # pylint: disable=no-member - and stat.path.name not in binaries] # pylint: disable=no-member + and Path(stat.path).name not in binaries] # pylint: disable=no-member if stats: print(path) -- cgit v1.2.1