[meta-freescale] [Documentation][PATCH][v2 1/3] script: create doc_utils.py module for commonly used methods

Lucas Dutra Nunes ldnunes at ossystems.com.br
Wed Nov 5 06:06:42 PST 2014


For now it only has "tabularize", a method extracted from
scripts/bitbake-metadata2doc.py that creates reST tables from
bi-dimensional lists.

Also, the method is slightly different from the original, as it applies
rstrip() to the generated table header and rows to avoid polluting the
commit diffs with blank spaces.

Signed-off-by: Lucas Dutra Nunes <ldnunes at ossystems.com.br>
---
 scripts/bitbake-metadata2doc.py | 31 +------------------------------
 scripts/doc_utils.py            | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 30 deletions(-)
 create mode 100644 scripts/doc_utils.py

diff --git a/scripts/bitbake-metadata2doc.py b/scripts/bitbake-metadata2doc.py
index fda27b8..7d3a1fa 100644
--- a/scripts/bitbake-metadata2doc.py
+++ b/scripts/bitbake-metadata2doc.py
@@ -8,6 +8,7 @@ import pickle
 import subprocess
 import copy
 import shutil
+from doc_utils import tabularize
 
 def info(fmt, *args):
     print(fmt % args)
@@ -18,36 +19,6 @@ def warn(fmt, *args):
 def error(fmt, *args):
     sys.stderr.write(('ERROR: ' + fmt + '\n') % args)
 
-def tabularize(lines, spacing=2):
-    def format_border(widths):
-        return spc.join([ '=' * width for width in widths ])
-
-    def format_header(header, widths, spc):
-        border = format_border(widths)
-        header = spc.join(map(lambda col, width: col.ljust(width),
-                              header, widths))
-        return '\n'.join([border, header, border])
-
-    def sort_by_col(lines, col):
-        return sorted(lines, key=lambda l: l[col])
-
-    def format_body(lines, widths, spc):
-        def format_line (line):
-            return spc.join(map(lambda col, width: col.ljust(width),
-                                line, widths))
-        return "\n".join(map(format_line, sort_by_col(lines, 0)))
-
-    spc = ' ' * spacing
-    if lines:
-        col_widths = map(lambda col: apply(max, map(len, col)),
-                         apply(zip, lines))
-        return '\n'.join([format_header(lines[0], col_widths, spc),
-                          format_body(lines[1:], col_widths, spc),
-                          format_border(col_widths)]) + \
-               '\n'
-    else:
-        return ""
-
 def describe(items):
     text = ''
     for item in sorted(items):
diff --git a/scripts/doc_utils.py b/scripts/doc_utils.py
new file mode 100644
index 0000000..0904c35
--- /dev/null
+++ b/scripts/doc_utils.py
@@ -0,0 +1,29 @@
+def tabularize(lines, spacing=2):
+    def format_border(widths):
+        return spc.join([ '=' * width for width in widths ])
+
+    def format_header(header, widths, spc):
+        border = format_border(widths)
+        header = spc.join(map(lambda col, width: col.ljust(width),
+                              header, widths)).rstrip()
+        return '\n'.join([border, header, border])
+
+    def sort_by_col(lines, col):
+        return sorted(lines, key=lambda l: l[col])
+
+    def format_body(lines, widths, spc):
+        def format_line (line):
+            return spc.join(map(lambda col, width: col.ljust(width),
+                                line, widths)).rstrip()
+        return "\n".join(map(format_line, sort_by_col(lines, 0)))
+
+    spc = ' ' * spacing
+    if lines:
+        col_widths = map(lambda col: apply(max, map(len, col)),
+                         apply(zip, lines))
+        return '\n'.join([format_header(lines[0], col_widths, spc),
+                          format_body(lines[1:], col_widths, spc),
+                          format_border(col_widths)]) + \
+               '\n'
+    else:
+        return ""
-- 
2.1.1



More information about the meta-freescale mailing list