#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright 2014 Red Hat, Inc. # License: GPLv2 # Author: Dan HorĂ¡k # # Compare the content of a tag between 2 koji instances # import sys import os import koji import time import string import rpm import shutil tag = 'f21' LOCALKOJIHUB = 'http://ppc-le.koji.fedoraproject.org/kojihub' REMOTEKOJIHUB = 'http://ppc.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') def _rpmvercmp ((e1, v1, r1), (e2, v2, r2)): """find out which build is newer""" if e1 == "None": e1 = "0" if e2 == "None": e2 = "0" rc = rpm.labelCompare((e1, v1, r1), (e2, v2, r2)) if rc == 1: #first evr wins return 1 elif rc == 0: #same evr return 0 else: #second evr wins return -1 def _countMissing (build): """find how many builds are missing in local koji""" builds = remotekojisession.listTagged(tag, inherit=True, package=build['package_name']) cnt = 0 local_evr = (str(build['epoch']), build['version'], build['release']) # print "local=%s" % build for b in builds: # print "remote[%d]=%s" % (cnt, b) remote_evr = (str(b['epoch']), b['version'], b['release']) newestRPM = _rpmvercmp(local_evr, remote_evr) if newestRPM == 0 or newestRPM == 1: break cnt += 1 if cnt > 5: break return cnt localkojisession = koji.ClientSession(LOCALKOJIHUB) remotekojisession = koji.ClientSession(REMOTEKOJIHUB) all_local_builds = sorted(localkojisession.listTagged(tag, inherit=False, latest=False), key = lambda pkg: pkg['nvr']) all_remote_builds = sorted(remotekojisession.listTagged(tag, inherit=False, latest=True), key = lambda pkg: pkg['nvr']) for remote_build in all_remote_builds: print("package=%s nvr=%s" % (remote_build['package_name'], remote_build['nvr'])), # found = False; for b in all_local_builds: if remote_build['nvr'] == b['nvr']: print("\tOK") found = True; break; if not found: print("\tmissing") remote_evr = (str(remote_build['epoch']), remote_build['version'], remote_build['release']) for local_build in localkojisession.listTagged(tag, inherit=False, package=remote_build['package_name']): print("comparing...") local_evr = (str(local_build['epoch']), local_build['version'], local_build['release']) res = _rpmvercmp(local_evr, remote_evr) if res == 1: print("local is newer %s" % (local_build['nvr'])) # break if res == -1: print("local is older %s" % (local_build['nvr'])) break # if remote_build['package_name'] > "a": # break