#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright 2013 Red Hat, Inc. # License: GPLv2 # Author: Dan HorĂ¡k # # Backup all RPMs for all builds in a tag to a specified location # import sys import os import koji import time import string import rpm import shutil # get tag from command line if len(sys.argv) > 3: SECONDARY_ARCH = sys.argv[1] tag = sys.argv[2] location = sys.argv[3] else: print("Backup all RPMs for all builds in a tag to a specified location") print("Usage: %s " % sys.argv[0]) exit(0) LOCALKOJIHUB = 'http://%s.koji.fedoraproject.org/kojihub' % (SECONDARY_ARCH) backupdir = '%s/%s' % (location, tag) localkojisession = koji.ClientSession(LOCALKOJIHUB) print("Reading list of builds for tag %s from %s ..." % (tag, LOCALKOJIHUB)) builds = sorted(localkojisession.listTagged(tag, inherit=False, latest=True), key = lambda pkg: pkg['package_name']) print("done") for build in builds: pkgdir = "/" + build['package_name'][0] + "/%(package_name)s" % build pkgverreldir = pkgdir + "/%(version)s/%(release)s" % build pkgbackupdir = backupdir + pkgverreldir builddir = koji.pathinfo.build(build) try: print("checking dir %s ..." % (pkgbackupdir)) os.stat(pkgbackupdir) except OSError: print("target dir doesn't exist, deleting old ones") shutil.rmtree(backupdir + pkgdir, True) os.makedirs(pkgbackupdir) else: print("target dir already exists, skipping") continue rpms = localkojisession.listRPMs(buildID=build['id']) for rinfo in rpms: rpmpath = os.path.join(builddir, koji.pathinfo.rpm(rinfo)) print("copying %s to %s" % (rpmpath, pkgbackupdir)) shutil.copy2(rpmpath, pkgbackupdir)