changeset 14:b51310293ee3

Fix grouper when iterable length is not a multiplier
author Cédric Krier <ced@b2ck.com>
date Mon, 23 Feb 2015 17:24:04 +0100
parents bfd7c8912d32
children 2a22b994aca4
files farmhouse.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/farmhouse.py	Mon Feb 23 17:23:10 2015 +0100
+++ b/farmhouse.py	Mon Feb 23 17:24:04 2015 +0100
@@ -12,6 +12,7 @@
 import xmlrpc.client
 from datetime import datetime
 from distutils.versionpredicate import VersionPredicate
+from itertools import zip_longest
 
 from pkg_resources import parse_requirements
 
@@ -125,8 +126,8 @@
     return map(str.strip, packages.split(','))
 
 
-def grouper(iterable, n=100):
-    return zip(*(iter(iterable),) * n)
+def grouper(iterable, n=100, fillvalue=None):
+    return zip_longest(*(iter(iterable),) * n, fillvalue=fillvalue)
 
 
 @cache.memoize(timeout=2 * 60 * 60)
@@ -134,7 +135,7 @@
     versions = []
     for g_names in grouper(names):
         multicall = xmlrpc.client.MultiCall(client)
-        for name in g_names:
+        for name in filter(None, g_names):
             multicall.package_releases(name)
         versions += list(multicall())
     return versions
@@ -145,7 +146,7 @@
     urls = []
     for g_args in grouper(args):
         multicall = xmlrpc.client.MultiCall(client)
-        for name, version in g_args:
+        for name, version in filter(None, g_args):
             multicall.release_urls(name, version)
         urls += list(multicall())
     return urls