All of lore.kernel.org
 help / color / mirror / Atom feed
* [gitdm PATCH] reports.py: Add very basic rST output
@ 2022-07-12 12:11 Tom Rini
  0 siblings, 0 replies; only message in thread
From: Tom Rini @ 2022-07-12 12:11 UTC (permalink / raw)
  To: u-boot; +Cc: wd

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 take care of adding a header, so we only concern ourselves
with making tables.  Given the longest section title is 58 characters,
we use 60 as the magic number to write/pad all of our first columns to,
and use "Amount" for the second column.

Signed-off-by: Tom Rini <trini@konsulko.com>
---
 gitdm      |  5 ++++-
 reports.py | 14 ++++++++++++++
 2 files changed, 18 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..3ed21f29c6ac 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
@@ -44,6 +49,9 @@ def BeginReport(title):
     Outfile.write('\n%s\n' % title)
     if HTMLfile:
         HTMLfile.write(THead % title)
+    if rSTfile:
+        rSTfile.write('%s %s\n%-60s %s\n%s %s\n' %
+                ('=' * 60, '======', title, 'Amount', '=' * 60, '======'))
 
 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 +62,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("%-60s %4d (%.1f%%)\n" % (text.strip(), count, pct))
 
 def ReportLineStr(text, count, extra):
     if count == 0:
@@ -61,10 +71,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('* %s with %d %s\n' % (text, count, extra))
 
 def EndReport():
     if HTMLfile:
         HTMLfile.write('</table>\n\n')
+    if rSTfile:
+        rSTfile.write('%s ======\n\n' % ('=' * 60))
         
 #
 # Comparison and report generation functions.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-12 12:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12 12:11 [gitdm PATCH] reports.py: Add very basic rST output Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.