portage.glsa module¶
- class portage.glsa.Glsa(myid, myconfig, vardbapi, portdbapi)¶
Bases:
object
This class is a wrapper for the XML data and provides methods to access and display the contained data.
- dump(outstream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, encoding='utf-8')¶
Dumps a plaintext representation of this GLSA to I{outfile} or B{stdout} if it is ommitted. You can specify an alternate I{encoding} if needed (default is utf-8).
- Parameters
outfile – Stream that should be used for writing (defaults to sys.stdout)
- getAffectionTable(least_change=True)¶
Will initialize the self.systemAffection list of atoms installed on the system that are affected by this GLSA, and the atoms that are minimal upgrades.
- getMergeList(least_change=True)¶
Returns the list of package-versions that have to be merged to apply this GLSA properly. The versions are as low as possible while avoiding downgrades (see
getMinUpgrade
).- Parameters
least_change (Boolean) – True if the smallest possible upgrade should be selected, False for an emerge-like algorithm
- Return type
List of Strings
- Returns
list of package-versions that have to be merged
- inject()¶
Puts the ID of this GLSA into the GLSA checkfile, so it won’t show up on future checks. Should be called after a GLSA is applied or on explicit user request.
- Return type
None
- Returns
None
- isInjected()¶
Looks if the GLSA ID is in the GLSA checkfile to check if this GLSA should be marked as applied.
- Return type
Boolean
- Returns
True if the GLSA is in the inject file, False if not
- isVulnerable()¶
Tests if the system is affected by this GLSA by checking if any vulnerable package versions are installed. Also checks for affected architectures.
- Return type
Boolean
- Returns
True if the system is affected, False if not
- parse(myfile)¶
This method parses the XML file and sets up the internal data structures by calling the different helper functions in this module.
- Parameters
myfile (String) – Filename to grab the XML data from
- Return type
None
- Returns
None
- read()¶
Here we build the filename from the config and the ID and pass it to urllib to fetch it from the filesystem or a remote server.
- Return type
None
- Returns
None
- exception portage.glsa.GlsaArgumentException¶
Bases:
Exception
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception portage.glsa.GlsaFormatException¶
Bases:
Exception
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception portage.glsa.GlsaTypeException(doctype)¶
Bases:
Exception
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- portage.glsa.format_date(datestr)¶
Takes a date (announced, revised) date from a GLSA and formats it as readable text (i.e. “January 1, 2008”).
- Parameters
date (String) – the date string to reformat
- Return type
String
- Returns
a reformatted string, or the original string if it cannot be reformatted.
- portage.glsa.getListElements(listnode)¶
Get all <li> elements for a given <ol> or <ul> node.
- Parameters
listnode (xml.dom.Node) – <ul> or <ol> list to get the elements for
- Return type
List of Strings
- Returns
a list that contains the value of the <li> elements
- portage.glsa.getMinUpgrade(vulnerableList, unaffectedList, portdbapi, vardbapi, minimize=True)¶
Checks if the systemstate is matching an atom in I{vulnerableList} and returns string describing the lowest version for the package that matches an atom in I{unaffectedList} and is greater than the currently installed version. It will return an empty list if the system is affected, and no upgrade is possible or None if the system is not affected. Both I{vulnerableList} and I{unaffectedList} should have the same base package.
- Parameters
vulnerableList (List of Strings) – atoms matching vulnerable package versions
unaffectedList (List of Strings) – atoms matching unaffected package versions
portdbapi (portage.dbapi.porttree.portdbapi) – Ebuild repository
vardbapi (portage.dbapi.vartree.vardbapi) – Installed package repository
minimize (Boolean) – True for a least-change upgrade, False for emerge-like algorithm
- Return type
String | None
- Returns
the lowest unaffected version that is greater than the installed version.
- portage.glsa.getMultiTagsText(rootnode, tagname, format)¶
Returns a list with the text of all subnodes of type I{tagname} under I{rootnode} (which itself is not parsed) using the given I{format}.
- Parameters
rootnode (xml.dom.Node) – the node to search for I{tagname}
tagname (String) – the name of the tags to search for
format (String) – see
getText
- Return type
List of Strings
- Returns
a list containing the text of all I{tagname} childnodes
- portage.glsa.getText(node, format, textfd=None)¶
This is the main parser function. It takes a node and traverses recursive over the subnodes, getting the text of each (and the I{link} attribute for <uri> and <mail>). Depending on the I{format} parameter the text might be formatted by adding/removing newlines, tabs and spaces. This function is only useful for the GLSA DTD, it’s not applicable for other DTDs.
- Parameters
node (xml.dom.Node) – the root node to start with the parsing
format (String) – this should be either I{strip}, I{keep} or I{xml} I{keep} just gets the text and does no formatting. I{strip} replaces newlines and tabs with spaces and replaces multiple spaces with one space. I{xml} does some more formatting, depending on the type of the encountered nodes.
textfd (writable file-like object) – the file-like object to write the output to
- Return type
String
- Returns
the (formatted) content of the node and its subnodes except if textfd was not none
- portage.glsa.get_applied_glsas(settings)¶
Return a list of applied or injected GLSA IDs
- Parameters
settings (portage.config) – portage config instance
- Return type
list
- Returns
list of glsa IDs
- portage.glsa.get_glsa_list(myconfig)¶
Returns a list of all available GLSAs in the given repository by comparing the filelist there with the pattern described in the config.
- Parameters
myconfig (portage.config) – Portage settings instance
- Return type
List of Strings
- Returns
a list of GLSA IDs in this repository
- portage.glsa.makeAtom(pkgname, versionNode)¶
creates from the given package name and information in the I{versionNode} a (syntactical) valid portage atom.
- Parameters
pkgname (String) – the name of the package for this atom
versionNode (xml.dom.Node) – a <vulnerable> or <unaffected> Node that contains the version information for this atom
- Return type
String
- Returns
the portage atom
- portage.glsa.makeVersion(versionNode)¶
creates from the information in the I{versionNode} a version string (format <op><version>).
- Parameters
versionNode (xml.dom.Node) – a <vulnerable> or <unaffected> Node that contains the version information for this atom
- Return type
String
- Returns
the version string
- portage.glsa.match(atom, dbapi, match_type='default')¶
wrapper that calls revisionMatch() or portage.dbapi.dbapi.match() depending on the given atom.
- Parameters
atom (string) – a <~ or >~ atom or a normal portage atom that contains the atom to match against
dbapi (portage.dbapi.dbapi) – one of the portage databases to use as information source
match_type (string) – if != “default” passed as first argument to dbapi.xmatch to apply the wanted visibility filters
- Return type
list of strings
- Returns
a list with the matching versions
- portage.glsa.revisionMatch(revisionAtom, dbapi, match_type='default')¶
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.
- Parameters
revisionAtom (string) – a <~ or >~ atom that contains the atom to match against
dbapi (portage.dbapi.dbapi) – one of the portage databases to use as information source
match_type (string) – if != “default” passed as first argument to portdb.xmatch to apply the wanted visibility filters
- Return type
list of strings
- Returns
a list with the matching versions
- portage.glsa.wrap(text, width, caption='')¶
Wraps the given text at column I{width}, optionally indenting it so that no text is under I{caption}. It’s possible to encode hard linebreaks in I{text} with
NEWLINE_ESCAPE
.- Parameters
text (String) – the text to be wrapped
width (Integer) – the column at which the text should be wrapped
caption (String) – this string is inserted at the beginning of the return value and the paragraph is indented up to
len(caption)
.
- Return type
String
- Returns
the wrapped and indented paragraph