summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-02-21 09:16:58 +0000
committerZac Medico <zmedico@gentoo.org>2010-02-21 09:16:58 +0000
commitf7608f6f3688a9e10c8ecafc81bac6a154a74a31 (patch)
treef0e3030d441a4ab295a8f50a6e8ce037f4fa7f74
parent67e7d29b6e7867ff8b23f4bb43370f27a3cf942b (diff)
downloadportage-f7608f6f3688a9e10c8ecafc81bac6a154a74a31.tar.gz
portage-f7608f6f3688a9e10c8ecafc81bac6a154a74a31.tar.bz2
portage-f7608f6f3688a9e10c8ecafc81bac6a154a74a31.zip
Move portage.flatten to portage.dep.flatten.
svn path=/main/trunk/; revision=15413
-rw-r--r--pym/portage/__init__.py13
-rw-r--r--pym/portage/dep.py32
2 files changed, 33 insertions, 12 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 77d36ffb5..25057f36c 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -85,7 +85,7 @@ try:
'uid,userland,userpriv_groups,wheelgid',
'portage.dep',
'portage.dep:best_match_to_list,dep_getcpv,dep_getkey,' + \
- 'get_operator,isjustname,isspecific,isvalidatom,' + \
+ 'flatten,get_operator,isjustname,isspecific,isvalidatom,' + \
'match_from_list,match_to_list',
'portage.eclass_cache',
'portage.env.loaders',
@@ -673,17 +673,6 @@ def listdir(mypath, recursive=False, filesonly=False, ignorecvs=False, ignorelis
return rlist
-def flatten(mytokens):
- """this function now turns a [1,[2,3]] list into
- a [1,2,3] list and returns it."""
- newlist=[]
- for x in mytokens:
- if isinstance(x, list):
- newlist.extend(flatten(x))
- else:
- newlist.append(x)
- return newlist
-
#beautiful directed graph object
class digraph(object):
diff --git a/pym/portage/dep.py b/pym/portage/dep.py
index e2eeb6d5b..282fe749d 100644
--- a/pym/portage/dep.py
+++ b/pym/portage/dep.py
@@ -3,6 +3,16 @@
# Distributed under the terms of the GNU General Public License v2
# $Id$
+__all__ = [
+ 'Atom', 'best_match_to_list', 'cpvequal',
+ 'dep_getcpv', 'dep_getkey', 'dep_getslot',
+ 'dep_getusedeps', 'dep_opconvert', 'flatten',
+ 'get_operator', 'isjustname', 'isspecific',
+ 'isvalidatom', 'match_from_list', 'match_to_list',
+ 'paren_enclose', 'paren_normalize', 'paren_reduce',
+ 'remove_slot', 'strip_empty', 'use_reduce'
+]
+
# DEPEND SYNTAX:
#
# 'use?' only affects the immediately following word!
@@ -343,6 +353,28 @@ def dep_opconvert(deplist):
x += 1
return retlist
+def flatten(mylist):
+ """
+ Recursively traverse nested lists and return a single list containing
+ all non-list elements that are found.
+
+ Example usage:
+ >>> flatten([1, [2, 3, [4]]])
+ [1, 2, 3, 4]
+
+ @param mylist: A list containing nested lists and non-list elements.
+ @type mylist: List
+ @rtype: List
+ @return: A single list containing only non-list elements.
+ """
+ newlist = []
+ for x in mylist:
+ if isinstance(x, list):
+ newlist.extend(flatten(x))
+ else:
+ newlist.append(x)
+ return newlist
+
class _use_dep(object):
__slots__ = ("__weakref__", "conditional",