From: Gabriel Filion Date: Sun, 25 Jul 2010 17:34:13 +0000 (-0400) Subject: fix helpers.columnate bug when list is empty X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=d349af0005f6b4181544a99729023d5b413213cf;p=packages%2Fb%2Fbup.git fix helpers.columnate bug when list is empty When the list given to the columnate function is empty, the function raises an exception when determining the max(len of all elements), since the list given to max is empty. One indirect example of when this bug is apparent is in the 'bup ftp' command when listing an empty directory: bup> ls backupname/latest/etc/keys error: max() arg is an empty sequence Add a special condition at the beginning of the columnate function that returns an empty string if the list of elements is empty. Signed-off-by: Gabriel Filion --- diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index 3524859..65dbc3f 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -348,6 +348,8 @@ def columnate(l, prefix): The number of columns is determined automatically based on the string lengths. """ + if not l: + return "" l = l[:] clen = max(len(s) for s in l) ncols = (78 - len(prefix)) / (clen + 2)