CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
browse_db.py
Go to the documentation of this file.
1 #! /usr/bin/python
2 # coding: utf-8
3 '''
4 CherryPy application, which enables dynamic SQLite3 database file with release
5 comparison information browsing. Database file can be generated with
6 ``ValidationMatrix_v2.py`` script.
7 
8 Author: Albertas Gimbutas, Vilnius University (LT)
9 e-mail: albertasgim@gmail.com
10 '''
11 import cherrypy as cpy
12 import sqlite3
13 from os.path import isfile
14 from jinja2 import Environment, FileSystemLoader, escape
15 from app_utils import *
16 
17 env = Environment(loader=FileSystemLoader('templates'))
18 
19 
20 class BrowseDB:
21  """
22  CherryPy application for release comparison browsing from SQLite3 database files.
23  The SQLite3 database files have to placed in the same directory as this script.
24  """
25  @cpy.expose
26  def default(self, db_name=None, release_title=None, st_test=None, file_id=None, *args, **kwargs):
27  """CherryPy controller, which handles all Http requests."""
28  if kwargs:
29  threshold = float(kwargs['threshold'])
30  else:
31  threshold = None
32 
33  context = {'db_name':db_name, 'release_title':release_title,
34  'threshold': threshold, 'st_test':st_test,
35  'file_id':file_id, 'args':args, 'kwargs':kwargs}
36  if not threshold:
37  threshold = 1e-5
38 
39  db_list_temp = env.get_template('db_list.html')
40  if not db_name:
41  context['db_list'] = db_list_with_releases()
42  return db_list_temp.render(context)
43 
44  if not isfile(db_name + '.db'):
45  context['db_list'] = db_list_with_releases()
46  context['error'] = 'Does not exist: %s.db' % db_name
47  return db_list_temp.render(context)
48 
49  conn = sqlite3.connect(db_name + '.db')
50  c = conn.cursor()
51  if not release_title or not st_test:
52  rel_list_temp = env.get_template('release_list.html')
53  context['release_list'] = get_release_list(c)
54  return rel_list_temp.render(context)
55 
56  if not file_id:
57  rel_summary_temp = env.get_template('release_summary.html')
58  context.update(get_release_summary_stats(c, release_title,
59  st_test, threshold))
60  return rel_summary_temp.render(context)
61 
62  dir_summary_temp = env.get_template('directory_summary.html')
63  context.update(get_directory_summary_stats(c, args, file_id, threshold))
64  return dir_summary_temp.render(context)
65 
66 
67 if __name__ == '__main__':
68  cpy.quickstart(BrowseDB())
def get_release_summary_stats
Definition: app_utils.py:162
def db_list_with_releases
Definition: app_utils.py:149
def get_directory_summary_stats
Definition: app_utils.py:282
def get_release_list
Definition: app_utils.py:143