4 Generates static HTML for the given database file. 5 Warrning!: did not finish the implementation, see TODO comment. 7 Author: Albertas Gimbutas, Vilnius University (LT) 8 e-mail: albertasgim@gmail.com 10 from __future__
import absolute_import
11 from __future__
import print_function
14 from os
import listdir, makedirs, getcwd
15 from os.path
import isfile, join, exists, dirname, basename
16 from .app_utils
import *
17 from optparse
import OptionParser
19 from jinja2
import Environment, FileSystemLoader, escape
20 env = Environment(loader=FileSystemLoader(
'templates'))
22 parser = OptionParser(usage=
'Usage: %prog --db PATH_TO_DB [options]')
23 parser.add_option(
'--db', action=
'store', dest=
'db_name',
24 help=
'Absolute path to SQLite3 database file.')
25 parser.add_option(
'--th', action=
'store', dest=
'threshold', default=1e-5,
26 help=
'Threshold to use for static HTML statistics. Default: %default.')
32 f = open(path +
'.html',
'w')
38 Generates static HTML from given release comparison database file. 39 Algorithm: iterates through database, renders Jinja2 templates and saves 40 them to static HTML files. 42 if not exists(db_name):
43 print(
"\nError: SQLite3 database file does not exsits. Exitting...\n")
46 conn = sqlite3.connect(db_name)
50 path =
join(work_path,
'static_html')
54 global_context = {
'db_name':
None ,
'threshold': threshold,
55 'file_id':
None,
'args': [],
'kwargs':
None}
56 global_context[
'static_html'] =
True 57 global_context[
'base_path'] = work_path.strip(
'/')
60 context = global_context.copy()
61 db_list_temp = env.get_template(
'db_list.html')
63 f = open(
join(path,
'index.html'),
'w')
64 f.write(db_list_temp.render(context))
67 c.execute(
'''SELECT id, title, statistical_test FROM ReleaseComparison;''')
68 releases = c.fetchall()
69 rel_summary_temp = env.get_template(
'release_summary.html')
70 dir_summary_temp = env.get_template(
'directory_summary.html')
73 for rel_id, release_title, st_test
in releases:
74 context = global_context.copy()
76 context[
'release_title'] = release_title
77 context[
'st_test'] = st_test
78 create_page([path, release_title, st_test], rel_summary_temp.render(context))
81 print(
'Generating %s (%s) comparison pages...' % (release_title, st_test))
82 c.execute(
'''SELECT id, directory_id FROM RootFileComparison WHERE release_comparison_id = ?;''', (rel_id,))
83 for file_id, file_top_dir_id
in c.fetchall():
84 context[
'file_id'] = file_id
86 create_page([path, release_title, st_test,
str(file_id)], dir_summary_temp.render(context))
88 c.execute(
'''SELECT id FROM Directory WHERE parent_id=?''', (file_top_dir_id,))
89 children_dirs = c.fetchall()
92 def create_dir_pages(c, dir_id, dir_path):
94 c.execute(
'''SELECT name FROM Directory WHERE id=?''', (dir_id,))
95 dir_path.append(c.fetchone()[0])
97 create_page([path, release_title, st_test,
str(file_id)] + dir_path, dir_summary_temp.render(context))
100 for children_dir
in children_dirs:
101 create_dir_pages(c, children_dir[0], [])
105 if __name__ ==
'__main__':
106 opts, args = parser.parse_args()
S & print(S &os, JobReport::InputFile const &f)
def create_page(path, content)
def db_list_with_releases(path='.')
static std::string join(char **cmd)
def get_release_summary_stats(c, release_title, st_test, threshold=1e-5)
def get_directory_summary_stats(c, url_args, file_id, threshold)
def dbfile2html(db_name, work_path, threshold=1e-5)