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/env 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 from __future__ import absolute_import
12 import cherrypy as cpy
13 import sqlite3
14 from os.path import isfile
15 from jinja2 import Environment, FileSystemLoader, escape
16 from .app_utils import *
17 
18 env = Environment(loader=FileSystemLoader('templates'))
19 
20 
21 class BrowseDB:
22  """
23  CherryPy application for release comparison browsing from SQLite3 database files.
24  The SQLite3 database files have to placed in the same directory as this script.
25  """
26  @cpy.expose
27  def default(self, db_name=None, release_title=None, st_test=None, file_id=None, *args, **kwargs):
28  """CherryPy controller, which handles all Http requests."""
29  if kwargs:
30  threshold = float(kwargs['threshold'])
31  else:
32  threshold = None
33 
34  context = {'db_name':db_name, 'release_title':release_title,
35  'threshold': threshold, 'st_test':st_test,
36  'file_id':file_id, 'args':args, 'kwargs':kwargs}
37  if not threshold:
38  threshold = 1e-5
39 
40  db_list_temp = env.get_template('db_list.html')
41  if not db_name:
42  context['db_list'] = db_list_with_releases()
43  return db_list_temp.render(context)
44 
45  if not isfile(db_name + '.db'):
46  context['db_list'] = db_list_with_releases()
47  context['error'] = 'Does not exist: %s.db' % db_name
48  return db_list_temp.render(context)
49 
50  conn = sqlite3.connect(db_name + '.db')
51  c = conn.cursor()
52  if not release_title or not st_test:
53  rel_list_temp = env.get_template('release_list.html')
54  context['release_list'] = get_release_list(c)
55  return rel_list_temp.render(context)
56 
57  if not file_id:
58  rel_summary_temp = env.get_template('release_summary.html')
59  context.update(get_release_summary_stats(c, release_title,
60  st_test, threshold))
61  return rel_summary_temp.render(context)
62 
63  dir_summary_temp = env.get_template('directory_summary.html')
64  context.update(get_directory_summary_stats(c, args, file_id, threshold))
65  return dir_summary_temp.render(context)
66 
67 
68 if __name__ == '__main__':
69  cpy.quickstart(BrowseDB())
def get_release_summary_stats
Definition: app_utils.py:163
def db_list_with_releases
Definition: app_utils.py:150
def get_directory_summary_stats
Definition: app_utils.py:283
def get_release_list
Definition: app_utils.py:144