summaryrefslogtreecommitdiff
path: root/ick-html
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-10-21 22:55:10 +0300
committerLars Wirzenius <liw@liw.fi>2015-10-24 17:20:53 +0300
commit939214962dfb003db3d6f322398c344e95a9134a (patch)
treebd635d38916786ac8e45eb04b812d1f5bb537b63 /ick-html
parent72d1ed8ece7985245a80a477dea0d9286d815e00 (diff)
downloadick-939214962dfb003db3d6f322398c344e95a9134a.tar.gz
Add ick-html program
Diffstat (limited to 'ick-html')
-rwxr-xr-xick-html109
1 files changed, 109 insertions, 0 deletions
diff --git a/ick-html b/ick-html
new file mode 100755
index 0000000..08510c6
--- /dev/null
+++ b/ick-html
@@ -0,0 +1,109 @@
+#!/usr/bin/env python2
+# Copyright 2015 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# =*= License: GPL-3+ =*=
+
+
+import glob
+import os
+import shutil
+
+import cliapp
+import jinja2
+import yaml
+
+import icklib
+
+
+class IckHTML(cliapp.Application):
+
+ def process_args(self, args):
+ ick_filename, html_dir = self.parse_command_line_args(args)
+ ick = self.read_ick_file(ick_filename)
+ self.create_html(ick_filename, ick, html_dir)
+
+ def parse_command_line_args(self, args):
+ if len(args) != 2:
+ raise cliapp.AppException('Must have exactly one argument')
+ return args[0], args[1]
+
+ def read_ick_file(self, filename):
+ with open(filename) as f:
+ return yaml.safe_load(f)
+
+ def create_html(self, ick_filename, ick, html_dir):
+ loader = jinja2.PackageLoader('icklib', 'templates')
+ env = jinja2.Environment(
+ loader=loader,
+ autoescape=lambda foo: True,
+ extensions=['jinja2.ext.autoescape'])
+
+ statedir = icklib.create_statedir_from_ick(ick)
+
+ self.create_index_html(ick_filename, ick, env, html_dir)
+ for project in self.get_projects(ick):
+ project.builds = statedir.get_build_infos(project.name)
+ self.copy_build_files_to_html_dir(statedir, project, html_dir)
+ self.create_project_html(statedir, project, env, html_dir)
+
+ def create_index_html(self, ick_filename, ick, env, html_dir):
+ vars = {
+ 'ick_filename': ick_filename,
+ 'projects': self.get_projects(ick),
+ 'statedir': icklib.create_statedir_from_ick(ick),
+ }
+
+ template = env.get_template('index.j2')
+ with open(os.path.join(html_dir, 'index.html'), 'w') as f:
+ f.write(template.render(**vars))
+
+ def get_projects(self, ick):
+ return sorted(
+ icklib.create_projects_from_ick(ick, None),
+ key=lambda p: p.name)
+
+ def copy_build_files_to_html_dir(self, statedir, project, html_dir):
+ for build in project.builds:
+ build_dir = os.path.join(
+ html_dir, project.name, str(build.build_number))
+ os.makedirs(build_dir)
+ self.copy_build_log(build, build_dir)
+ self.copy_build_artifacts(statedir, project, build, build_dir)
+
+ def copy_build_log(self, build, build_dir):
+ orig = build.get_build_log_filename()
+ target = os.path.join(build_dir, 'build_log.txt')
+ shutil.copy(orig, target)
+
+ def copy_build_artifacts(self, statedir, project, build, build_dir):
+ artifacts = build.get_artifacts_directory()
+ target = os.path.join(build_dir, 'build_log.txt')
+ for artifact in glob.glob(os.path.join(artifacts, '*')):
+ shutil.copy(artifact, build_dir)
+
+ def create_project_html(self, statedir, project, env, html_dir):
+
+ vars = {
+ 'project': project,
+ }
+
+ template = env.get_template('project.j2')
+ with open(os.path.join(html_dir, '%s.html' % project.name), 'w') as f:
+ f.write(template.render(**vars))
+
+
+if __name__ == '__main__':
+ IckHTML().run()