Refactoring: better method name
[ci.git] / hbuild / web.py
blob0db871af2e1107e2dbc4e822ed16e26ca9627ae2
1 #!/usr/bin/env python3
4 # Copyright (c) 2017 Vojtech Horky
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
11 # - Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # - Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # - The name of the author may not be used to endorse or promote products
17 # derived from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 from hbuild.scheduler import Task
32 import os
34 class MakeHtmlReportTask(Task):
35 def __init__(self, root_path, rss_url, resource_path):
36 Task.__init__(self, 'html-report')
37 self.root = os.path.abspath(root_path)
38 self.rss_url = rss_url
39 self.static_resources_relative_path = resource_path
41 def copy_file_to_downloadable(self, source_filename, dest_filename):
42 with open(os.path.join(self.root, source_filename)) as input:
43 content = input.read()
44 with self.ctl.open_downloadable_file(dest_filename, 'w') as output:
45 output.write(content)
47 def run(self):
48 copy_static_resources = False
50 if self.static_resources_relative_path is None:
51 self.static_resources_relative_path = './'
52 copy_static_resources = True
54 command = [
55 'xsltproc',
56 '--stringparam',
57 'CONFIG_RESOURCE_DIR',
58 self.static_resources_relative_path,
61 if not self.rss_url is None:
62 command.append('--stringparam')
63 command.append('CONFIG_RSS_PATH')
64 command.append(self.rss_url)
66 command.append(os.path.join(self.root, 'hbuild/web/report.xsl'))
67 command.append(self.ctl.get_artefact_absolute_path('report.xml'))
69 res = self.ctl.run_command(command, needs_output=True)
70 if res['failed']:
71 return False
73 with self.ctl.open_downloadable_file('index.html', 'w') as index_html:
74 index_html.write(res['stdout'])
76 if copy_static_resources:
77 for filename in [ 'main.css', 'jquery-2.1.4.min.js' ]:
78 src = os.path.join('hbuild/web/', filename)
79 self.copy_file_to_downloadable(src, filename)