-
Notifications
You must be signed in to change notification settings - Fork 7
/
check-repo-index-consistency
executable file
·113 lines (88 loc) · 2.92 KB
/
check-repo-index-consistency
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# tool to find dependency inconsistencies in repositories
# can work on both source and binary index
# can work with local or remote files
# supports multiple inputs
#
import os
import sys
import urllib2
import bz2
import lzma
import pisi
import piksemel
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 data.replace("<PISI>", "").replace("</PISI>", "")
def convertToRepoDB(ix):
doc = piksemel.parseString(ix)
dbobj = pisi.index.Index()
dbobj.decode(doc, [])
return dbobj
def printMissing(pkgname, pkgprop, latest, isruntime):
depstr = "runtime dep" if isruntime else "build dep"
if latest != pkgname:
print "\n %s" % pkgname
print " %s %s" % (depstr, pkgprop)
def checkRepoDB(repodb):
if len(repodb.specs):
print "found source index"
repodict = {}
for spec in repodb.specs:
for package in spec.packages:
package.version = spec.history[0].version
package.release = spec.history[0].release
repodict[package.name] = package
latest = ""
for spec in repodb.specs:
for d in spec.source.buildDependencies:
if not d.satisfied_by_dict_repo(repodict):
printMissing(spec.source.name, str(d), latest, False)
latest = spec.source.name
for package in spec.packages:
for d in package.runtimeDependencies():
if not d.satisfied_by_dict_repo(repodict):
printMissing(package.name, str(d), latest, True)
latest = package.name
else:
print "found binary index"
repodict = dict((pkg.name, pkg) for pkg in repodb.packages)
latest = ""
for package in repodb.packages:
for d in package.runtimeDependencies():
if not d.satisfied_by_dict_repo(repodict):
printMissing(package.name, str(d), latest, True)
latest = package.name
if __name__ == "__main__":
print
if len(sys.argv) > 1:
targets = sys.argv[1:]
else:
targets = ["pisi-index.xml"]
print "* working on"
for i in targets:
print " %s" % i
# FIXME: find a way to update iksemel object with another one
srcstring = "<PISI>"
for indexfile in targets:
srcstring += getIndex(indexfile)
srcstring += "</PISI>"
if srcstring != "":
repo = convertToRepoDB(srcstring)
checkRepoDB(repo)
print