move checkfile parsing into its own function
authorMarius Mauch <genone@gentoo.org>
Fri, 9 Nov 2007 15:38:48 +0000 (15:38 -0000)
committerMarius Mauch <genone@gentoo.org>
Fri, 9 Nov 2007 15:38:48 +0000 (15:38 -0000)
svn path=/main/trunk/; revision=8479

bin/glsa-check
pym/portage/glsa.py
pym/portage/sets/security.py

index d79dda6fb4adc4f037ad61cf20e3c9f9279b045c..8d955526af179b07cd58e268bb330c4d0d6c9356 100644 (file)
@@ -126,15 +126,11 @@ from portage.glsa import *
 
 vardb = portage.db[portage.settings["ROOT"]]["vartree"].dbapi
 portdb = portage.db["/"]["porttree"].dbapi
-checkfile = os.path.join(portage.settings["ROOT"], CACHE_PATH.lstrip(os.sep), "glsa")
 
 # build glsa lists
 completelist = get_glsa_list(portage.settings)
 
-if os.access(checkfile, os.R_OK):
-       checklist = [line.strip() for line in open(checkfile, "r").readlines()]
-else:
-       checklist = []
+checklist = get_applied_glsas(portage.settings)
 todolist = [e for e in completelist if e not in checklist]
 
 glsalist = []
index 91f719c8f0812b5543db390642e3ed20fde5204f..2d2f27b3039ac405e560ea7d640e35dc700553e7 100644 (file)
@@ -19,6 +19,18 @@ opMapping = {"le": "<=", "lt": "<", "eq": "=", "gt": ">", "ge": ">=",
 NEWLINE_ESCAPE = "!;\\n"       # some random string to mark newlines that should be preserved
 SPACE_ESCAPE = "!;_"           # some random string to mark spaces that should be preserved
 
+def get_applied_glsas(settings):
+       """
+       Return a list of applied or injected GLSA IDs
+       
+       @type   settings: portage.config
+       @param  settings: portage config instance
+       @rtype:         list
+       @return:        list of glsa IDs
+       """
+       return grabfile(os.path.join(os.sep, settings["ROOT"], CACHE_PATH.lstrip(os.sep), "glsa"))
+
+
 # TODO: use the textwrap module instead
 def wrap(text, width, caption=""):
        """
@@ -553,8 +565,7 @@ class Glsa:
                @rtype:         Boolean
                @returns:       True if the GLSA was applied, False if not
                """
-               aList = grabfile(os.path.join(os.sep, self.config["ROOT"], CACHE_PATH.lstrip(os.sep), "glsa"))
-               return (self.nr in aList)
+               return (self.nr in get_applied_glsas())
 
        def inject(self):
                """
index a172e6f8c06fdc203dcab2c9c2e08633342f62cd..24661a42ede8d5c06a8f46cc5a274bab8c87dad3 100644 (file)
@@ -5,7 +5,6 @@
 import os
 import portage.glsa as glsa
 from portage.util import grabfile, write_atomic
-from portage.const import CACHE_PATH
 from portage.sets.base import PackageSet
 
 __all__ = ["SecuritySet", "NewGlsaSet", "NewAffectedSet", "AffectedSet"]
@@ -21,13 +20,12 @@ class SecuritySet(PackageSet):
                self._settings = settings
                self._vardbapi = vardbapi
                self._portdbapi = portdbapi
-               self._checkfile = os.path.join(os.sep, self._settings["ROOT"], CACHE_PATH.lstrip(os.sep), "glsa")
                self._least_change = least_change
 
        def getGlsaList(self, skip_applied):
                glsaindexlist = glsa.get_glsa_list(self._settings)
                if skip_applied:
-                       applied_list = grabfile(self._checkfile)
+                       applied_list = glsa.get_applied_glsas(self._settings)
                        glsaindexlist = set(glsaindexlist).difference(applied_list)
                        glsaindexlist = list(glsaindexlist)
                glsaindexlist.sort()
@@ -48,12 +46,11 @@ class SecuritySet(PackageSet):
 
        def updateAppliedList(self):
                glsaindexlist = self.getGlsaList(True)
-               applied_list = grabfile(self._checkfile)
+               applied_list = glsa.get_applied_glsas(self._settings)
                for glsaid in glsaindexlist:
                        myglsa = glsa.Glsa(glsaid, self._settings, self._vardbapi, self._portdbapi)
-                       if not myglsa.isVulnerable():
-                               applied_list.append(glsaid)
-               write_atomic(self._checkfile, "\n".join(applied_list))
+                       if not myglsa.isVulnerable() and not myglsa.nr in applied_list:
+                               myglsa.inject()
        
        def singleBuilder(cls, options, settings, trees):
                if "use_emerge_resoler" in options \