Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:02

0001 #!/usr/bin/env python
0002 # coding: utf-8
0003 '''
0004 CherryPy application, which enables dynamic SQLite3 database file with release
0005 comparison information browsing. Database file can be generated with
0006 ``ValidationMatrix_v2.py`` script.
0007 
0008 Author:  Albertas Gimbutas,  Vilnius University (LT)
0009 e-mail:  albertasgim@gmail.com
0010 '''
0011 from __future__ import absolute_import
0012 import cherrypy as cpy
0013 import sqlite3
0014 from os.path import isfile
0015 from jinja2 import Environment, FileSystemLoader, escape
0016 from .app_utils import *
0017 
0018 env = Environment(loader=FileSystemLoader('templates'))
0019 
0020 
0021 class BrowseDB:
0022     """
0023     CherryPy application for release comparison browsing from SQLite3 database files.
0024     The SQLite3 database files have to placed in the same directory as this script.
0025     """
0026     @cpy.expose
0027     def default(self, db_name=None, release_title=None, st_test=None, file_id=None, *args, **kwargs):
0028         """CherryPy controller, which handles all Http requests."""
0029         if kwargs:
0030             threshold = float(kwargs['threshold'])
0031         else:
0032             threshold = None
0033 
0034         context = {'db_name':db_name, 'release_title':release_title,
0035                    'threshold': threshold, 'st_test':st_test,
0036                    'file_id':file_id, 'args':args, 'kwargs':kwargs}
0037         if not threshold:
0038             threshold = 1e-5
0039 
0040         db_list_temp = env.get_template('db_list.html')
0041         if not db_name:
0042             context['db_list'] = db_list_with_releases()
0043             return db_list_temp.render(context)
0044 
0045         if not isfile(db_name + '.db'):
0046             context['db_list'] = db_list_with_releases()
0047             context['error'] = 'Does not exist: %s.db' % db_name
0048             return db_list_temp.render(context)
0049 
0050         conn = sqlite3.connect(db_name + '.db')
0051         c = conn.cursor()
0052         if not release_title or not st_test:
0053             rel_list_temp = env.get_template('release_list.html')
0054             context['release_list'] = get_release_list(c)
0055             return rel_list_temp.render(context)
0056 
0057         if not file_id:
0058             rel_summary_temp = env.get_template('release_summary.html')
0059             context.update(get_release_summary_stats(c, release_title,
0060                                               st_test, threshold))
0061             return rel_summary_temp.render(context)
0062 
0063         dir_summary_temp = env.get_template('directory_summary.html')
0064         context.update(get_directory_summary_stats(c, args, file_id, threshold))
0065         return dir_summary_temp.render(context)
0066 
0067 
0068 if __name__ == '__main__':
0069     cpy.quickstart(BrowseDB())