| |
@@ -162,13 +162,13 @@
|
| |
continue
|
| |
|
| |
try:
|
| |
- cmd = ['prunerepo', '--verbose', '--days', str(self.prune_days),
|
| |
- '--cleancopr', '--nocreaterepo', chroot_path]
|
| |
+ cmd = ['prunerepo', '--verbose', '--days', str(self.prune_days), '--nocreaterepo', chroot_path]
|
| |
stdout = runcmd(cmd)
|
| |
loginfo(stdout)
|
| |
createrepo(path=chroot_path, front_url=self.opts.frontend_base_url,
|
| |
username=username, projectname=projectname,
|
| |
override_acr_flag=True)
|
| |
+ clean_copr(chroot_path, self.prune_days, verbose=True)
|
| |
except Exception as err:
|
| |
logexception(err)
|
| |
logerror("Error pruning chroot {}/{}:{}".format(username, projectdir, sub_dir_name))
|
| |
@@ -178,6 +178,50 @@
|
| |
loginfo("Pruning finished for projectdir {}/{}".format(username, projectdir))
|
| |
|
| |
|
| |
+ def clean_copr(path, days=DEF_DAYS, verbose=True):
|
| |
+ """
|
| |
+ Remove whole copr build dirs if they no longer contain a RPM file
|
| |
+ """
|
| |
+ loginfo("Cleaning COPR repository...")
|
| |
+ for dir_name in os.listdir(path):
|
| |
+ dir_path = os.path.abspath(os.path.join(path, dir_name))
|
| |
+
|
| |
+ if not os.path.isdir(dir_path):
|
| |
+ continue
|
| |
+ if not os.path.isfile(os.path.join(dir_path, 'build.info')):
|
| |
+ continue
|
| |
+ if is_rpm_in_dir(dir_path):
|
| |
+ continue
|
| |
+ if time.time() - os.stat(dir_path).st_mtime <= days * 24 * 3600:
|
| |
+ continue
|
| |
+
|
| |
+ if verbose:
|
| |
+ loginfo('Removing: ' + dir_path)
|
| |
+ shutil.rmtree(dir_path)
|
| |
+
|
| |
+ # also remove the associated log in the main dir
|
| |
+ build_id = os.path.basename(dir_path).split('-')[0]
|
| |
+ buildlog_name = 'build-' + build_id + '.log'
|
| |
+ buildlog_path = os.path.abspath(os.path.join(path, buildlog_name))
|
| |
+ rm_file(os.path.join(path, buildlog_path))
|
| |
+
|
| |
+
|
| |
+ def rm_file(path, verbose=True):
|
| |
+ """
|
| |
+ Remove file given its absolute path
|
| |
+ """
|
| |
+ if verbose:
|
| |
+ loginfo("Removing: "+path)
|
| |
+ if os.path.exists(path) and os.path.isfile(path):
|
| |
+ os.remove(path)
|
| |
+
|
| |
+
|
| |
+ def is_rpm_in_dir(path):
|
| |
+ files = os.listdir(path)
|
| |
+ srpm_ex = (".src.rpm", ".nosrc.rpm")
|
| |
+ return any([f for f in files if f.endswith(".rpm") and not f.endswith(srpm_ex)])
|
| |
+
|
| |
+
|
| |
def main():
|
| |
args = parser.parse_args()
|
| |
config_file = os.environ.get("BACKEND_CONFIG", "/etc/copr/copr-be.conf")
|
| |
Fix #619
This fix was originally proposed as https://pagure.io/prunerepo/pull-request/1
but it makes more sense to own this part of the code.
This PR additionally adds a
--path
parameter to make the debugging easier. If you don't like it, we can throw it away or move to separate PR.