Skip to contentSkip to conversation

matrix_to_string: header columns width

PATCH New Lukas Doktor 2 participants 3 messages Sep 29, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 matrix_to_string: header columns width

Hi,

this patch calculates the columns' width including the header's one. In addition it accepts the header of booth types - tuple or list.

Regards,
Lukas

#1 lore raw

PATCH 1/1 FIX matrix_to_string: header columns width ADD matrix_to_string: accept header of type tupple or list

---
 client/common_lib/utils.py |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
client/common_lib/utils.py +6 -1
index f44dd1e..6b8cdf6 100644
@@ -211,9 +211,14 @@ def matrix_to_string(matrix, header=None):
     in each column, and determining the format string dynamically.
 
     @param matrix: Matrix representation (list with n rows of m elements).
-    @param header: Optional tuple with header elements to be displayed.
+    @param header: Optional tuple or list with header elements to be displayed.
     """
+    if type(header) is list:
+        header = tuple(header)
     lengths = []
+    if header:
+        for column in header:
+            lengths.append(len(column))
     for row in matrix:
         for column in row:
             i = row.index(column)
Signature · 1 line
1.7.2.3
#2 lore raw

Re: [PATCH] FIX matrix_to_string: header columns width ADD matrix_to_string: accept header of type tupple or list

Quoted 1 line · Lukas Doktor

Ooops, my bad, I forgot about the header. Looks good to me, applied, thanks!

http://autotest.kernel.org/changeset/4818

Lucas

Quoted 24 lines
---
 client/common_lib/utils.py |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
client/common_lib/utils.py +6 -1
index f44dd1e..6b8cdf6 100644
@@ -211,9 +211,14 @@ def matrix_to_string(matrix, header=None):
     in each column, and determining the format string dynamically.
 
     @param matrix: Matrix representation (list with n rows of m elements).
-    @param header: Optional tuple with header elements to be displayed.
+    @param header: Optional tuple or list with header elements to be displayed.
     """
+    if type(header) is list:
+        header = tuple(header)
     lengths = []
+    if header:
+        for column in header:
+            lengths.append(len(column))
     for row in matrix:
         for column in row:
             i = row.index(column)