[U-Boot] [PATCH 0/2] Fill blank fields of doc/README.scrapyard with a tool

Masahiro Yamada (2): scripts: add a utility to fill blank fields of doc/README.scrapyard README.scrapyard: fill commit and date fields
doc/README.scrapyard | 96 +++++++++++++------------- scripts/fill_scrapyard.py | 168 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 216 insertions(+), 48 deletions(-) create mode 100755 scripts/fill_scrapyard.py

We are removing bunch of non-generic boards these days.
Updating doc/README.scrapyard is a really tedious task, but it can be automated. I hope this tool will make our life easier.
Signed-off-by: Masahiro Yamada yamada.m@jp.panasonic.com ---
scripts/fill_scrapyard.py | 168 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100755 scripts/fill_scrapyard.py
diff --git a/scripts/fill_scrapyard.py b/scripts/fill_scrapyard.py new file mode 100755 index 0000000..6895c9f --- /dev/null +++ b/scripts/fill_scrapyard.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python2 +# +# Author: Masahiro Yamada yamada.m@jp.panasonic.com +# +# SPDX-License-Identifier: GPL-2.0+ +# + +""" +Fill the "Commit" and "Removed" fields of doc/README.scrapyard + +The file doc/README.scrapyard is used to keep track of removed boards. + +When we remove support for boards, we are supposed to add entries to +doc/README.scrapyard leaving "Commit" and "Removed" fields blank. + +The "Commit" field is the commit hash in which the board was removed +and the "Removed" is the date at which the board was removed. Those +two are known only after the board removal patch was applied, thus they +need to be filled in later. + +This effectively means that the person who removes another board is +first supposed to fill in the blank fields and then add the board that +is being removed, again with blank fields for the commit hash and date +of removal. + +That is a really tedious task that should be automated. +This script fills the blank fields of doc/README.scrapyard for you! + +Usage: + +The "Commit" and "Removed" fields must be "-". The other fields should +have already been filled in by a former commit. + +Run + scripts/fill_scrapyard.py +""" + +import os +import subprocess +import sys +import tempfile + +DOC='doc/README.scrapyard' + +def get_last_modify_commit(file, line_num): + """Get the commit that last modified the given line. + + This function runs "git blame" against the given line of the given + file and returns the commit hash that last modified it. + + Arguments: + file: the file to be git-blame'd. + line_num: the line number to be git-blame'd. This line number + starts from 1, not 0. + + Returns: + Commit hash that last modified the line. The number of digits is + long enough to form a unique commit. + """ + result = subprocess.check_output(['git', 'blame', '-L', + '%d,%d' % (line_num, line_num), file]) + commit = result.split()[0] + + if commit[0] == '^': + sys.exit('%s: line %d: ' % (file, line_num) + + 'this line was modified before the beginning of git history') + + if commit == '0' * len(commit): + sys.exit('%s: line %d: locally modified\n' % (file, line_num) + + 'Please run this tool in a clean repository.') + + return commit + +def get_committer_date(commit): + """Get the committer date of the given commit. + + This function returns the date when the given commit was applied. + + Arguments: + commit: commit-ish object. + + Returns: + The committer date of the given commit in the form YY-MM-DD. + """ + committer_date = subprocess.check_output(['git', 'show', '-s', + '--format=%ci', commit]) + return committer_date.split()[0] + +def move_to_topdir(): + """Change directory to the top of the git repository. + + Or, exit with an error message if called out of a git repository. + """ + try: + toplevel = subprocess.check_output(['git', 'rev-parse', + '--show-toplevel']) + except subprocess.CalledProcessError: + sys.exit('Please run in a git repository.') + + # strip '\n' + toplevel = toplevel.rstrip() + + # Change the current working directory to the toplevel of the respository + # for our easier life. + os.chdir(toplevel) + +class TmpFile: + + """Useful class to handle a temporary file. + + tempfile.mkstemp() is often used to create a unique temporary file, + but what is inconvenient is that the caller is responsible for + deleting the file when done with it. + + Even when the caller errors out on the way, the temporary file must + be deleted somehow. The idea here is that we delete the file in + the destructor of this class because the destructor is always + invoked when the instance of the class is freed. + """ + + def __init__(self): + """Constructor - create a temporary file""" + fd, self.filename = tempfile.mkstemp() + self.file = os.fdopen(fd, 'w') + + def __del__(self): + """Destructor - delete the temporary file""" + try: + os.remove(self.filename) + except: + pass + +def main(): + move_to_topdir() + + with open(DOC) as f: + lines = f.readlines() + + line_num = 1 + + tmpfile = TmpFile() + for line in open(DOC): + tmp = line.split(None, 5) + modified = False + + if len(tmp) >= 5: + if tmp[3] == '-': + tmp[3] = get_last_modify_commit(DOC, line_num) + modified = True + if tmp[4] == '-': + tmp[4] = get_committer_date(tmp[3]) + if modified: + line = tmp[0].ljust(17) + line += tmp[1].ljust(12) + line += tmp[2].ljust(15) + line += tmp[3].ljust(12) + line += tmp[4].ljust(12) + if len(tmp) >= 6: + line += tmp[5] + line = line.rstrip() + '\n' + + tmpfile.file.write(line) + line_num += 1 + + os.rename(tmpfile.filename, DOC) + +if __name__ == '__main__': + main()

Hi Masahiro,
On 13 January 2015 at 11:13, Masahiro Yamada yamada.m@jp.panasonic.com wrote:
We are removing bunch of non-generic boards these days.
Updating doc/README.scrapyard is a really tedious task, but it can be automated. I hope this tool will make our life easier.
Signed-off-by: Masahiro Yamada yamada.m@jp.panasonic.com
scripts/fill_scrapyard.py | 168 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100755 scripts/fill_scrapyard.py
Reviewed-by: Simon Glass sjg@chromium.org
Note there is gitutils.GetTopLevel() available. I don't think you want to use the patman libraries, but thought I would mention it.
diff --git a/scripts/fill_scrapyard.py b/scripts/fill_scrapyard.py new file mode 100755 index 0000000..6895c9f --- /dev/null +++ b/scripts/fill_scrapyard.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python2 +# +# Author: Masahiro Yamada yamada.m@jp.panasonic.com +# +# SPDX-License-Identifier: GPL-2.0+ +#
+""" +Fill the "Commit" and "Removed" fields of doc/README.scrapyard
+The file doc/README.scrapyard is used to keep track of removed boards.
+When we remove support for boards, we are supposed to add entries to +doc/README.scrapyard leaving "Commit" and "Removed" fields blank.
+The "Commit" field is the commit hash in which the board was removed +and the "Removed" is the date at which the board was removed. Those +two are known only after the board removal patch was applied, thus they +need to be filled in later.
+This effectively means that the person who removes another board is +first supposed to fill in the blank fields and then add the board that +is being removed, again with blank fields for the commit hash and date +of removal.
+That is a really tedious task that should be automated. +This script fills the blank fields of doc/README.scrapyard for you!
+Usage:
+The "Commit" and "Removed" fields must be "-". The other fields should +have already been filled in by a former commit.
+Run
- scripts/fill_scrapyard.py
+"""
+import os +import subprocess +import sys +import tempfile
+DOC='doc/README.scrapyard'
+def get_last_modify_commit(file, line_num):
- """Get the commit that last modified the given line.
- This function runs "git blame" against the given line of the given
- file and returns the commit hash that last modified it.
- Arguments:
file: the file to be git-blame'd.
line_num: the line number to be git-blame'd. This line number
starts from 1, not 0.
- Returns:
Commit hash that last modified the line. The number of digits is
long enough to form a unique commit.
- """
- result = subprocess.check_output(['git', 'blame', '-L',
'%d,%d' % (line_num, line_num), file])
- commit = result.split()[0]
- if commit[0] == '^':
sys.exit('%s: line %d: ' % (file, line_num) +
'this line was modified before the beginning of git history')
- if commit == '0' * len(commit):
sys.exit('%s: line %d: locally modified\n' % (file, line_num) +
'Please run this tool in a clean repository.')
- return commit
+def get_committer_date(commit):
- """Get the committer date of the given commit.
- This function returns the date when the given commit was applied.
- Arguments:
commit: commit-ish object.
- Returns:
The committer date of the given commit in the form YY-MM-DD.
- """
- committer_date = subprocess.check_output(['git', 'show', '-s',
'--format=%ci', commit])
- return committer_date.split()[0]
+def move_to_topdir():
- """Change directory to the top of the git repository.
- Or, exit with an error message if called out of a git repository.
- """
- try:
toplevel = subprocess.check_output(['git', 'rev-parse',
'--show-toplevel'])
- except subprocess.CalledProcessError:
sys.exit('Please run in a git repository.')
- # strip '\n'
- toplevel = toplevel.rstrip()
- # Change the current working directory to the toplevel of the respository
- # for our easier life.
- os.chdir(toplevel)
+class TmpFile:
- """Useful class to handle a temporary file.
- tempfile.mkstemp() is often used to create a unique temporary file,
- but what is inconvenient is that the caller is responsible for
- deleting the file when done with it.
- Even when the caller errors out on the way, the temporary file must
- be deleted somehow. The idea here is that we delete the file in
- the destructor of this class because the destructor is always
- invoked when the instance of the class is freed.
- """
- def __init__(self):
"""Constructor - create a temporary file"""
fd, self.filename = tempfile.mkstemp()
self.file = os.fdopen(fd, 'w')
- def __del__(self):
"""Destructor - delete the temporary file"""
try:
os.remove(self.filename)
except:
pass
+def main():
- move_to_topdir()
- with open(DOC) as f:
lines = f.readlines()
- line_num = 1
- tmpfile = TmpFile()
- for line in open(DOC):
tmp = line.split(None, 5)
modified = False
if len(tmp) >= 5:
if tmp[3] == '-':
tmp[3] = get_last_modify_commit(DOC, line_num)
modified = True
if tmp[4] == '-':
tmp[4] = get_committer_date(tmp[3])
if modified:
line = tmp[0].ljust(17)
line += tmp[1].ljust(12)
line += tmp[2].ljust(15)
line += tmp[3].ljust(12)
line += tmp[4].ljust(12)
if len(tmp) >= 6:
line += tmp[5]
line = line.rstrip() + '\n'
tmpfile.file.write(line)
line_num += 1
- os.rename(tmpfile.filename, DOC)
+if __name__ == '__main__':
- main()
-- 1.9.1
Regards, Simon

This commit was generated by the following command:
scripts/fill_scrapyard.py
Signed-off-by: Masahiro Yamada yamada.m@jp.panasonic.com ---
I notice lots of ppc4xx boards are being removed.
I will send v2 later.
doc/README.scrapyard | 96 ++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 48 deletions(-)
diff --git a/doc/README.scrapyard b/doc/README.scrapyard index 5d2875c..3772010 100644 --- a/doc/README.scrapyard +++ b/doc/README.scrapyard @@ -12,54 +12,54 @@ The list should be sorted in reverse chronological order.
Board Arch CPU Commit Removed Last known maintainer/contact ================================================================================================= -A3000 powerpc mpc824x - - -CPC45 powerpc mpc824x - - Josef Wagner Wagner@Microsys.de -CU824 powerpc mpc824x - - Wolfgang Denk wd@denx.de -eXalion powerpc mpc824x - - Torsten Demke torsten.demke@fci.com -MVBLUE powerpc mpc824x - - -MUSENKI powerpc mpc824x - - Jim Thompson jim@musenki.com -Sandpoint8240 powerpc mpc824x - - Wolfgang Denk wd@denx.de -Sandpoint8245 powerpc mpc824x - - Jim Thompson jim@musenki.com -utx8245 powerpc mpc824x - - Greg Allen gallen@arlut.utexas.edu -atc powerpc mpc8260 - - Wolfgang Denk wd@denx.de -CPU86 powerpc mpc8260 - - Wolfgang Denk wd@denx.de -CPU87 powerpc mpc8260 - - -ep82xxm powerpc mpc8260 - - -gw8260 powerpc mpc8260 - - Oliver Brown obrown@adventnetworks.com -IPHASE4539 powerpc mpc8260 - - Wolfgang Grandegger wg@denx.de -muas3001 powerpc mpc8260 - - Heiko Schocher hs@denx.de -PM825 powerpc mpc8260 - - Wolfgang Denk wd@denx.de -PM826 powerpc mpc8260 - - Wolfgang Denk wd@denx.de -PM828 powerpc mpc8260 - - -MPC8266ADS powerpc mpc8260 - - Rune Torgersen runet@innovsys.com -VoVPN-GW powerpc mpc8260 - - -ep8260 powerpc mpc8260 - - Frank Panno fpanno@delphintech.com -ppmc8260 powerpc mpc8260 - - Brad Kemp Brad.Kemp@seranoa.com -sacsng powerpc mpc8260 - - Jerry Van Baren gerald.vanbaren@smiths-aerospace.com -cogent_mpc8260 powerpc mpc8260 - - Murray Jensen Murray.Jensen@csiro.au -cogent_8xx powerpc mpc8xx - - Murray Jensen Murray.Jensen@csiro.au -ESTEEM192E powerpc mpc8xx - - Conn Clark clark@esteem.com -IP860 powerpc mpc8xx - - Wolfgang Denk wd@denx.de -IVML24 powerpc mpc8xx - - Wolfgang Denk wd@denx.de -IVMS8 powerpc mpc8xx - - Wolfgang Denk wd@denx.de -lwmon powerpc mpc8xx - - Wolfgang Denk wd@denx.de -NETVIA powerpc mpc8xx - - Pantelis Antoniou panto@intracom.gr -R360MPI powerpc mpc8xx - - Wolfgang Denk wd@denx.de -RRvision powerpc mpc8xx - - Wolfgang Denk wd@denx.de -SPD823TS powerpc mpc8xx - - Wolfgang Denk wd@denx.de -KUP4K powerpc mpc8xx - - Klaus Heydeck heydeck@kieback-peter.de -KUP4X powerpc mpc8xx - - Klaus Heydeck heydeck@kieback-peter.de -ELPT860 powerpc mpc8xx - - The LEOX team team@leox.org -hmi1001 powerpc mpc5xxx - - -mucmc52 powerpc mpc5xxx - - Heiko Schocher hs@denx.de -uc101 powerpc mpc5xxx - - Heiko Schocher hs@denx.de -uc100 powerpc mpc8xx - - Stefan Roese sr@denx.de -FPS850L powerpc mpc8xx - - Wolfgang Denk wd@denx.de -FPS860L powerpc mpc8xx - - Wolfgang Denk wd@denx.de -NSCU powerpc mpc8xx - - -SM850 powerpc mpc8xx - - Wolfgang Denk wd@denx.de -TK885D powerpc mpc8xx - - -virtlab2 powerpc mpc8xx - - Wolfgang Denk wd@denx.de +A3000 powerpc mpc824x d622ac39 2015-01-05 +CPC45 powerpc mpc824x d622ac39 2015-01-05 Josef Wagner Wagner@Microsys.de +CU824 powerpc mpc824x d622ac39 2015-01-05 Wolfgang Denk wd@denx.de +eXalion powerpc mpc824x d622ac39 2015-01-05 Torsten Demke torsten.demke@fci.com +MVBLUE powerpc mpc824x d622ac39 2015-01-05 +MUSENKI powerpc mpc824x d622ac39 2015-01-05 Jim Thompson jim@musenki.com +Sandpoint8240 powerpc mpc824x d622ac39 2015-01-05 Wolfgang Denk wd@denx.de +Sandpoint8245 powerpc mpc824x d622ac39 2015-01-05 Jim Thompson jim@musenki.com +utx8245 powerpc mpc824x d622ac39 2015-01-05 Greg Allen gallen@arlut.utexas.edu +atc powerpc mpc8260 9067b300 2015-01-05 Wolfgang Denk wd@denx.de +CPU86 powerpc mpc8260 f7e1af86 2015-01-05 Wolfgang Denk wd@denx.de +CPU87 powerpc mpc8260 f7e1af86 2015-01-05 +ep82xxm powerpc mpc8260 e2b19629 2015-01-05 +gw8260 powerpc mpc8260 8eecbaf3 2015-01-05 Oliver Brown obrown@adventnetworks.com +IPHASE4539 powerpc mpc8260 87882f57 2015-01-05 Wolfgang Grandegger wg@denx.de +muas3001 powerpc mpc8260 d2fd1d66 2015-01-05 Heiko Schocher hs@denx.de +PM825 powerpc mpc8260 dc0b2fb4 2015-01-05 Wolfgang Denk wd@denx.de +PM826 powerpc mpc8260 dc0b2fb4 2015-01-05 Wolfgang Denk wd@denx.de +PM828 powerpc mpc8260 dc0b2fb4 2015-01-05 +MPC8266ADS powerpc mpc8260 b3a2bbe1 2015-01-05 Rune Torgersen runet@innovsys.com +VoVPN-GW powerpc mpc8260 cc90905f 2015-01-05 +ep8260 powerpc mpc8260 4ad015ba 2015-01-05 Frank Panno fpanno@delphintech.com +ppmc8260 powerpc mpc8260 793116d2 2015-01-05 Brad Kemp Brad.Kemp@seranoa.com +sacsng powerpc mpc8260 b35c0ad6 2015-01-05 Jerry Van Baren gerald.vanbaren@smiths-aerospace.com +cogent_mpc8260 powerpc mpc8260 d19f6a60 2015-01-05 Murray Jensen Murray.Jensen@csiro.au +cogent_8xx powerpc mpc8xx d19f6a60 2015-01-05 Murray Jensen Murray.Jensen@csiro.au +ESTEEM192E powerpc mpc8xx af0e3514 2015-01-05 Conn Clark clark@esteem.com +IP860 powerpc mpc8xx 5ec71100 2015-01-05 Wolfgang Denk wd@denx.de +IVML24 powerpc mpc8xx ca620cd1 2015-01-05 Wolfgang Denk wd@denx.de +IVMS8 powerpc mpc8xx ca620cd1 2015-01-05 Wolfgang Denk wd@denx.de +lwmon powerpc mpc8xx acc2372d 2015-01-05 Wolfgang Denk wd@denx.de +NETVIA powerpc mpc8xx f017cd7f 2015-01-05 Pantelis Antoniou panto@intracom.gr +R360MPI powerpc mpc8xx 79cbecb8 2015-01-05 Wolfgang Denk wd@denx.de +RRvision powerpc mpc8xx 8737fc75 2015-01-05 Wolfgang Denk wd@denx.de +SPD823TS powerpc mpc8xx 72ba368f 2015-01-05 Wolfgang Denk wd@denx.de +KUP4K powerpc mpc8xx 4317d070 2015-01-05 Klaus Heydeck heydeck@kieback-peter.de +KUP4X powerpc mpc8xx 4317d070 2015-01-05 Klaus Heydeck heydeck@kieback-peter.de +ELPT860 powerpc mpc8xx 3c5b20f1 2015-01-05 The LEOX team team@leox.org +hmi1001 powerpc mpc5xxx ceaf499b 2015-01-05 +mucmc52 powerpc mpc5xxx ceaf499b 2015-01-05 Heiko Schocher hs@denx.de +uc101 powerpc mpc5xxx ceaf499b 2015-01-05 Heiko Schocher hs@denx.de +uc100 powerpc mpc8xx ceaf499b 2015-01-05 Stefan Roese sr@denx.de +FPS850L powerpc mpc8xx 5d2a5ef7 2015-01-05 Wolfgang Denk wd@denx.de +FPS860L powerpc mpc8xx 5d2a5ef7 2015-01-05 Wolfgang Denk wd@denx.de +NSCU powerpc mpc8xx 5d2a5ef7 2015-01-05 +SM850 powerpc mpc8xx 5d2a5ef7 2015-01-05 Wolfgang Denk wd@denx.de +TK885D powerpc mpc8xx 5d2a5ef7 2015-01-05 +virtlab2 powerpc mpc8xx 5d2a5ef7 2015-01-05 Wolfgang Denk wd@denx.de hermes powerpc mpc8xx 36da51e 2014-12-08 Wolfgang Denk wd@denx.de PRS200 powerpc mpc5200 ecfdcee 2014-11-12 MCC200 powerpc mpc5200 ecfdcee 2014-11-12

On Wed, Jan 14, 2015 at 04:13:24AM +0900, Masahiro Yamada wrote:
Masahiro Yamada (2): scripts: add a utility to fill blank fields of doc/README.scrapyard README.scrapyard: fill commit and date fields
Yay, thanks!
participants (3)
-
Masahiro Yamada
-
Simon Glass
-
Tom Rini