From: Julian Andres Klode Date: Sun, 21 Apr 2013 00:59:25 +0000 (+0000) Subject: dak: ls: Calculate optimal column sizes X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c2a6a0c45a82cd77fbcf705be3c13782d950f34;p=dak dak: ls: Calculate optimal column sizes If a package name is longer than 10 characters, or a version longer than 13 characters, columns had different widths in different rows. By calculating the maximum column size and using that instead of hard-coded values, we have a nice table again (Closes: #705289). --- diff --git a/dak/ls.py b/dak/ls.py index ea51aaef..9d21e5ca 100755 --- a/dak/ls.py +++ b/dak/ls.py @@ -174,6 +174,19 @@ SELECT s.source, s.version, 'source', su.suite_name, c.name, m.name packages = d.keys() packages.sort() + + # Calculate optimal column sizes + sizes = [10, 13, 10] + for pkg in packages: + versions = d[pkg].keys() + for version in versions: + suites = d[pkg][version].keys() + for suite in suites: + sizes[0] = max(sizes[0], len(pkg)) + sizes[1] = max(sizes[1], len(version)) + sizes[2] = max(sizes[2], len(suite)) + fmt = "%%%is | %%%is | %%%is | " % tuple(sizes) + for pkg in packages: versions = d[pkg].keys() versions.sort(apt_pkg.version_compare) @@ -184,7 +197,7 @@ SELECT s.source, s.version, 'source', su.suite_name, c.name, m.name arches = d[pkg][version][suite] arches.sort(utils.arch_compare_sw) if Options["Format"] == "": #normal - sys.stdout.write("%10s | %10s | %13s | " % (pkg, version, suite)) + sys.stdout.write(fmt % (pkg, version, suite)) sys.stdout.write(", ".join(arches)) sys.stdout.write('\n') elif Options["Format"] in [ "control-suite", "heidi" ]: