-
Notifications
You must be signed in to change notification settings - Fork 7
/
find-security-updates
executable file
·125 lines (99 loc) · 3.66 KB
/
find-security-updates
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Script to list security udpates for a given repository.
#
# Usage: (can work for both source and binary)
#
# script -> to search for default target
# script pardus-2009 -> to search in pardus-2009 repos
# script http://packages.pardus.org.tr/pardus-2009-test/pisi-index.xml.bz2 /svn/stable/pisi-index.xml.bz2 -> to search using test repo and source stable index
#
import os
import sys
import urllib2
import piksemel
import bz2
import lzma
distroBase = "http://packages.pardus.org.tr/pardus-2009"
def loadUrl(_url):
try:
return urllib2.urlopen(_url).read()
except urllib2.URLError:
print "could not download %s" % _url
sys.exit(1)
def getLastSecurity(parent):
xnode = parent.getTag("History").tags("Update")
for tag in xnode:
release = tag.getAttribute("release")
updatetime = tag.getTagData("Date")
if tag.getAttribute("type") == "security" or tag.getTagData("Type") == "security":
return int(release), updatetime
return 0, "never"
def unpackXml(url, isStable):
pkglist = {}
if url.startswith("http"):
compressedData = loadUrl(url)
else:
compressedData = open(url).read()
if url.endswith("bz2"):
rawData = bz2.decompress(compressedData)
elif url.endswith("xz"):
rawData = lzma.decompress(compressedData)
else:
rawData = compressedData
index = piksemel.parseString(rawData)
hasSpecFile = index.getTag("SpecFile")
if hasSpecFile:
for parent in index.tags("SpecFile"):
pkgname = parent.getTag("Source").getTagData("Name")
pkguri = None # this is source repo
srcname = pkgname
lastSecurity, securityUpdate = getLastSecurity(parent)
if lastSecurity or isStable:
pkglist[pkgname] = [lastSecurity, securityUpdate, pkguri, srcname]
else:
for parent in index.tags("Package"):
pkgname = parent.getTagData("Name")
pkguri = parent.getTagData("PackageURI")
srcname = parent.getTag("Source").getTagData("Name")
lastSecurity, securityUpdate = getLastSecurity(parent)
if lastSecurity or isStable:
pkglist[pkgname] = [lastSecurity, securityUpdate, pkguri, srcname]
return pkglist
def parsePackages(stablePackages, develPackages):
updateDict = {}
stablePackages = stableIndex.keys()
stablePackages.sort()
for i in stablePackages:
if develIndex.has_key(i):
if develIndex[i][0] > stableIndex[i][0]:
pkg = develIndex[i]
if updateDict.has_key(pkg[3]):
updateDict[pkg[3]][2].append(pkg[2])
else:
updateDict[pkg[3]] = pkg[1], pkg[0], [pkg[2]]
return updateDict
if __name__ == "__main__":
if len(sys.argv) == 3:
toIndex = sys.argv[2]
fromIndex = sys.argv[1]
elif len(sys.argv) == 2:
distroBase = "http://packages.pardus.org.tr/%s" % sys.argv[1]
toIndex = "%s/pisi-index.xml.bz2" % distroBase
fromIndex= "%s-test/pisi-index.xml.bz2" % distroBase
else:
toIndex = "%s/pisi-index.xml.bz2" % distroBase
fromIndex= "%s-test/pisi-index.xml.bz2" % distroBase
stableIndex = unpackXml(toIndex, True) # True means it is a target repo
develIndex = unpackXml(fromIndex, False)
pkg = parsePackages(stableIndex, develIndex)
pkglist = pkg.keys()
pkglist.sort()
print ""
for i in pkglist:
print "%s (%s, release %d)" % (i, pkg[i][0], pkg[i][1])
for p in pkg[i][2]:
if p:
print " %s" % p
print ""