#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright 2010 Red Hat, Inc. # License: GPLv2 # Author: Dan HorĂ¡k # # sync package list between primary and secondary kojis # import sys import os import koji import time import string import rpm import shutil # get packages from command line if len(sys.argv) > 2: SECONDARY_ARCH = sys.argv[1] tag = sys.argv[2] else: print("sync package list between primary and secondary koji") print("Usage: %s " % sys.argv[0]) exit(0) LOCALKOJIHUB = 'https://%s.koji.fedoraproject.org/kojihub' % (SECONDARY_ARCH) REMOTEKOJIHUB = 'https://koji.fedoraproject.org/kojihub' # Should probably set these from a koji config file SERVERCA = os.path.expanduser('~/.fedora-server-ca.cert') CLIENTCA = os.path.expanduser('~/.fedora-upload-ca.cert') CLIENTCERT = os.path.expanduser('~/.fedora.cert') localkojisession = koji.ClientSession(LOCALKOJIHUB) localkojisession.ssl_login(CLIENTCERT, CLIENTCA, SERVERCA) remotekojisession = koji.ClientSession(REMOTEKOJIHUB) remotekojisession.ssl_login(CLIENTCERT, CLIENTCA, SERVERCA) local_pkgs = sorted(localkojisession.listPackages(tagID=tag, inherited=True), key = lambda pkg: pkg['package_name']) remote_pkgs = sorted(remotekojisession.listPackages(tagID=tag, inherited=True), key = lambda pkg: pkg['package_name']) local_num = len(local_pkgs) remote_num = len(remote_pkgs) local = 0 remote = 0 #print "pkgs local=%d remote=%d" % (local_num, remote_num) while (local < local_num) or (remote < remote_num): #print "local=%d remote=%d" % (local, remote) if remote_pkgs[remote]['package_name'] == local_pkgs[local]['package_name']: print "%s in both" % (remote_pkgs[remote]['package_name']) if remote_pkgs[remote]['blocked'] != local_pkgs[local]['blocked']: # print "\tremote blocked = %s, local blocked = %s" % (remote_pkgs[remote]['blocked'], local_pkgs[local]['blocked']) print "\tsetting blocked to %s" % (remote_pkgs[remote]['blocked']) if remote_pkgs[remote]['blocked'] == True and not (local_pkgs[local]['package_name'] in [ 's390utils' ]): localkojisession.packageListBlock(tag, remote_pkgs[remote]['package_name']) elif remote_pkgs[remote]['blocked'] == False: localkojisession.packageListUnblock(tag, remote_pkgs[remote]['package_name']) # break remote += 1 local += 1 elif remote_pkgs[remote]['package_name'] > local_pkgs[local]['package_name']: print "%s only locally" % (local_pkgs[remote]['package_name']) local += 1 elif remote_pkgs[remote]['package_name'] < local_pkgs[local]['package_name']: print "%s only remote" % (remote_pkgs[remote]['package_name']) # print "pkg=%s" % (remote_pkgs[remote]) if remote_pkgs[remote]['blocked'] != True: print "\tadding with owner %s" % (remote_pkgs[remote]['owner_name']) user = localkojisession.getUser(remote_pkgs[remote]['owner_name']) if not user: print "\t\tcreating owner" localkojisession.createUser(remote_pkgs[remote]['owner_name'], status=koji.USER_STATUS['NORMAL']) localkojisession.packageListAdd(remote_pkgs[remote]['tag_name'], remote_pkgs[remote]['package_name'], remote_pkgs[remote]['owner_name'], False) else: print "\tbut blocked there" remote += 1