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

Mario Domenech Goulart mario.goulart at gmail.com
Sat Feb 27 10:24:00 PST 2016


Hello Lucas,

On Sat, 27 Feb 2016 11:40:20 -0300 Lucas Dutra Nunes <ldnunes at ossystems.com.br> wrote:

> 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

I think it would be better to send error messages to stderr (i.e., use
sys.stderr.write instead of print).

> +        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()

Use print(table.script()) for consistency with other usages of print.

> +
> +
> +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

Regards,
Mario
-- 
http://parenteses.org/mario


More information about the meta-freescale mailing list