commit:     1ed9be28e1c70ea89f68d15cf7456ffd7721f352
Author:     Gilles Dartiguelongue <eva <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 24 12:07:21 2015 +0000
Commit:     Gilles Dartiguelongue <eva <AT> gentoo <DOT> org>
CommitDate: Wed Jun 24 12:13:27 2015 +0000
URL:        https://gitweb.gentoo.org/proj/gnome.git/commit/?id=1ed9be28

scripts/gen_archlist: Simplify functions and try to enhance documentation

 scripts/gen_archlist.py | 46 ++++++++++++++++++++--------------------------
 1 file changed, 20 insertions(+), 26 deletions(-)

diff --git a/scripts/gen_archlist.py b/scripts/gen_archlist.py
index 1a57fe2..8ec59c0 100755
--- a/scripts/gen_archlist.py
+++ b/scripts/gen_archlist.py
@@ -101,14 +101,11 @@ def nothing_to_be_done(atom, type='cpv'):
 
 
 def make_unstable(kws):
-    "Takes a keyword list, and returns a list with them all unstable"
-    nkws = []
-    for kw in kws:
-        if not kw.startswith('~'):
-            nkws.append('~'+kw)
-        else:
-            nkws.append(kw)
-    return nkws
+    """Transform `kws` into a list of unstable keywords."""
+    return [
+        kwd if kw.startswith('~') else '~' + kwd
+        for kwd in kws
+    ]
 
 
 def belongs_release(cpv, release):
@@ -127,14 +124,11 @@ def issystempackage(cpv):
 
 
 def get_kws(cpv, arches=ARCHES):
-    """
-    Returns an array of KEYWORDS matching 'arches'
-    """
-    kws = []
-    for kw in portage.portdb.aux_get(cpv, ['KEYWORDS'])[0].split():
-        if kw in arches:
-            kws.append(kw)
-    return kws
+    """Return keywords of `cpv` filtered by `arches`."""
+    return [
+        for keyword in portage.portdb.aux_get(cpv, ['KEYWORDS'])[0].split()
+        if keyword in arches
+    ]
 
 
 def do_not_want(cpv, release=None):
@@ -149,20 +143,20 @@ def do_not_want(cpv, release=None):
 
 
 def match_wanted_atoms(atom, release=None):
+    """Return a list of CPV matching `atom`.
+
+    If `release` is provided, CPVs are filtered against it.
+
+    The list is sorted by descending order of version.
     """
-    Given an atom and a release, return all matching wanted atoms ordered in
-    descending order of version
-    """
-    atoms = []
     # xmatch is stupid, and ignores ! in an atom...
     if atom.startswith('!'):
         return []
-    for cpv in portage.portdb.xmatch('match-all', atom):
-        if do_not_want(cpv, release):
-            continue
-        atoms.append(cpv)
-    atoms.reverse()
-    return atoms
+
+    return [
+        for cpv in reversed(portage.portdb.xmatch('match-all', atom)):
+        if not do_not_want(cpv, release)
+    ]
 
 
 def get_best_deps(cpv, kws, release=None):

Reply via email to