-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlist-component-owners-and-packages
executable file
·133 lines (95 loc) · 3.32 KB
/
list-component-owners-and-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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Pretty printer for repo index components
# Can work with either pisi-index.xml in CWD or remote index given as first parameter
#
# TODO:
# really pretty print
# work with binary index
# parameters for verbose, and / or one component
#
import os
import sys
import urllib2
import bz2
import lzma
import piksemel
defaultIndexFile = "pisi-index.xml"
def getIndex(uri):
try:
if "://" in uri:
rawdata = urllib2.urlopen(uri).read()
else:
rawdata = open(uri, "r").read()
except IOError:
print "could not fetch %s" % uri
return None
if uri.endswith("bz2"):
data = bz2.decompress(rawdata)
elif uri.endswith("xz") or uri.endswith("lzma"):
data = lzma.decompress(rawdata)
else:
data = rawdata
return piksemel.parseString(data)
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 = [PackagePartOf, PackageName]
if not PackagePackagerName in packageOf:
packageOf[PackagePackagerName] = []
packageOf[PackagePackagerName].append(fullpath)
def fillComponentDict(tag, _hasSpecFile, componentDict):
componentName = tag.getTagData("Name")
maintainerName = tag.getTag("Maintainer").getTagData("Name")
componentDict[componentName] = maintainerName
def parseIndexData(_index):
packageOf = {}
componentDict = {}
hasSpecFile = _index.getTag("SpecFile")
if hasSpecFile:
for i in _index.tags("SpecFile"):
parent = i.getTag("Source")
fillPackageDict(parent, hasSpecFile, packageOf)
for k in _index.tags("Component"):
fillComponentDict(k, hasSpecFile, componentDict)
else:
for parent in _index.tags("Package"):
fillPackageDict(parent, hasSpecFile, packageOf)
return packageOf, componentDict
def printComponentStats(packager, component):
packagerByComponent = {}
componentList = component.keys()
componentList.sort()
for p in packager:
for pkgcomponent, pkgname in packager[p]:
if pkgcomponent in packagerByComponent:
packagerByComponent[pkgcomponent].append(p)
else:
packagerByComponent[pkgcomponent] = [p]
for i in componentList:
print
stroffset = " " * 4 * i.count(".")
componentName = i.split(".")[-1]
componentOwner = component[i]
print "%s* %s (%s)" % (stroffset, componentName, componentOwner)
try:
packagerList = packagerByComponent[i]
packagerList = list(set(packagerList))
packagerList.sort()
for k in packagerList:
print " %s%s (%i)" % (stroffset, k, packagerByComponent[i].count(k))
except KeyError:
continue
if __name__ == "__main__":
if len(sys.argv) > 1:
indexFile = sys.argv[1]
else:
indexFile = defaultIndexFile
xmldata = getIndex(indexFile)
packagers, components = parseIndexData(xmldata)
printComponentStats(packagers, components)