Package portage :: Package _sets :: Module security
[hide private]

Source Code for Module portage._sets.security

 1  # Copyright 2007-2012 Gentoo Foundation 
 2  # Distributed under the terms of the GNU General Public License v2 
 3   
 4  import portage.glsa as glsa 
 5  from portage._sets.base import PackageSet 
 6  from portage.versions import vercmp 
 7  from portage._sets import get_boolean 
 8   
 9  __all__ = ["SecuritySet", "NewGlsaSet", "NewAffectedSet", "AffectedSet"] 
10   
11 -class SecuritySet(PackageSet):
12 _operations = ["merge"] 13 _skip_applied = False 14 15 description = "package set that includes all packages possibly affected by a GLSA" 16
17 - def __init__(self, settings, vardbapi, portdbapi, least_change=True):
18 super(SecuritySet, self).__init__() 19 self._settings = settings 20 self._vardbapi = vardbapi 21 self._portdbapi = portdbapi 22 self._least_change = least_change
23
24 - def getGlsaList(self, skip_applied):
25 glsaindexlist = glsa.get_glsa_list(self._settings) 26 if skip_applied: 27 applied_list = glsa.get_applied_glsas(self._settings) 28 glsaindexlist = set(glsaindexlist).difference(applied_list) 29 glsaindexlist = list(glsaindexlist) 30 glsaindexlist.sort() 31 return glsaindexlist
32
33 - def load(self):
34 glsaindexlist = self.getGlsaList(self._skip_applied) 35 atomlist = [] 36 for glsaid in glsaindexlist: 37 myglsa = glsa.Glsa(glsaid, self._settings, self._vardbapi, self._portdbapi) 38 #print glsaid, myglsa.isVulnerable(), myglsa.isApplied(), myglsa.getMergeList() 39 if self.useGlsa(myglsa): 40 atomlist += ["="+x for x in myglsa.getMergeList(least_change=self._least_change)] 41 self._setAtoms(self._reduce(atomlist))
42
43 - def _reduce(self, atomlist):
44 mydict = {} 45 for atom in atomlist[:]: 46 cpv = self._portdbapi.xmatch("match-all", atom)[0] 47 pkg = self._portdbapi._pkg_str(cpv, None) 48 cps = "%s:%s" % (pkg.cp, pkg.slot) 49 if not cps in mydict: 50 mydict[cps] = (atom, cpv) 51 else: 52 other_cpv = mydict[cps][1] 53 if vercmp(cpv.version, other_cpv.version) > 0: 54 atomlist.remove(mydict[cps][0]) 55 mydict[cps] = (atom, cpv) 56 return atomlist
57
58 - def useGlsa(self, myglsa):
59 return True
60
61 - def updateAppliedList(self):
62 glsaindexlist = self.getGlsaList(True) 63 applied_list = glsa.get_applied_glsas(self._settings) 64 for glsaid in glsaindexlist: 65 myglsa = glsa.Glsa(glsaid, self._settings, self._vardbapi, self._portdbapi) 66 if not myglsa.isVulnerable() and not myglsa.nr in applied_list: 67 myglsa.inject()
68
69 - def singleBuilder(cls, options, settings, trees):
70 least_change = not get_boolean(options, "use_emerge_resolver", False) 71 return cls(settings, trees["vartree"].dbapi, trees["porttree"].dbapi, least_change=least_change)
72 singleBuilder = classmethod(singleBuilder)
73
74 -class NewGlsaSet(SecuritySet):
75 _skip_applied = True 76 description = "Package set that includes all packages possibly affected by an unapplied GLSA"
77
78 -class AffectedSet(SecuritySet):
79 description = "Package set that includes all packages affected by an unapplied GLSA" 80
81 - def useGlsa(self, myglsa):
82 return myglsa.isVulnerable()
83
84 -class NewAffectedSet(AffectedSet):
85 _skip_applied = True 86 description = "Package set that includes all packages affected by an unapplied GLSA"
87