-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfind-delta-packages-to-merge
executable file
·131 lines (96 loc) · 3.42 KB
/
find-delta-packages-to-merge
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# utility to parse binary package file list gathered from http index
# and finds delta packages that can be merged within a new pisi file
#
# internal package name flow is without pisi extensions, like
# xulrunner-devel-11-13.delta
# zd1211-firmware-1.4-3-2
import httplib
import sys
repoBase = "packages.pardus.org.tr"
repoName = "pardus-2009"
pisiPrefix = ".pisi"
deltaPrefix = ".delta"
def getHttp(addr):
root, base = addr.split("/", 1)
conn = httplib.HTTPConnection(root)
conn.request("GET", "/%s/" % base)
r = conn.getresponse()
if r.reason != "OK":
print "Fetching file list returned error %s %s" % (r.status, r.reason)
sys.exit(1)
data = r.read().split("\n")
return data
def getFileList(addr):
fileList = []
data = getHttp(addr)
prefix = '%s">' % pisiPrefix
for line in data:
if prefix in line:
# this can be done with a nice html parser but it does the job for now
line.replace('HREF="', 'href="', 1)
f = line[line.find("href=")+6:line.find("%s" % prefix)]
fileList.append(f)
return fileList
def parseFileList(fileList):
fileList.sort()
# deltas[module-virtualbox] = [['11', '13'], ['11', '14'], ['13', '14']]
deltas = {}
# normals[yasm] = [['5', 'yasm-0.8.0-2-5'], ['5', 'yasm-0.8.0-2-5']]
normals = {}
for i in fileList:
if i.endswith(deltaPrefix):
n, f, t = i.replace(deltaPrefix, "").rsplit("-", 2)
if n in deltas:
deltas[n].append([f, t])
else:
deltas[n] = [[f, t]]
else:
n, v, r, b = i.rsplit("-", 3)
if n in normals:
normals[n].append([b, i])
else:
normals[n] = [[b, i]]
return deltas, normals
def getDeltas(target, stablePkg, testDelta, stableDelta):
deltalist = []
pkgname, v, r, buildno = target.replace(pisiPrefix, "").rsplit("-", 3)
if not testDelta.has_key(pkgname) or not stablePkg.has_key(pkgname):
return deltalist
fromList = [a[0] for a in stablePkg[pkgname]]
for i in fromList:
if [i, buildno] in testDelta[pkgname]:
addToList = True
if stableDelta.has_key(pkgname):
if [i, buildno] in stableDelta[pkgname]:
addToList = False
if addToList:
deltalist.append("%s-%s-%s%s%s" % (pkgname, i, buildno, deltaPrefix, pisiPrefix))
addToList = False
else:
print "could not find a delta for %s-%s-%s%s%s" % (pkgname, i, buildno, deltaPrefix, pisiPrefix)
return deltalist
def usage():
print "please give a list of pisi files"
if __name__ == "__main__":
if len(sys.argv) < 2:
usage()
sys.exit(1)
else:
sourcePackages = sys.argv[1:]
stableFiles = getFileList("%s/%s" % (repoBase, repoName))
testFiles = getFileList("%s/%s-test" % (repoBase, repoName))
stableDelta, stableNormal = parseFileList(stableFiles)
testDelta, testNormal = parseFileList(testFiles)
foundDeltas = []
for i in sourcePackages:
target = i.replace(pisiPrefix, "")
if not target in testFiles:
print "package not found %s" % i
else:
foundDeltas.extend(getDeltas(target, stableNormal, testDelta, stableDelta))
foundDeltas.sort()
for i in foundDeltas:
print i