[meta-freescale] [Documentation][PATCH 1/4] output-machine-list: use doc_utils.tabularize for table formatting

Lucas Dutra Nunes ldnunes at ossystems.com.br
Sat Feb 27 06:40:20 PST 2016


Signed-off-by: Lucas Dutra Nunes <ldnunes at ossystems.com.br>
---
 scripts/format_machine_list.py | 45 ++++++++++++++++++++++++++++++++++++++++++
 scripts/output-machine-list    | 17 +++++-----------
 2 files changed, 50 insertions(+), 12 deletions(-)
 create mode 100755 scripts/format_machine_list.py

diff --git a/scripts/format_machine_list.py b/scripts/format_machine_list.py
new file mode 100755
index 0000000..989a6d7
--- /dev/null
+++ b/scripts/format_machine_list.py
@@ -0,0 +1,45 @@
+#! /usr/bin/env python
+from doc_utils import tabularize
+import csv
+import os
+import sys
+
+
+def process_machines_table(csv_table):
+    return tabularize(csv_table)
+
+def read_csv_file(csv_file):
+    try:
+        with open(csv_file, 'rb') as csv_fd:
+            reader = csv.reader(csv_fd, delimiter=',')
+            return list(reader)
+    except IOError:
+        print('Could not read %s.  Aborting.') % csv_file
+        sys.exit(1)
+
+
+def usage(exit_code=None):
+    msg = '''Usage: %s <csv file>
+
+<csv file> is the CSV file with the machines.
+''' % os.path.basename(sys.argv[0])
+    if exit_code is not None and exit_code != 0:
+        sys.stderr.write(msg)
+        sys.exit(exit_code)
+    sys.stdout.write(msg)
+
+
+def main():
+    if '-h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv:
+        usage(0)
+
+    if len(sys.argv) < 2:
+        usage(1)
+
+    csv_file = sys.argv[1]
+    table = process_machines_table(read_csv_file(csv_file))
+    print table.strip()
+
+
+if __name__ == '__main__':
+    main()
diff --git a/scripts/output-machine-list b/scripts/output-machine-list
index 41e4393..0f3e5de 100755
--- a/scripts/output-machine-list
+++ b/scripts/output-machine-list
@@ -51,28 +51,21 @@ list_machines() {
 }
 
 tabularize_machines() {
+    echo "Machine,Name,SoC,Layer" >> $TMP
+
     for l in $MACHINE_LAYERS; do
         MACHINES=`cd $REPO; repo forall $l -c 'find -wholename "*/conf/machine/*.conf" | sed "s,./\(.*\),$REPO_PATH/\1,g"'`
         for m in $MACHINES; do
             machine=`basename $m | sed 's,\.conf$,,g'`
             name=`sed -n 's,#@NAME:\s*\(.*\),\1,p' $REPO/$m`
             soc=`sed -n 's,#@SOC:\s*\(.*\),\1,p' $REPO/$m`
-
-            printf "%-25s  %-50s  %-20s  %-10s\n" "$machine" "$name" "$soc" "$l" >> $TMP
+            l=`basename $l`
+            printf "%s,%s,%s,%s\n" "$machine" "$name" "$soc" "$l" >> $TMP
         done
     done
 
-    cat <<EOF
-=========================  ==================================================  ====================  ====================
-         Machine             Name                                                      SoC                  Layer
-=========================  ==================================================  ====================  ====================
-EOF
+    python format_machine_list.py $TMP
 
-    sort -u -k 1 $TMP
-
-    cat <<EOF
-=========================  ==================================================  ====================  ====================
-EOF
     rm $TMP
 }
 
-- 
2.1.4



More information about the meta-freescale mailing list