avocado app: Entirely remove --relative-links from 'avocado run'

The option --relative links instructed the htmlresult plugin
whether to use absolute log paths in anchor tags, or to use
relative paths, something that dates back to the old autotest
html job report. After thinking about it I realized that this
option doesn't need to be here, as using relative links is
basically better for all intents and purposes (the job results
can be safely redistributed and the report would still work).

So get rid of that option and always use relative links for
the job results dir links and logs. Tested with local execution
as well as remote/vm execution.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 33620475
...@@ -42,13 +42,13 @@ class ReportModel(object): ...@@ -42,13 +42,13 @@ class ReportModel(object):
Prepares JSON that can be passed up to mustache for rendering. Prepares JSON that can be passed up to mustache for rendering.
""" """
def __init__(self, json_input, html_output, relative_links): def __init__(self, json_input, html_output):
""" """
Base JSON that comes from test results. Base JSON that comes from test results.
""" """
self.json = json_input self.json = json_input
self.relative_links = relative_links
self.html_output = html_output self.html_output = html_output
self.html_output_dir = os.path.abspath(os.path.dirname(html_output))
def get(self, key, default): def get(self, key, default):
value = getattr(self, key, default) value = getattr(self, key, default)
...@@ -63,20 +63,18 @@ class ReportModel(object): ...@@ -63,20 +63,18 @@ class ReportModel(object):
def execution_time(self): def execution_time(self):
return "%.2f" % self.json['time'] return "%.2f" % self.json['time']
def _results_dir(self, relative_links=True): def results_dir(self, relative_links=True):
debuglog_abspath = os.path.abspath(os.path.dirname( results_dir = os.path.abspath(os.path.dirname(self.json['debuglog']))
self.json['debuglog']))
html_output_abspath = os.path.abspath(os.path.dirname(self.html_output))
if relative_links: if relative_links:
return os.path.relpath(debuglog_abspath, html_output_abspath) return os.path.relpath(results_dir, self.html_output_dir)
else: else:
return debuglog_abspath return results_dir
def results_dir(self):
return self._results_dir(relative_links=self.relative_links)
def results_dir_basename(self): def results_dir_basename(self):
return os.path.basename(self._results_dir(relative_links=False)) return os.path.basename(self.results_dir(False))
def logdir(self):
return os.path.relpath(self.json['logdir'], self.html_output_dir)
def total(self): def total(self):
return self.json['total'] return self.json['total']
...@@ -94,7 +92,7 @@ class ReportModel(object): ...@@ -94,7 +92,7 @@ class ReportModel(object):
return "%.2f" % pr return "%.2f" % pr
def _get_sysinfo(self, sysinfo_file): def _get_sysinfo(self, sysinfo_file):
sysinfo_path = os.path.join(self._results_dir(relative_links=False), sysinfo_path = os.path.join(self.results_dir(False),
'sysinfo', 'pre', sysinfo_file) 'sysinfo', 'pre', sysinfo_file)
try: try:
with open(sysinfo_path, 'r') as sysinfo_file: with open(sysinfo_path, 'r') as sysinfo_file:
...@@ -122,15 +120,13 @@ class ReportModel(object): ...@@ -122,15 +120,13 @@ class ReportModel(object):
"NOSTATUS": "info", "NOSTATUS": "info",
"INTERRUPTED": "danger"} "INTERRUPTED": "danger"}
test_info = self.json['tests'] test_info = self.json['tests']
results_dir = self.results_dir(False)
for t in test_info: for t in test_info:
t['logdir'] = os.path.join(self._results_dir( logdir = os.path.join(results_dir, 'test-results', t['logdir'])
relative_links=self.relative_links), t['logdir'] = os.path.relpath(logdir, self.html_output_dir)
'test-results', t['logdir']) logfile = os.path.join(logdir, 'debug.log')
t['logfile'] = os.path.join(self._results_dir( t['logfile'] = os.path.relpath(logfile, self.html_output_dir)
relative_links=self.relative_links), t['logfile_basename'] = os.path.basename(logfile)
'test-results', t['logdir'],
'debug.log')
t['logfile_basename'] = os.path.basename(t['logfile'])
t['time'] = "%.2f" % t['time'] t['time'] = "%.2f" % t['time']
t['time_start'] = time.strftime("%Y-%m-%d %H:%M:%S", t['time_start'] = time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime(t['time_start'])) time.localtime(t['time_start']))
...@@ -148,7 +144,7 @@ class ReportModel(object): ...@@ -148,7 +144,7 @@ class ReportModel(object):
def sysinfo(self): def sysinfo(self):
sysinfo_list = [] sysinfo_list = []
base_path = os.path.join(self._results_dir(relative_links=False), base_path = os.path.join(self.results_dir(False),
'sysinfo', 'pre') 'sysinfo', 'pre')
try: try:
sysinfo_files = os.listdir(base_path) sysinfo_files = os.listdir(base_path)
...@@ -238,13 +234,7 @@ class HTMLTestResult(TestResult): ...@@ -238,13 +234,7 @@ class HTMLTestResult(TestResult):
self._render_report() self._render_report()
def _render_report(self): def _render_report(self):
if self.args is not None: context = ReportModel(json_input=self.json, html_output=self.output)
relative_links = getattr(self.args, 'relative_links')
else:
relative_links = False
context = ReportModel(json_input=self.json, html_output=self.output,
relative_links=relative_links)
html = HTML() html = HTML()
template = html.get_resource_path('templates', 'report.mustache') template = html.get_resource_path('templates', 'report.mustache')
...@@ -304,13 +294,6 @@ class HTML(plugin.Plugin): ...@@ -304,13 +294,6 @@ class HTML(plugin.Plugin):
'since not all HTML resources can be embedded into a ' 'since not all HTML resources can be embedded into a '
'single file (page resources will be copied to the ' 'single file (page resources will be copied to the '
'output file dir)')) 'output file dir)'))
self.parser.runner.output.add_argument(
'--relative-links',
dest='relative_links',
action='store_true',
default=False,
help=('On the HTML report, generate anchor links with relative '
'instead of absolute paths. Current: %s' % False))
self.parser.runner.output.add_argument( self.parser.runner.output.add_argument(
'--open-browser', '--open-browser',
dest='open_browser', dest='open_browser',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册