summaryrefslogtreecommitdiff
path: root/trunk/src
diff options
context:
space:
mode:
authorgenone <genone@gentoo.org>2004-03-31 06:22:35 +0000
committergenone <genone@gentoo.org>2004-03-31 06:22:35 +0000
commit2f1a37c718a8d5a9c65dad661aba411ac1f6bda4 (patch)
tree5c059005aa5a4d63616af4a510befc33d01f1cf3 /trunk/src
parent7784410af1a1465846fdbc527ae69998c957680d (diff)
downloadgentoolkit-2f1a37c718a8d5a9c65dad661aba411ac1f6bda4.tar.gz
glsa-check updates
svn path=/; revision=98
Diffstat (limited to 'trunk/src')
-rw-r--r--trunk/src/glsa-check/glsa-check31
-rw-r--r--trunk/src/glsa-check/glsa.py64
2 files changed, 77 insertions, 18 deletions
diff --git a/trunk/src/glsa-check/glsa-check b/trunk/src/glsa-check/glsa-check
index d59ec08..25d27b9 100644
--- a/trunk/src/glsa-check/glsa-check
+++ b/trunk/src/glsa-check/glsa-check
@@ -4,6 +4,7 @@
# This program is licensed under the GPL, version 2
import os,string,sys
+sys.path.insert(0, "/usr/lib/gentoolkit/pym")
from getopt import getopt,GetoptError
__program__ = "glsa-check"
@@ -75,8 +76,9 @@ if mode == "help":
for o in m[2:-1]:
print "\t" + o
print
- print "glsa-list can contain an arbitrary number of GLSA ids "
- print "or the special identifiers 'all' and 'new'"
+ print "glsa-list can contain an arbitrary number of GLSA ids, "
+ print "filenames containing GLSAs or the special identifiers "
+ print "'all' and 'new'"
print
sys.exit(1)
@@ -97,7 +99,6 @@ if mode == "version":
sys.exit(0)
# delay this for speed increase
-sys.path.insert(0, "/usr/lib/gentoolkit/pym")
from glsa import *
glsaconfig = checkconfig(portage.config(clone=portage.settings))
@@ -149,7 +150,11 @@ if mode == "list":
# dump, fix, inject and fix are nearly the same code, only the glsa method call differs
if mode in ["dump", "fix", "inject", "pretend"]:
for myid in glsalist:
- myglsa = Glsa(myid, glsaconfig)
+ try:
+ myglsa = Glsa(myid, glsaconfig)
+ except GlsaTypeException, e:
+ #print "invalid GLSA: %s (error message was: %s)" % (myid, e)
+ continue
if mode == "dump":
myglsa.dump()
elif mode == "fix":
@@ -165,13 +170,17 @@ if mode in ["dump", "fix", "inject", "pretend"]:
sys.exit(exitcode)
myglsa.inject()
elif mode == "pretend":
+ print "Checking GLSA "+myid
mergelist = myglsa.getMergeList()
- print "The following updates will be performed for this GLSA:"
- for pkg in mergelist:
- # we simplify a bit here
- oldver = portage.db["/"]["vartree"].dbapi.match(portage.dep_getkey(pkg))[-1]
- oldver = oldver[len(portage.dep_getkey(oldver))+1:]
- print " ", pkg, "("+oldver+")"
+ if mergelist:
+ print "The following updates will be performed for this GLSA:"
+ for pkg in mergelist:
+ # we simplify a bit here
+ oldver = portage.db["/"]["vartree"].dbapi.match(portage.dep_getkey(pkg))[-1]
+ oldver = oldver[len(portage.dep_getkey(oldver))+1:]
+ print " ", pkg, "("+oldver+")"
+ else:
+ print "Nothing to do for this GLSA"
elif mode == "inject":
print "injecting " + myid
myglsa.inject()
@@ -179,6 +188,8 @@ if mode in ["dump", "fix", "inject", "pretend"]:
print
print 70*'*'
print
+ else:
+ print
sys.exit(0)
# test is a bit different as Glsa.test() produces no output
diff --git a/trunk/src/glsa-check/glsa.py b/trunk/src/glsa-check/glsa.py
index 4848a89..614ceff 100644
--- a/trunk/src/glsa-check/glsa.py
+++ b/trunk/src/glsa-check/glsa.py
@@ -13,12 +13,16 @@
__author__ = "Marius Mauch <genone@gentoo.org>"
-import os, sys, urllib, time, string, portage, codecs, re
+import os, sys, urllib, time, string, codecs, re
import xml.dom.minidom
sys.path.insert(0, "/usr/lib/portage/pym") # to find portage.py
-opMapping = {"le": "<=", "lt": "<", "eq": "=", "gt": ">", "ge": ">="}
+import portage
+
+# Note: the space for rgt and rlt is important !!
+opMapping = {"le": "<=", "lt": "<", "eq": "=", "gt": ">", "ge": ">=",
+ "rge": ">=~", "rle": "<=~", "rgt": " >~", "rlt": " <~"}
NEWLINE_ESCAPE = "!;\\n" # some random string to mark newlines that should be preserved
def center(text, width):
@@ -263,6 +267,30 @@ def makeVersion(versionNode):
return opMapping[versionNode.getAttribute("range")] \
+getText(versionNode, format="strip")
+def revisionMatch(revisionAtom, portdb):
+ """
+ handler for the special >~, >=~, <=~ and <~ atoms that are supposed to behave
+ as > and < except that they are limited to the same version, the range only
+ applies to the revision part.
+
+ @type revisionAtom: string
+ @param revisionAtom: a <~ or >~ atom that contains the atom to match against
+ @type portdb: portage.dbapi
+ @param portdb: one of the portage databases to use as information source
+
+ @rtype: list of strings
+ @return: a list with the matching versions
+ """
+ mylist = portdb.match(revisionAtom[2:])
+ rValue = []
+ for v in mylist:
+ r1 = "\""+portage.pkgsplit(v)[-1]+"\""
+ r2 = "\""+portage.pkgsplit(revisionAtom[3:])[-1]+"\""
+ if eval(r1+" "+revisionAtom[0:1]+" "+r2):
+ rValue.append(v)
+ return rValue
+
+
def getMinUpgrade(vulnerableList, unaffectedList):
"""
Checks if the systemstate is matching an atom in
@@ -283,11 +311,18 @@ def getMinUpgrade(vulnerableList, unaffectedList):
"""
rValue = None
for v in vulnerableList:
- installed = portage.db["/"]["vartree"].dbapi.match(v)
+ if v[2] == "~":
+ installed = revisionMatch(v, portage.db["/"]["vartree"].dbapi)
+ else:
+ installed = portage.db["/"]["vartree"].dbapi.match(v)
if not installed:
continue
for u in unaffectedList:
- for c in portage.db["/"]["porttree"].dbapi.match(u):
+ if u[2] == "~":
+ mylist = revisionMatch(u, portage.db["/"]["porttree"].dbapi)
+ else:
+ mylist = portage.db["/"]["porttree"].dbapi.match(u)
+ for c in mylist:
c_pv = portage.catpkgsplit(c)
i_pv = portage.catpkgsplit(portage.best(installed))
if portage.pkgcmp(c_pv[1:], i_pv[1:]) > 0 and (rValue == None or portage.pkgcmp(c_pv[1:], rValue) < 0):
@@ -301,9 +336,12 @@ class GlsaTypeException(Exception):
def __init__(self, doctype):
Exception.__init__(self, "wrong DOCTYPE: %s" % doctype)
-class GlsaFormatExceptio(Exception):
+class GlsaFormatException(Exception):
pass
+class GlsaArgumentException(Exception):
+ pass
+
# GLSA xml data wrapper class
class Glsa:
"""
@@ -317,10 +355,17 @@ class Glsa:
@type myid: String
@param myid: String describing the id for the GLSA object (standard
- GLSAs have an ID of the form YYYYMM-nn)
+ GLSAs have an ID of the form YYYYMM-nn) or an existing
+ filename containing a GLSA.
@type myconfig: portage.config
@param myconfig: the config that should be used for this object.
"""
+ if re.match(r'\d{6}-\d{2}', myid):
+ self.type = "id"
+ elif os.path.exists(myid):
+ self.type = "file"
+ else:
+ raise GlsaArgumentException("Given ID "+myid+" isn't a valid GLSA ID or filename.")
self.nr = myid
self.config = myconfig
self.read()
@@ -337,7 +382,10 @@ class Glsa:
repository = "file://" + self.config["GLSA_DIR"]
else:
repository = self.config["GLSA_SERVER"]
- myurl = repository + self.config["GLSA_PREFIX"] + str(self.nr) + self.config["GLSA_SUFFIX"]
+ if self.type == "file":
+ myurl = "file://"+self.nr
+ else:
+ myurl = repository + self.config["GLSA_PREFIX"] + str(self.nr) + self.config["GLSA_SUFFIX"]
self.parse(urllib.urlopen(myurl))
return None
@@ -358,7 +406,7 @@ class Glsa:
elif self.DOM.doctype.systemId != "http://www.gentoo.org/dtd/glsa.dtd":
raise GlsaTypeException(self.DOM.doctype.systemId)
myroot = self.DOM.getElementsByTagName("glsa")[0]
- if myroot.getAttribute("id") != self.nr:
+ if self.type == "id" and myroot.getAttribute("id") != self.nr:
raise GlsaFormatException("filename and internal id don't match:" + myroot.getAttribute("id") + " != " + self.nr)
# the simple (single, required, top-level, #PCDATA) tags first