-
Notifications
You must be signed in to change notification settings - Fork 7
/
find-urgent-packages
executable file
·93 lines (73 loc) · 2.63 KB
/
find-urgent-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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import piksemel
import bz2
import sys
import os
indexFileName = "pisi-index.xml"
def loadFile(_file):
try:
f = file(_file)
d = [a.lstrip().rstrip("\n") for a in f]
d = filter(lambda x: not (x.startswith("#") or x == ""), d)
f.close()
return d
except:
return []
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 findRequiredPackages(packageList, packagersList):
pkgdict = {}
for pkg in packageList:
for packager in packagersList:
for sourcePackage in packagersList[packager]:
if sourcePackage.endswith("/%s" % pkg):
if not packager in pkgdict:
pkgdict[packager] = []
pkgdict[packager].append(pkg)
return pkgdict
if __name__ == "__main__":
if len(sys.argv) < 2:
print " usage:"
print " %s <devel indexfile path> <required packages file>" % sys.argv[0]
else:
indexfile = "%s/%s" % (sys.argv[1], indexFileName)
packageList = loadFile(sys.argv[2])
xmldata = getXmlData(indexfile)
packagers = parseXmlData(xmldata)
requiredPackages = findRequiredPackages(packageList, packagers)
tmp = requiredPackages.keys()
tmp.sort()
for i in tmp:
print "-> %s" % i
for k in requiredPackages[i]:
print "\t%s" % k