From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC V2 6/9] tools: add reformat.py and (temporary merge.py)
Date: Fri, 26 Jul 2013 23:37:12 +0200 [thread overview]
Message-ID: <1374874635-12042-7-git-send-email-albert.u.boot@aribaud.net> (raw)
In-Reply-To: <1374874635-12042-6-git-send-email-albert.u.boot@aribaud.net>
tools/merge.py is only in the RFC, and will actually
be removed once it has merged MAINTAINERS and boards.cfg
tools/reformat.py will be used to keep boards.cfg
properly sorted and formatted.
Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
tools/merge.py | 61 +++++++++++++++++++++++++
tools/reformat.py | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 193 insertions(+)
create mode 100755 tools/merge.py
create mode 100755 tools/reformat.py
diff --git a/tools/merge.py b/tools/merge.py
new file mode 100755
index 0000000..c043ebb
--- /dev/null
+++ b/tools/merge.py
@@ -0,0 +1,61 @@
+#! /usr/bin/python
+
+import sys
+
+# read MAINTAINERS into an array of [ system, board, status, maintainers ]
+
+MArray = []
+MFile = open('MAINTAINERS', 'r')
+for mline in MFile:
+ mline = mline.strip('\n')
+ if (len(mline)>0) and (mline[0] != '#'):
+ mfields = mline.split(None,3)
+ while len(mfields)<4:
+ mfields.append('')
+ MArray.append(tuple(mfields))
+MFile.close
+
+# read boards.cfg into an array of [ Target, ARCH, CPU, Board name, Vendor,
+# SoC, Options ]
+
+BArray = []
+BFile = open('boards.cfg', 'r')
+for bline in BFile:
+ bline = bline.strip('\n')
+ if (len(bline)>0) and (bline[0] != '#'):
+ bfields = bline.split(None,6)
+ while len(bfields)<7:
+ bfields.append('')
+ BArray.append(tuple(bfields))
+BFile.close
+
+# Now, for each boards target: search for matching entries in MAINTAINERS
+# and collect their status and maintainer(s). Matching is done against
+# base target in opts if any, or target, or board.
+
+for tgt, arch, cpu, brd, vend, soc, opts in BArray:
+ if len(vend)==0:
+ vend = '-'
+ if len(soc)==0:
+ soc = '-'
+ if len(opts)==0:
+ opts = '-'
+ mtnrs = []
+ base = opts.split(':',1)
+ if len(base)>0:
+ base = base[0]
+ else:
+ base = ''
+ status = 'Active'
+ for sys, brd2, sts, mtnr in MArray:
+ if (brd2.lower() == base.lower()) \
+ or (brd2.lower() == tgt.lower()) \
+ or (brd2.lower() == brd.lower()):
+ mtnrs.append(mtnr)
+ status = sts
+ print status, arch, cpu, soc, vend, brd, tgt, opts,
+ if len(mtnrs) >0:
+ print ':'.join(set(mtnrs)),
+ else:
+ print '-',
+ print
diff --git a/tools/reformat.py b/tools/reformat.py
new file mode 100755
index 0000000..ff6633f
--- /dev/null
+++ b/tools/reformat.py
@@ -0,0 +1,132 @@
+#! /usr/bin/python
+########################################################################
+#
+# reorder and reformat a file in columns
+#
+# this utility takes lines from its standard input and reproduces them,
+# partially reordered and reformatted, on its standard output.
+#
+# It has the same effect as a 'sort | column -t', with the exception
+# that empty lines, as well as lines which start with a '#' sign, are
+# not affected, i.e. they keep their position and formatting, and act
+# as separators, i.e. the parts before and after them are each sorted
+# separately (but overall field widths are computed across the whole
+# input).
+#
+# Options:
+# -i:
+# --ignore-case:
+# Do not consider case when sorting.
+# -d:
+# --default:
+# What to chage empty fields to.
+# -s <N>:
+# --split=<N>:
+# Treat only the first N whitespace sequences as separators.
+# line content after the Nth separator will count as only one
+# field even if it contains whitespace.
+# Example : '-s 2' causes input 'a b c d e' to be split into
+# three fields, 'a', 'b', and 'c d e'.
+#
+# boards.cfg requires -ids 6.
+#
+########################################################################
+
+import sys, getopt, locale
+
+# ensure we sort using the C locale.
+
+locale.setlocale(locale.LC_ALL, 'C')
+
+# check options
+
+maxsplit = 0
+ignore_case = 0
+default_field =''
+
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "id:s:",
+ ["ignore-case","default","split="])
+except getopt.GetoptError as err:
+ print str(err) # will print something like "option -a not recognized"
+ sys.exit(2)
+
+for o, a in opts:
+ if o in ("-s", "--split"):
+ maxsplit = eval(a)
+ elif o in ("-i", "--ignore-case"):
+ ignore_case = 1
+ elif o in ("-d", "--default"):
+ default_field = a
+ else:
+ assert False, "unhandled option"
+
+# collect all lines from standard input and, for the ones which must be
+# reformatted and sorted, count their fields and compute each field's
+# maximum size
+
+input_lines = []
+field_width = []
+
+for line in sys.stdin:
+ # remove final end of line
+ input_line = line.strip('\n')
+ if (len(input_line)>0) and (input_line[0] != '#'):
+ # sortable line: split into fields
+ fields = input_line.split(None,maxsplit)
+ # if there are new fields, top up field_widths
+ for f in range(len(field_width), len(fields)):
+ field_width.append(0)
+ # compute the maximum witdh of each field
+ for f in range(len(fields)):
+ field_width[f] = max(field_width[f],len(fields[f]))
+ # collect the line for next stage
+ input_lines.append(input_line)
+
+# run through collected input lines, collect the ones which must be
+# reformatted and sorted, and whenever a non-reformattable, non-sortable
+# line is met, sort the collected lines before it and append them to the
+# output lines, then add the non-sortable line too.
+
+output_lines = []
+sortable_lines = []
+for input_line in input_lines:
+ if (len(input_line)>0) and (input_line[0] != '#'):
+ # this line should be reformatted and sorted
+ input_fields = input_line.split(None,maxsplit)
+ output_fields = [];
+ # reformat each field to this field's column width
+ for f in range(len(input_fields)):
+ output_field = input_fields[f];
+ output_fields.append(output_field.ljust(field_width[f]))
+ # any missing field is set to default if it exists
+ if default_field != '':
+ for f in range(len(input_fields),len(field_width)):
+ output_fields.append(default_field.ljust(field_width[f]))
+ # join fields using two spaces, like column -t would
+ output_line = ' '.join(output_fields);
+ # collect line for later
+ sortable_lines.append(output_line)
+ else:
+ # this line is non-sortable
+ # sort collected sortable lines
+ if ignore_case!=0:
+ sortable_lines.sort(key=lambda x: str.lower(locale.strxfrm(x)))
+ else:
+ sortable_lines.sort(key=lambda x: locale.strxfrm(x))
+ # append sortable lines to the final output
+ output_lines.extend(sortable_lines)
+ sortable_lines = []
+ # append non-sortable line to the final output
+ output_lines.append(input_line)
+# maybe we had sortable lines pending, so append them to the final output
+if ignore_case!=0:
+ sortable_lines.sort(key=lambda x: str.lower(locale.strxfrm(x)))
+else:
+ sortable_lines.sort(key=lambda x: locale.strxfrm(x))
+output_lines.extend(sortable_lines)
+
+# run through output lines and print them, except rightmost whitespace
+
+for output_line in output_lines:
+ print output_line.rstrip()
--
1.8.1.2
next prev parent reply other threads:[~2013-07-26 21:37 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-23 20:28 [U-Boot] [RFC] [PATCH 0/5] Refactor MAINTAINERS file Albert ARIBAUD
2013-07-23 20:28 ` [U-Boot] [RFC] [PATCH 1/5] MAINTAINERS: move ARM entries into ARM section Albert ARIBAUD
2013-07-23 20:28 ` [U-Boot] [RFC] [PATCH 2/5] MAINTAINERS: move improperly placed e-mail addresses Albert ARIBAUD
2013-07-23 20:28 ` [U-Boot] [RFC] [PATCH 3/5] MAINTAINERS: remove misplaced comments Albert ARIBAUD
2013-07-23 20:29 ` [U-Boot] [RFC] [PATCH 4/5] MAINTAINERS: remove useless 'header' lines Albert ARIBAUD
2013-07-23 20:29 ` [U-Boot] [RFC] [PATCH 5/5] MAINTAINERS: refactor file for easier processing Albert ARIBAUD
2013-07-23 20:51 ` Otavio Salvador
2013-07-24 5:57 ` Albert ARIBAUD
2013-07-24 4:34 ` [U-Boot] [RFC] [PATCH 0/5] Refactor MAINTAINERS file Wolfgang Denk
2013-07-25 10:11 ` Albert ARIBAUD
2013-07-26 21:37 ` [U-Boot] [RFC V2 0/9] " Albert ARIBAUD
2013-07-26 21:37 ` [U-Boot] [RFC V2 1/9] MAINTAINERS: move ARM entries into ARM section Albert ARIBAUD
2013-07-26 21:37 ` [U-Boot] [RFC V2 2/9] MAINTAINERS: move improperly placed e-mail addresses Albert ARIBAUD
2013-07-26 21:37 ` [U-Boot] [RFC V2 3/9] MAINTAINERS: remove misplaced comments Albert ARIBAUD
2013-07-26 21:37 ` [U-Boot] [RFC V2 4/9] MAINTAINERS: remove useless 'header' lines Albert ARIBAUD
2013-07-26 21:37 ` [U-Boot] [RFC V2 5/9] MAINTAINERS: refactor file for easier processing Albert ARIBAUD
2013-07-26 21:37 ` Albert ARIBAUD [this message]
2013-07-26 21:37 ` [U-Boot] [RFC V2 7/9] reformat MAINTAINERS and boards.cfg Albert ARIBAUD
2013-07-26 21:37 ` [U-Boot] [RFC V2 8/9] boards.cfg: merge MAINTAINERS and reformat Albert ARIBAUD
2013-07-26 21:37 ` [U-Boot] [RFC V2 9/9] Changes due to boards.cfg reformat Albert ARIBAUD
2013-08-03 14:24 ` [U-Boot] [RFC V2 0/9] Refactor MAINTAINERS file Albert ARIBAUD
2013-08-05 14:28 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1374874635-12042-7-git-send-email-albert.u.boot@aribaud.net \
--to=albert.u.boot@aribaud.net \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox