sb/reports: add sanitize parameter enabled for --mail

Adds a --sanitize option to command line for reports.py
and also for the reports.report() interface from setbuilder.py
to remove the Remotes information from git.

Closes #3887.
This commit is contained in:
Gedare Bloom 2020-04-01 22:29:31 -06:00
parent 113c65cb56
commit 4727c3e58f
2 changed files with 35 additions and 21 deletions

View File

@ -241,6 +241,9 @@ class markdown_formatter(formatter):
self.line(self._strong('Remotes:')) self.line(self._strong('Remotes:'))
self.line('') self.line('')
rc = 1 rc = 1
if not remotes:
self.line('[ remotes removed, contact sender for details ]')
else:
for r in remotes: for r in remotes:
if 'url' in remotes[r]: if 'url' in remotes[r]:
text = remotes[r]['url'] text = remotes[r]['url']
@ -427,6 +430,9 @@ class text_formatter(formatter):
if valid: if valid:
self.line('%s Remotes:' % (self.cini)) self.line('%s Remotes:' % (self.cini))
rc = 0 rc = 0
if not remotes:
self.line('[ remotes removed, contact sender for details ]')
else:
for r in remotes: for r in remotes:
rc += 1 rc += 1
if 'url' in remotes[r]: if 'url' in remotes[r]:
@ -603,7 +609,7 @@ def _merge(_dict, new):
class report: class report:
"""Report the build details about a package given a config file.""" """Report the build details about a package given a config file."""
def __init__(self, formatter, _configs, opts, macros = None): def __init__(self, formatter, sanitize, _configs, opts, macros = None):
if type(formatter) == str: if type(formatter) == str:
if formatter == 'text': if formatter == 'text':
self.formatter = text_formatter() self.formatter = text_formatter()
@ -621,6 +627,7 @@ class report:
self.formatter = formatter self.formatter = formatter
self.configs = _configs self.configs = _configs
self.opts = opts self.opts = opts
self.sanitize = sanitize
if macros is None: if macros is None:
self.macros = opts.defaults self.macros = opts.defaults
else: else:
@ -649,6 +656,9 @@ class report:
def git_status(self): def git_status(self):
r = git.repo('.', self.opts, self.macros) r = git.repo('.', self.opts, self.macros)
if self.sanitize:
self.formatter.git_status(r.valid(), r.dirty(), r.head(), None)
else:
self.formatter.git_status(r.valid(), r.dirty(), r.head(), r.remotes()) self.formatter.git_status(r.valid(), r.dirty(), r.head(), r.remotes())
def introduction(self, name, intro_text = None): def introduction(self, name, intro_text = None):
@ -892,7 +902,8 @@ def run(args):
optargs = { '--list-bsets': 'List available build sets', optargs = { '--list-bsets': 'List available build sets',
'--list-configs': 'List available configurations', '--list-configs': 'List available configurations',
'--format': 'Output format (text, html, markdown, ini, xml)', '--format': 'Output format (text, html, markdown, ini, xml)',
'--output': 'File name to output the report' } '--output': 'File name to output the report',
'--sanitize': 'Remove Remotes information from report'}
opts = options.load(args, optargs, logfile = False) opts = options.load(args, optargs, logfile = False)
if opts.get_arg('--output') and len(opts.params()) > 1: if opts.get_arg('--output') and len(opts.params()) > 1:
raise error.general('--output can only be used with a single config') raise error.general('--output can only be used with a single config')
@ -922,7 +933,10 @@ def run(args):
formatter = xml_formatter() formatter = xml_formatter()
else: else:
raise error.general('invalid format: %s' % (format_opt[1])) raise error.general('invalid format: %s' % (format_opt[1]))
r = report(formatter, configs, opts) sanitize = False
if opts.get_arg('--sanitize'):
sanitize = True
r = report(formatter, sanitize, configs, opts)
for _config in opts.params(): for _config in opts.params():
if output is None: if output is None:
outname = path.splitext(_config)[0] + formatter.ext() outname = path.splitext(_config)[0] + formatter.ext()

View File

@ -189,7 +189,7 @@ class buildset:
outname = path.host(path.join(outpath, name)) outname = path.host(path.join(outpath, name))
else: else:
outname = None outname = None
r = reports.report(format, self.configs, r = reports.report(format, False, self.configs,
copy.copy(opts), copy.copy(macros)) copy.copy(opts), copy.copy(macros))
r.introduction(_build.config.file_name()) r.introduction(_build.config.file_name())
r.generate(_build.config.file_name()) r.generate(_build.config.file_name())
@ -199,7 +199,7 @@ class buildset:
r.write(outname) r.write(outname)
del r del r
if mail: if mail:
r = reports.report('text', self.configs, r = reports.report('text', True, self.configs,
copy.copy(opts), copy.copy(macros)) copy.copy(opts), copy.copy(macros))
r.introduction(_build.config.file_name()) r.introduction(_build.config.file_name())
r.generate(_build.config.file_name()) r.generate(_build.config.file_name())