[gitdm v2] reports.py: Add very basic rST output

Add a -R option to gitdm to allow for reStructuredText output and add some very simple table generation. We assume that whatever uses this output will be including it in other documents and we only concern ourselves with making tables. Give ourselves 36 characters to fill in the nae field, as this tends to be long enough and can be corrected manually in the cases where it's slightly too short still.
Cc: Heinrich Schuchardt xypron.glpk@gmx.de Signed-off-by: Tom Rini trini@konsulko.com --- Changes in v2: - Rework how we declare a table, per Heinrich --- gitdm | 5 ++++- reports.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/gitdm b/gitdm index b837f0aafe27..3568d08f55af 100755 --- a/gitdm +++ b/gitdm @@ -59,6 +59,7 @@ FileReport = None # -D Output date statistics # -f file Write touched-files report to <file> # -h hfile HTML output to hfile +# -R rfile reStructuredText output to rfile # -H file Export individual developer raw data as CSV # -l count Maximum length for output lists # -n Use numstats instead of generated patch from git log @@ -80,7 +81,7 @@ def ParseOpts(): global ReportByFileType, ReportUnknowns, CompanyFilter, FileReport global HackersCSV
- opts, rest = getopt.getopt(sys.argv[1:], 'ab:dC:c:Df:H:h:l:no:p:r:stUuwx:yz') + opts, rest = getopt.getopt(sys.argv[1:], 'ab:dC:c:Df:H:h:l:no:p:r:R:stUuwx:yz') for opt in opts: if opt[0] == '-a': AkpmOverLt = 1 @@ -111,6 +112,8 @@ def ParseOpts(): elif opt[0] == '-r': print('Filter on "%s"' % (opt[1])) FileFilter = re.compile(opt[1]) + elif opt[0] == '-R': + reports.SetrSTOutput(open(opt[1], 'w')) elif opt[0] == '-s': AuthorSOBs = 0 elif opt[0] == '-t': diff --git a/reports.py b/reports.py index 39c237bdae00..782ebb8fb032 100644 --- a/reports.py +++ b/reports.py @@ -14,6 +14,7 @@ import sys
Outfile = sys.stdout HTMLfile = None +rSTfile = None ListCount = 999999
@@ -25,6 +26,10 @@ def SetHTMLOutput(file): global HTMLfile HTMLfile = file
+def SetrSTOutput(file): + global rSTfile + rSTfile = file + def SetMaxList(max): global ListCount ListCount = max @@ -40,10 +45,21 @@ THead = '''<p> <tr><th colspan=3>%s</th></tr> '''
+RHead = ''' +.. table:: %s + :widths: auto + + ==================================== ===== + Name Count + ==================================== ===== +''' + def BeginReport(title): Outfile.write('\n%s\n' % title) if HTMLfile: HTMLfile.write(THead % title) + if rSTfile: + rSTfile.write(RHead % title)
TRow = ' <tr><td>%s</td><td align="right">%d</td><td align="right">%.1f%%</td></tr>\n' TRowStr = ' <tr><td>%s</td><td align="right">%d</td><td>%s</td></tr>\n' @@ -54,6 +70,8 @@ def ReportLine(text, count, pct): Outfile.write ('%-25s %4d (%.1f%%)\n' % (text, count, pct)) if HTMLfile: HTMLfile.write(TRow % (text, count, pct)) + if rSTfile: + rSTfile.write(" %-36s %d (%.1f%%)\n" % (text.strip(), count, pct))
def ReportLineStr(text, count, extra): if count == 0: @@ -61,10 +79,14 @@ def ReportLineStr(text, count, extra): Outfile.write ('%-25s %4d %s\n' % (text, count, extra)) if HTMLfile: HTMLfile.write(TRowStr % (text, count, extra)) + if rSTfile: + rSTfile.write('%-36s %d %s\n' % (text, count, extra))
def EndReport(): if HTMLfile: HTMLfile.write('</table>\n\n') + if rSTfile: + rSTfile.write(' ==================================== =====\n\n')
# # Comparison and report generation functions.

On Tue, 12 Jul 2022 at 15:14, Tom Rini trini@konsulko.com wrote:
Add a -R option to gitdm to allow for reStructuredText output and add some very simple table generation. We assume that whatever uses this output will be including it in other documents and we only concern ourselves with making tables. Give ourselves 36 characters to fill in the nae field, as this tends to be long enough and can be corrected manually in the cases where it's slightly too short still.
Cc: Heinrich Schuchardt xypron.glpk@gmx.de Signed-off-by: Tom Rini trini@konsulko.com
Changes in v2:
- Rework how we declare a table, per Heinrich
gitdm | 5 ++++- reports.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org
participants (2)
-
Simon Glass
-
Tom Rini