public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:repoman commit in: bin/, pym/portage/xml/, repoman/pym/repoman/modules/scan/metadata/
  2016-05-15 23:51 [gentoo-commits] proj/portage:master commit in: pym/portage/xml/, repoman/pym/repoman/modules/scan/metadata/, bin/ Brian Dolbec
@ 2016-05-14 23:14 ` Brian Dolbec
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Dolbec @ 2016-05-14 23:14 UTC (permalink / raw
  To: gentoo-commits

commit:     700b80efad6af8f6360ffbec996fbf789848bbbe
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat May 14 23:10:51 2016 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat May 14 23:10:51 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=700b80ef

Move parse_metadata_use to portage.xml.metadata namespace

This function was used by egencache, so move it to portage namespace to prevent code 
duplication.

 bin/egencache                                      |  2 +-
 pym/portage/xml/metadata.py                        | 59 ++++++++++++++++++++--
 .../repoman/modules/scan/metadata/pkgmetadata.py   | 53 +------------------
 3 files changed, 59 insertions(+), 55 deletions(-)

diff --git a/bin/egencache b/bin/egencache
index 0123d57..af0e1f2 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -73,7 +73,7 @@ else:
 	except ImportError:
 		pass
 	else:
-		from repoman.metadata import parse_metadata_use
+		from portage.xml.metadata import parse_metadata_use
 
 if sys.hexversion >= 0x3000000:
 	# pylint: disable=W0622

diff --git a/pym/portage/xml/metadata.py b/pym/portage/xml/metadata.py
index 33b9779..42f0982 100644
--- a/pym/portage/xml/metadata.py
+++ b/pym/portage/xml/metadata.py
@@ -30,7 +30,7 @@
 
 from __future__ import unicode_literals
 
-__all__ = ('MetaDataXML',)
+__all__ = ('MetaDataXML', 'parse_metadata_use')
 
 import sys
 
@@ -63,6 +63,11 @@ import xml.etree.ElementTree
 from portage import _encodings, _unicode_encode
 from portage.util import unique_everseen
 
+if sys.hexversion >= 0x3000000:
+	# pylint: disable=W0622
+	basestring = str
+
+
 class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
 	"""
 	Implements doctype() as required to avoid deprecation warnings with
@@ -85,7 +90,7 @@ class _Maintainer(object):
 	@type restrict: str or None
 	@ivar restrict: e.g. &gt;=portage-2.2 means only maintains versions
 		of Portage greater than 2.2. Should be DEPEND string with < and >
-		converted to &lt; and &gt; respectively. 
+		converted to &lt; and &gt; respectively.
 	@type status: str or None
 	@ivar status: If set, either 'active' or 'inactive'. Upstream only.
 	"""
@@ -180,7 +185,7 @@ class _Upstream(object):
 			lang = elem.get('lang')
 			result.append((elem.text, lang))
 		return result
-	
+
 	def upstream_maintainers(self):
 		"""Retrieve upstream maintainer information from xml node."""
 		return [_Maintainer(m) for m in self.node.findall('maintainer')]
@@ -424,3 +429,51 @@ class MetaDataXML(object):
 		maintainers = list(unique_everseen(maintainers))
 		maint_str = " ".join(maintainers)
 		return maint_str
+
+
+def parse_metadata_use(xml_tree):
+	"""
+	Records are wrapped in XML as per GLEP 56
+	returns a dict with keys constisting of USE flag names and values
+	containing their respective descriptions
+	"""
+	uselist = {}
+
+	usetags = xml_tree.findall("use")
+	if not usetags:
+		return uselist
+
+	# It's possible to have multiple 'use' elements.
+	for usetag in usetags:
+		flags = usetag.findall("flag")
+		if not flags:
+			# DTD allows use elements containing no flag elements.
+			continue
+
+		for flag in flags:
+			pkg_flag = flag.get("name")
+			if pkg_flag is not None:
+				flag_restrict = flag.get("restrict")
+
+				# emulate the Element.itertext() method from python-2.7
+				inner_text = []
+				stack = []
+				stack.append(flag)
+				while stack:
+					obj = stack.pop()
+					if isinstance(obj, basestring):
+						inner_text.append(obj)
+						continue
+					if isinstance(obj.text, basestring):
+						inner_text.append(obj.text)
+					if isinstance(obj.tail, basestring):
+						stack.append(obj.tail)
+					stack.extend(reversed(obj))
+
+				if flag.get("name") not in uselist:
+					uselist[flag.get("name")] = {}
+
+				# (flag_restrict can be None)
+				uselist[flag.get("name")][flag_restrict] = " ".join("".join(inner_text).split())
+	return uselist
+

diff --git a/repoman/pym/repoman/modules/scan/metadata/pkgmetadata.py b/repoman/pym/repoman/modules/scan/metadata/pkgmetadata.py
index 433551a..5235249 100644
--- a/repoman/pym/repoman/modules/scan/metadata/pkgmetadata.py
+++ b/repoman/pym/repoman/modules/scan/metadata/pkgmetadata.py
@@ -29,13 +29,10 @@ from repoman.modules.scan.scanbase import ScanBase
 from portage.exception import InvalidAtom
 from portage import os
 from portage.dep import Atom
+from portage.xml.metadata import parse_metadata_use
 
 from .use_flags import USEFlagChecks
 
-if sys.hexversion >= 0x3000000:
-	# pylint: disable=W0622
-	basestring = str
-
 metadata_xml_encoding = 'UTF-8'
 metadata_xml_declaration = '<?xml version="1.0" encoding="%s"?>' \
 	% (metadata_xml_encoding,)
@@ -130,7 +127,7 @@ class PkgMetadata(ScanBase, USEFlagChecks):
 					(xpkg, metadata_doctype_name, doctype_name))
 
 		# load USE flags from metadata.xml
-		self.musedict = self._parse_metadata_use(_metadata_xml, xpkg)
+		self.musedict = parse_metadata_use(_metadata_xml)
 		for atom in chain(*self.musedict.values()):
 			if atom is None:
 				continue
@@ -174,52 +171,6 @@ class PkgMetadata(ScanBase, USEFlagChecks):
 					% (xpkg, myflag))
 		return False
 
-	def _parse_metadata_use(self, xml_tree, xpkg):
-		"""
-		Records are wrapped in XML as per GLEP 56
-		returns a dict with keys constisting of USE flag names and values
-		containing their respective descriptions
-		"""
-		uselist = {}
-
-		usetags = xml_tree.findall("use")
-		if not usetags:
-			return uselist
-
-		# It's possible to have multiple 'use' elements.
-		for usetag in usetags:
-			flags = usetag.findall("flag")
-			if not flags:
-				# DTD allows use elements containing no flag elements.
-				continue
-
-			for flag in flags:
-				pkg_flag = flag.get("name")
-				if pkg_flag is not None:
-					flag_restrict = flag.get("restrict")
-
-					# emulate the Element.itertext() method from python-2.7
-					inner_text = []
-					stack = []
-					stack.append(flag)
-					while stack:
-						obj = stack.pop()
-						if isinstance(obj, basestring):
-							inner_text.append(obj)
-							continue
-						if isinstance(obj.text, basestring):
-							inner_text.append(obj.text)
-						if isinstance(obj.tail, basestring):
-							stack.append(obj.tail)
-						stack.extend(reversed(obj))
-
-					if flag.get("name") not in uselist:
-						uselist[flag.get("name")] = {}
-
-					# (flag_restrict can be None)
-					uselist[flag.get("name")][flag_restrict] = " ".join("".join(inner_text).split())
-		return uselist
-
 	def _add_validate_errors(self, xpkg, log):
 		listed = set()
 		for error in log:


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-commits] proj/portage:master commit in: pym/portage/xml/, repoman/pym/repoman/modules/scan/metadata/, bin/
@ 2016-05-15 23:51 Brian Dolbec
  2016-05-14 23:14 ` [gentoo-commits] proj/portage:repoman commit in: bin/, pym/portage/xml/, repoman/pym/repoman/modules/scan/metadata/ Brian Dolbec
  0 siblings, 1 reply; 2+ messages in thread
From: Brian Dolbec @ 2016-05-15 23:51 UTC (permalink / raw
  To: gentoo-commits

commit:     700b80efad6af8f6360ffbec996fbf789848bbbe
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat May 14 23:10:51 2016 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat May 14 23:10:51 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=700b80ef

Move parse_metadata_use to portage.xml.metadata namespace

This function was used by egencache, so move it to portage namespace to prevent code 
duplication.

 bin/egencache                                      |  2 +-
 pym/portage/xml/metadata.py                        | 59 ++++++++++++++++++++--
 .../repoman/modules/scan/metadata/pkgmetadata.py   | 53 +------------------
 3 files changed, 59 insertions(+), 55 deletions(-)

diff --git a/bin/egencache b/bin/egencache
index 0123d57..af0e1f2 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -73,7 +73,7 @@ else:
 	except ImportError:
 		pass
 	else:
-		from repoman.metadata import parse_metadata_use
+		from portage.xml.metadata import parse_metadata_use
 
 if sys.hexversion >= 0x3000000:
 	# pylint: disable=W0622

diff --git a/pym/portage/xml/metadata.py b/pym/portage/xml/metadata.py
index 33b9779..42f0982 100644
--- a/pym/portage/xml/metadata.py
+++ b/pym/portage/xml/metadata.py
@@ -30,7 +30,7 @@
 
 from __future__ import unicode_literals
 
-__all__ = ('MetaDataXML',)
+__all__ = ('MetaDataXML', 'parse_metadata_use')
 
 import sys
 
@@ -63,6 +63,11 @@ import xml.etree.ElementTree
 from portage import _encodings, _unicode_encode
 from portage.util import unique_everseen
 
+if sys.hexversion >= 0x3000000:
+	# pylint: disable=W0622
+	basestring = str
+
+
 class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
 	"""
 	Implements doctype() as required to avoid deprecation warnings with
@@ -85,7 +90,7 @@ class _Maintainer(object):
 	@type restrict: str or None
 	@ivar restrict: e.g. &gt;=portage-2.2 means only maintains versions
 		of Portage greater than 2.2. Should be DEPEND string with < and >
-		converted to &lt; and &gt; respectively. 
+		converted to &lt; and &gt; respectively.
 	@type status: str or None
 	@ivar status: If set, either 'active' or 'inactive'. Upstream only.
 	"""
@@ -180,7 +185,7 @@ class _Upstream(object):
 			lang = elem.get('lang')
 			result.append((elem.text, lang))
 		return result
-	
+
 	def upstream_maintainers(self):
 		"""Retrieve upstream maintainer information from xml node."""
 		return [_Maintainer(m) for m in self.node.findall('maintainer')]
@@ -424,3 +429,51 @@ class MetaDataXML(object):
 		maintainers = list(unique_everseen(maintainers))
 		maint_str = " ".join(maintainers)
 		return maint_str
+
+
+def parse_metadata_use(xml_tree):
+	"""
+	Records are wrapped in XML as per GLEP 56
+	returns a dict with keys constisting of USE flag names and values
+	containing their respective descriptions
+	"""
+	uselist = {}
+
+	usetags = xml_tree.findall("use")
+	if not usetags:
+		return uselist
+
+	# It's possible to have multiple 'use' elements.
+	for usetag in usetags:
+		flags = usetag.findall("flag")
+		if not flags:
+			# DTD allows use elements containing no flag elements.
+			continue
+
+		for flag in flags:
+			pkg_flag = flag.get("name")
+			if pkg_flag is not None:
+				flag_restrict = flag.get("restrict")
+
+				# emulate the Element.itertext() method from python-2.7
+				inner_text = []
+				stack = []
+				stack.append(flag)
+				while stack:
+					obj = stack.pop()
+					if isinstance(obj, basestring):
+						inner_text.append(obj)
+						continue
+					if isinstance(obj.text, basestring):
+						inner_text.append(obj.text)
+					if isinstance(obj.tail, basestring):
+						stack.append(obj.tail)
+					stack.extend(reversed(obj))
+
+				if flag.get("name") not in uselist:
+					uselist[flag.get("name")] = {}
+
+				# (flag_restrict can be None)
+				uselist[flag.get("name")][flag_restrict] = " ".join("".join(inner_text).split())
+	return uselist
+

diff --git a/repoman/pym/repoman/modules/scan/metadata/pkgmetadata.py b/repoman/pym/repoman/modules/scan/metadata/pkgmetadata.py
index 433551a..5235249 100644
--- a/repoman/pym/repoman/modules/scan/metadata/pkgmetadata.py
+++ b/repoman/pym/repoman/modules/scan/metadata/pkgmetadata.py
@@ -29,13 +29,10 @@ from repoman.modules.scan.scanbase import ScanBase
 from portage.exception import InvalidAtom
 from portage import os
 from portage.dep import Atom
+from portage.xml.metadata import parse_metadata_use
 
 from .use_flags import USEFlagChecks
 
-if sys.hexversion >= 0x3000000:
-	# pylint: disable=W0622
-	basestring = str
-
 metadata_xml_encoding = 'UTF-8'
 metadata_xml_declaration = '<?xml version="1.0" encoding="%s"?>' \
 	% (metadata_xml_encoding,)
@@ -130,7 +127,7 @@ class PkgMetadata(ScanBase, USEFlagChecks):
 					(xpkg, metadata_doctype_name, doctype_name))
 
 		# load USE flags from metadata.xml
-		self.musedict = self._parse_metadata_use(_metadata_xml, xpkg)
+		self.musedict = parse_metadata_use(_metadata_xml)
 		for atom in chain(*self.musedict.values()):
 			if atom is None:
 				continue
@@ -174,52 +171,6 @@ class PkgMetadata(ScanBase, USEFlagChecks):
 					% (xpkg, myflag))
 		return False
 
-	def _parse_metadata_use(self, xml_tree, xpkg):
-		"""
-		Records are wrapped in XML as per GLEP 56
-		returns a dict with keys constisting of USE flag names and values
-		containing their respective descriptions
-		"""
-		uselist = {}
-
-		usetags = xml_tree.findall("use")
-		if not usetags:
-			return uselist
-
-		# It's possible to have multiple 'use' elements.
-		for usetag in usetags:
-			flags = usetag.findall("flag")
-			if not flags:
-				# DTD allows use elements containing no flag elements.
-				continue
-
-			for flag in flags:
-				pkg_flag = flag.get("name")
-				if pkg_flag is not None:
-					flag_restrict = flag.get("restrict")
-
-					# emulate the Element.itertext() method from python-2.7
-					inner_text = []
-					stack = []
-					stack.append(flag)
-					while stack:
-						obj = stack.pop()
-						if isinstance(obj, basestring):
-							inner_text.append(obj)
-							continue
-						if isinstance(obj.text, basestring):
-							inner_text.append(obj.text)
-						if isinstance(obj.tail, basestring):
-							stack.append(obj.tail)
-						stack.extend(reversed(obj))
-
-					if flag.get("name") not in uselist:
-						uselist[flag.get("name")] = {}
-
-					# (flag_restrict can be None)
-					uselist[flag.get("name")][flag_restrict] = " ".join("".join(inner_text).split())
-		return uselist
-
 	def _add_validate_errors(self, xpkg, log):
 		listed = set()
 		for error in log:


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-15 23:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-15 23:51 [gentoo-commits] proj/portage:master commit in: pym/portage/xml/, repoman/pym/repoman/modules/scan/metadata/, bin/ Brian Dolbec
2016-05-14 23:14 ` [gentoo-commits] proj/portage:repoman commit in: bin/, pym/portage/xml/, repoman/pym/repoman/modules/scan/metadata/ Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox