summaryrefslogtreecommitdiff
path: root/portato/helper.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2008-03-12 09:24:06 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2008-03-12 09:24:06 +0100
commit6ac3ab0f0e625e8cad02ab6291635e6f2180fe50 (patch)
treec187c7a738fdac6ae2f30841c0c1175cb991ccae /portato/helper.py
parentce3998575855189e4fb87a8c9777397fac1ffa23 (diff)
downloadportato-6ac3ab0f0e625e8cad02ab6291635e6f2180fe50.tar.gz
portato-6ac3ab0f0e625e8cad02ab6291635e6f2180fe50.tar.bz2
portato-6ac3ab0f0e625e8cad02ab6291635e6f2180fe50.zip
Moved get_dependencies to top package class
Diffstat (limited to 'portato/helper.py')
-rw-r--r--portato/helper.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/portato/helper.py b/portato/helper.py
index 5cf57a0..331bf9a 100644
--- a/portato/helper.py
+++ b/portato/helper.py
@@ -45,6 +45,51 @@ def send_signal_to_group (sig):
pgid = os.getpgrp()
os.killpg(pgid, sig)
+def paren_reduce(mystr):
+ """
+ Take a string and convert all paren enclosed entities into sublists, optionally
+ futher splitting the list elements by spaces.
+
+ This function is copied from portage.
+
+ Example usage:
+ >>> paren_reduce('foobar foo ( bar baz )')
+ ['foobar', 'foo', ['bar', 'baz']]
+
+ @param mystr: The string to reduce
+ @type mystr: String
+ @rtype: Array
+ @return: The reduced string in an array
+ """
+ mylist = []
+ while mystr:
+ left_paren = mystr.find("(")
+ has_left_paren = left_paren != -1
+ right_paren = mystr.find(")")
+ has_right_paren = right_paren != -1
+ if not has_left_paren and not has_right_paren:
+ freesec = mystr
+ subsec = None
+ tail = ""
+ elif mystr[0] == ")":
+ return [mylist,mystr[1:]]
+ elif has_left_paren and not has_right_paren:
+ error(_("Invalid dependency string"))
+ return []
+ elif has_left_paren and left_paren < right_paren:
+ freesec,subsec = mystr.split("(",1)
+ subsec,tail = paren_reduce(subsec)
+ else:
+ subsec,tail = mystr.split(")",1)
+ subsec = filter(None, subsec.split(" "))
+ return [mylist+subsec,tail]
+ mystr = tail
+ if freesec:
+ mylist = mylist + filter(None, freesec.split(" "))
+ if subsec is not None:
+ mylist = mylist + [subsec]
+ return mylist
+
def flatten (listOfLists):
"""Flattens the given list of lists.