forked from Pardus-Linux/scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist-repo-packages
executable file
·81 lines (63 loc) · 2.18 KB
/
list-repo-packages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/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