00035 :
00036 """
00037 Generates static HTML from given release comparison database file.
00038 Algorithm: iterates through database, renders Jinja2 templates and saves
00039 them to static HTML files.
00040 """
00041 if not exists(db_name):
00042 print "\nError: SQLite3 database file does not exsits. Exitting...\n"
00043 exit()
00044
00045 conn = sqlite3.connect(db_name)
00046 c = conn.cursor()
00047
00048
00049 path = join(work_path, 'static_html')
00050 if not exists(path):
00051 makedirs(path)
00052
00053 global_context = {'db_name': None , 'threshold': threshold,
00054 'file_id': None, 'args': [], 'kwargs': None}
00055 global_context['static_html'] = True
00056 global_context['base_path'] = work_path.strip('/')
00057
00058
00059 context = global_context.copy()
00060 db_list_temp = env.get_template('db_list.html')
00061 context['db_list'] = db_list_with_releases(work_path)
00062 f = open(join(path, 'index.html'), 'w')
00063 f.write(db_list_temp.render(context))
00064
00065
00066 c.execute('''SELECT id, title, statistical_test FROM ReleaseComparison;''')
00067 releases = c.fetchall()
00068 rel_summary_temp = env.get_template('release_summary.html')
00069 dir_summary_temp = env.get_template('directory_summary.html')
00070
00071
00072 for rel_id, release_title, st_test in releases:
00073 context = global_context.copy()
00074 context.update(get_release_summary_stats(c, release_title, st_test, threshold))
00075 context['release_title'] = release_title
00076 context['st_test'] = st_test
00077 create_page([path, release_title, st_test], rel_summary_temp.render(context))
00078
00079
00080 print 'Generating %s (%s) comparison pages...' % (release_title, st_test)
00081 c.execute('''SELECT id, directory_id FROM RootFileComparison WHERE release_comparison_id = ?;''', (rel_id,))
00082 for file_id, file_top_dir_id in c.fetchall():
00083 context['file_id'] = file_id
00084 context.update(get_directory_summary_stats(c, [], file_id, threshold))
00085 create_page([path, release_title, st_test, str(file_id)], dir_summary_temp.render(context))
00086
00087 c.execute('''SELECT id FROM Directory WHERE parent_id=?''', (file_top_dir_id,))
00088 children_dirs = c.fetchall()
00089
00090
00091 def create_dir_pages(c, dir_id, dir_path):
00092
00093 c.execute('''SELECT name FROM Directory WHERE id=?''', (dir_id,))
00094 dir_path.append(c.fetchone()[0])
00095 context.update(get_directory_summary_stats(c, dir_path, file_id, threshold))
00096 create_page([path, release_title, st_test, str(file_id)] + dir_path, dir_summary_temp.render(context))
00097
00098
00099 for children_dir in children_dirs:
00100 create_dir_pages(c, children_dir[0], [])
00101 print 'Done.'
00102