#!/usr/bin/python # -*- coding: utf-8 -*- import piksemel import bz2 import sys import os indexfile = "pisi-index.xml" def getXmlData(_file): if os.path.exists(_file): return piksemel.parse(_file) elif os.path.exists("%s.bz2" % _file): indexdata = bz2.decompress(file("%s.bz2" % _file).read()) return piksemel.parseString(indexdata) else: print "%s not found" % indexfile sys.exit(1) def fillPackageDict(tag, _hasSpecFile, packageOf): PackagePartOf = tag.getTagData("PartOf") PackageName = tag.getTagData("Name") if _hasSpecFile: PackagePackagerName = tag.getTag("Packager").getTagData("Name") else: PackagePackagerName = tag.getTag("Source").getTag("Packager").getTagData("Name") fullpath = "%s/%s" % (PackagePartOf.replace(".", "/"), PackageName) if not PackagePackagerName in packageOf: packageOf[PackagePackagerName] = [] packageOf[PackagePackagerName].append(fullpath) def parseXmlData(_index): packageOf = {} hasSpecFile = _index.getTag("SpecFile") if hasSpecFile: for i in _index.tags("SpecFile"): parent = i.getTag("Source") fillPackageDict(parent, hasSpecFile, packageOf) else: for parent in _index.tags("Package"): fillPackageDict(parent, hasSpecFile, packageOf) return packageOf def printPackagesOf(owner, xmldata, escape=""): packages = xmldata[owner] packages.sort() for package in packages: print "%s%s" % (escape, package) def ladderPrint(_dict, pkgs = False): owners = _dict.keys() owners.sort() for owner in owners: print "%s (%i)" % (owner, len(_dict[owner])) if pkgs: printPackagesOf(owner, _dict, " ") if __name__ == "__main__": xmldata = getXmlData(indexfile) packagers = parseXmlData(xmldata) if len(sys.argv) == 1: ladderPrint(packagers, pkgs = True) else: arg = sys.argv[1] if arg == "owners": ladderPrint(packagers) elif arg in packagers: printPackagesOf(arg, packagers) else: print "%s does not have any package" % arg