CMS 3D CMS Logo

Functions | Variables

web::dbfile2html Namespace Reference

Functions

def create_page
def dbfile2html

Variables

tuple env = Environment(loader=FileSystemLoader('templates'))
string help = 'Absolute path to SQLite3 database file.'
tuple parser = OptionParser(usage='Usage: %prog --db PATH_TO_DB [options]')

Function Documentation

def web::dbfile2html::create_page (   path,
  content 
)

Definition at line 26 of file dbfile2html.py.

00027                               :
00028     path = join(*path)
00029     if not exists(dirname(path)):
00030         makedirs(dirname(path))
00031     f = open(path + '.html', 'w')
00032     f.write(content)
00033     f.close()

def web::dbfile2html::dbfile2html (   db_name,
  work_path,
  threshold = 1e-5 
)
Generates static HTML from given release comparison database file.
Algorithm: iterates through database, renders Jinja2 templates and saves
them to static HTML files.

Definition at line 34 of file dbfile2html.py.

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     ## Initialise working directory.
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     ## Generate DB list page
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     ## Generate ReleaseComparison html pages
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         ## Generate RootFileComparison html pages
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             ## Generate Directory html pages
00091             def create_dir_pages(c, dir_id, dir_path):
00092                 # Generate Directory page
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                 # TODO: Call for subdirectories
00098 
00099             for children_dir in children_dirs:
00100                 create_dir_pages(c, children_dir[0], [])
00101         print 'Done.'
00102 


Variable Documentation

tuple web::dbfile2html::env = Environment(loader=FileSystemLoader('templates'))

Definition at line 18 of file dbfile2html.py.

string web::dbfile2html::help = 'Absolute path to SQLite3 database file.'

Definition at line 22 of file dbfile2html.py.

tuple web::dbfile2html::parser = OptionParser(usage='Usage: %prog --db PATH_TO_DB [options]')

Definition at line 20 of file dbfile2html.py.