From d042fff18f2b7621dc0ec11c57e9c5b1936c8ca2 Mon Sep 17 00:00:00 2001 From: Marius Mauch Date: Fri, 9 Nov 2007 15:38:48 +0000 Subject: move checkfile parsing into its own function svn path=/main/trunk/; revision=8479 --- pym/portage/glsa.py | 15 +++++++++++++-- pym/portage/sets/security.py | 11 ++++------- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'pym') diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py index 91f719c8f..2d2f27b30 100644 --- a/pym/portage/glsa.py +++ b/pym/portage/glsa.py @@ -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): """ diff --git a/pym/portage/sets/security.py b/pym/portage/sets/security.py index a172e6f8c..24661a42e 100644 --- a/pym/portage/sets/security.py +++ b/pym/portage/sets/security.py @@ -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 \ -- cgit v1.2.3-1-g7c22