# Copyright 2003-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import codecs import sys try: from urllib.request import urlopen as urllib_request_urlopen except ImportError: from urllib import urlopen as urllib_request_urlopen import re import xml.dom.minidom import portage from portage import os from portage import _encodings from portage import _unicode_decode from portage import _unicode_encode from portage.versions import pkgsplit, catpkgsplit, pkgcmp, best from portage.util import grabfile from portage.const import CACHE_PATH from portage.localization import _ # Note: the space for rgt and rlt is important !! # FIXME: use slot deps instead, requires GLSA format versioning opMapping = {"le": "<=", "lt": "<", "eq": "=", "gt": ">", "ge": ">=", "rge": ">=~", "rle": "<=~", "rgt": " >~", "rlt": " <~"} 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, "glsa")) # TODO: use the textwrap module instead def 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 L{NEWLINE_ESCAPE}. @type text: String @param text: the text to be wrapped @type width: Integer @param width: the column at which the text should be wrapped @type caption: String @param caption: this string is inserted at the beginning of the return value and the paragraph is indented up to C{len(caption)}. @rtype: String @return: the wrapped and indented paragraph """ rValue = "" line = caption text = text.replace(2*NEWLINE_ESCAPE, NEWLINE_ESCAPE+" "+NEWLINE_ESCAPE) words = text.split() indentLevel = len(caption)+1 for w in words: if line != "" and line[-1] == "\n": rValue += line line = " "*indentLevel if len(line)+len(w.replace(NEWLINE_ESCAPE, ""))+1 > width: rValue += line+"\n" line = " "*indentLevel+w.replace(NEWLINE_ESCAPE, "\n") elif w.find(NEWLINE_ESCAPE) >= 0: if len(line.strip()) > 0: rValue += line+" "+w.replace(NEWLINE_ESCAPE, "\n") else: rValue += line+w.replace(NEWLINE_ESCAPE, "\n") line = " "*indentLevel else: if len(line.strip()) > 0: line += " "+w else: line += w if len(line) > 0: rValue += line.replace(NEWLINE_ESCAPE, "\n") rValue = rValue.replace(SPACE_ESCAPE, " ") return rValue def 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. @type myconfig: portage.config @param myconfig: Portage settings instance @rtype: List of Strings @return: a list of GLSA IDs in this repository """ rValue = [] if "GLSA_DIR" in myconfig: repository = myconfig["GLSA_DIR"] else: repository = os.path.join(myconfig["PORTDIR"], "metadata", "glsa") if not os.access(repository, os.R_OK): return [] dirlist = os.listdir(repository) prefix = "glsa-" suffix = ".xml" for f in dirlist: try: if f[:len(prefix)] == prefix: rValue.append(f[len(prefix):-1*len(suffix)]) except IndexError: pass return rValue def getListElements(listnode): """ Get all
  • elements for a given
      or