-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlist-missing-packages-for-distupdate
executable file
·131 lines (96 loc) · 3.29 KB
/
list-missing-packages-for-distupdate
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 -*-
import os
import sys
import bz2
import lzma # install python-pyliblzma if you are using Pardus 2009
import urllib2
import piksemel
import pisi
defaultNextRepoURI = "http://packages.pardus.org.tr/pardus/2011/testing/i686/pisi-index.xml.xz"
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 uniq(i):
return list(set(i))
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 parseRepoIndex(_file):
pkgprop = {}
obsoletelist = []
ix = getIndex(_file)
obsoleteParent = ix.getTag("Distribution").getTag("Obsoletes")
for node in obsoleteParent.tags("Package"):
obsoletelist.append(node.firstChild().data())
for i in ix.tags("Package"):
replaceslist = []
pkgName = i.getTagData("Name")
pkgURI = i.getTagData("PackageURI")
pkgSize = i.getTagData("PackageSize")
pkgHash = i.getTagData("PackageHash")
pkgInstalledSize = i.getTagData("InstalledSize")
replacedPackages = i.getTag("Replaces")
if replacedPackages:
for replaced in replacedPackages.tags("Package"):
replaceslist.append(replaced.firstChild().data())
pkgprop[pkgName] = [replaceslist, pkgURI, pkgSize, pkgInstalledSize, pkgHash]
return pkgprop, obsoletelist
def getInstalledPackages():
a = pisi.api.list_installed()
a.sort()
return a
def getDistroDiff(installed, nextRepo, obsoletes):
pkglist = []
replacedBy = {}
neededPackages = []
# we make a cache of replaced packages, not to iterate over and over on package dict
for i in nextRepo:
pkglist.append(i)
for r in nextRepo[i][0]:
pkglist.append(r)
if r in replacedBy:
replacedBy[r].append(i)
else:
replacedBy[r] = [i]
pkglist.extend(obsoletes)
uniqpkglist = uniq(pkglist)
for i in installed:
if i not in uniqpkglist:
neededPackages.append(i)
return neededPackages
def findMissingPackagesForDistupdate(nextRepoURI):
# parseRepoIndex returns dictionary as package[NAME] = [Replaces, PISIfile, Size, Installedsize, Checksum]
# and obsoleted package name list as second arg
nextRepo, nextRepoObsoletes = parseRepoIndex(nextRepoURI)
installedPackages = getInstalledPackages()
neededPackages = getDistroDiff(installedPackages, nextRepo, nextRepoObsoletes)
return neededPackages
if __name__ == "__main__":
if len(sys.argv) > 1:
newRepoURI = sys.argv[1]
else:
newRepoURI = defaultNextRepoURI
print "working on %s" % newRepoURI
neededPackages = findMissingPackagesForDistupdate(newRepoURI)
for i in neededPackages:
print i