[gentoo-commits] proj/portage:master commit in: pym/portage/tests/util/, pym/portage/util/

2018-06-26 Thread Zac Medico
commit: deb87a465306d05146d7eb55d27d7d89943725c0
Author: Zac Medico  gentoo  org>
AuthorDate: Sun Jun 24 21:42:52 2018 +
Commit: Zac Medico  gentoo  org>
CommitDate: Wed Jun 27 03:15:08 2018 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=deb87a46

{,PKG_}INSTALL_MASK: support trailing slash (bug 658322)

Fix the python INSTALL_MASK implementation so that a trailing slash
matches a directory, for compatibility with the previous bash
implementation.

Fixes: 3416876c0ee7 ("{,PKG_}INSTALL_MASK: python implementation")
Bug: https://bugs.gentoo.org/658322

 pym/portage/tests/util/test_install_mask.py | 129 
 pym/portage/util/install_mask.py|   7 +-
 2 files changed, 134 insertions(+), 2 deletions(-)

diff --git a/pym/portage/tests/util/test_install_mask.py 
b/pym/portage/tests/util/test_install_mask.py
new file mode 100644
index 0..f651eb4b7
--- /dev/null
+++ b/pym/portage/tests/util/test_install_mask.py
@@ -0,0 +1,129 @@
+# Copyright 2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+from portage.tests import TestCase
+from portage.util.install_mask import InstallMask
+
+
+class InstallMaskTestCase(TestCase):
+
+   def testTrailingSlash(self):
+   """
+   Test that elements with a trailing slash match a directory
+   but not a regular file.
+   """
+   cases = (
+   (
+   '/foo/bar/ -/foo/bar/*.foo -*.baz',
+   (
+   (
+   'foo/bar/baz',
+   True,
+   ),
+   (
+   'foo/bar/',
+   True,
+   ),
+   # /foo/bar/ does not match
+   (
+   'foo/bar',
+   False,
+   ),
+   # this is excluded
+   (
+   'foo/bar/baz.foo',
+   False,
+   ),
+   # this is excluded
+   (
+   'foo/bar/baz.baz',
+   False,
+   ),
+   (
+   'foo/bar/baz.bar',
+   True,
+   ),
+   )
+   ),
+   (
+   '/foo/bar -/foo/bar/*.foo -*.baz',
+   (
+   (
+   'foo/bar/baz',
+   True,
+   ),
+   # /foo/bar matches both foo/bar/ and 
foo/bar
+   (
+   'foo/bar/',
+   True,
+   ),
+   (
+   'foo/bar',
+   True,
+   ),
+   # this is excluded
+   (
+   'foo/bar/baz.foo',
+   False,
+   ),
+   # this is excluded
+   (
+   'foo/bar/baz.baz',
+   False,
+   ),
+   (
+   'foo/bar/baz.bar',
+   True,
+   ),
+   )
+   ),
+   (
+   '/foo*',
+   (
+   (
+   'foo',
+   True,
+   ),
+

[gentoo-commits] proj/portage:master commit in: pym/portage/tests/util/, pym/portage/util/

2017-04-20 Thread Zac Medico
commit: c8c038fd4c201a582c420004b5ff759f28fe626b
Author: Zac Medico  gentoo  org>
AuthorDate: Wed Apr 19 04:39:31 2017 +
Commit: Zac Medico  gentoo  org>
CommitDate: Thu Apr 20 19:39:00 2017 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=c8c038fd

digraph: add update and clear methods

Also, optimize the add method to avoid creating a lot of
duplicate priorities when called by the update method.

Acked-by: Brian Dolbec  gentoo.org>

 pym/portage/tests/util/test_digraph.py |  4 +++-
 pym/portage/util/digraph.py| 26 --
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/pym/portage/tests/util/test_digraph.py 
b/pym/portage/tests/util/test_digraph.py
index f519536d3..01e075c99 100644
--- a/pym/portage/tests/util/test_digraph.py
+++ b/pym/portage/tests/util/test_digraph.py
@@ -88,7 +88,9 @@ class DigraphTest(TestCase):
g.add("D", "A", 2)
 
f = g.clone()
-   for x in g, f:
+   h = digraph()
+   h.update(f)
+   for x in g, f, h:
self.assertEqual(bool(x), True)
self.assertEqual(x.contains("A"), True)
self.assertEqual(x.firstzero(), None)

diff --git a/pym/portage/util/digraph.py b/pym/portage/util/digraph.py
index 99b24fa1d..ba0e81c07 100644
--- a/pym/portage/util/digraph.py
+++ b/pym/portage/util/digraph.py
@@ -44,8 +44,10 @@ class digraph(object):
priorities = []
self.nodes[node][1][parent] = priorities
self.nodes[parent][0][node] = priorities
-   priorities.append(priority)
-   priorities.sort()
+
+   if not priorities or priorities[-1] is not priority:
+   priorities.append(priority)
+   priorities.sort()
 
def discard(self, node):
"""
@@ -73,6 +75,26 @@ class digraph(object):
del self.nodes[node]
self.order.remove(node)
 
+   def update(self, other):
+   """
+   Add all nodes and edges from another digraph instance.
+   """
+   for node in other.order:
+   children, parents, node = other.nodes[node]
+   if parents:
+   for parent, priorities in parents.items():
+   for priority in priorities:
+   self.add(node, parent, 
priority=priority)
+   else:
+   self.add(node, None)
+
+   def clear(self):
+   """
+   Remove all nodes and edges.
+   """
+   self.nodes.clear()
+   del self.order[:]
+
def difference_update(self, t):
"""
Remove all given nodes from node_set. This is more efficient