#!/usr/bin/python -tt # Author: Toshio Kuratomi # Date: June 14, 2007 ''' Merge Fedora Extras and Fedora Core packages in owners.list so we end up with one set of packages for one Product, Fedora. ''' import sys #OWNERS='/home/fedora/toshio/owners/owners.list' try: OWNERS=sys.argv[1] except IndexError: print '''owners-merge.py owners.list > newowners.list This script merges the Fedora Core and Fedora Extras products in owners.list into a single product called Fedora. Give the present owners.list file as the only argument to the script. Redirect stdout to the new owners.list file you are creating. ''' sys.exit(1) class Package(object): def __init__(self, product, component, description, owners, qacontact, cclist): self.product = product or 'Fedora' self.component = component self.description = description self.owners = owners or [] self.qacontact = qacontact self.cclist = cclist or [] class Packages(dict): '''It's the hash that acts like an array.''' def __setitem__(self, key, value): if key: raise KeyError, 'Packages can only set a null key' # Parse the value into pieces t = value.split('|', 6) product, component, desc, owners, qa, cc = value.split('|', 6) ownerList = owners.split(',') ccList = None cc = cc.strip() if cc: ccList = cc.split(',') if owners == 'extras-orphan@fedoraproject.org': ownerList = None if self.has_key(component): # Merge the pieces into an existing Package oldPackage = super(Packages, self).__getitem__(component) if product == 'Fedora Core': # Take precedence if ownerList: if oldPackage.owners: for maintainer in oldPackage.owners: if maintainer not in ownerList: ownerList.append(maintainer) oldPackage.owners = ownerList else: oldPackage.owners = ownerList if ccList: if oldPackage.cclist: for watcher in oldPackage.cclist: if watcher not in ccList: ccList.append(watcher) oldPackage.cclist = ccList else: oldPackage.cclist = ccList else: # Append if ownerList: if oldPackage.owners: for maintainer in ownerList: if maintainer not in oldPackage.owners: oldPackage.owners.append(maintainer) else: oldPackage.owners = ownerList if ccList: if oldPackage.cclist: for watcher in ccList: if watcher not in oldPackage.cclist: oldPackage.cclist.append(ccList) else: oldPackage.cclist = ccList else: # Create a new Package newPackage = Package('Fedora', component, desc, ownerList, qa, ccList) super(Packages, self).__setitem__(component, newPackage) def __getitem__(self, key): # Retrieve a string for the Package pkg = super(Packages, self).__getitem__(key) if not pkg.owners: owners = 'extras-orphan@fedoraproject.org' else: owners = ','.join(pkg.owners) cclist = ','.join(pkg.cclist) return '%s|%s|%s|%s|%s|%s' % (pkg.product, pkg.component, pkg.description, owners, pkg.qacontact, cclist) if __name__ == '__main__': output = [] owners = file(OWNERS, 'r') packages = Packages() for line in owners: if line.strip().startswith('#'): output.append(line.rstrip()) continue packages[None] = line pkgList = packages.keys() pkgList.sort() print '\n'.join(output) for pkg in pkgList: print packages[pkg] sys.exit(0)