]> git.decadent.org.uk Git - dak.git/commitdiff
dak: ls: Calculate optimal column sizes
authorJulian Andres Klode <jak@debian.org>
Sun, 21 Apr 2013 00:59:25 +0000 (00:59 +0000)
committerLuca Falavigna <dktrkranz@debian.org>
Sun, 21 Apr 2013 01:00:36 +0000 (01:00 +0000)
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).

dak/ls.py

index ea51aaeffcad698eea8d1beae643bd57a6c7eef9..9d21e5ca76952f9d1a9909407d7ae22bf9abafb0 100755 (executable)
--- 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" ]: