CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/Utilities/RelMon/python/web/browse_db.py

Go to the documentation of this file.
00001 #! /usr/bin/python
00002 # coding: utf-8
00003 '''
00004 CherryPy application, which enables dynamic SQLite3 database file with release
00005 comparison information browsing. Database file can be generated with
00006 ``ValidationMatrix_v2.py`` script.
00007 
00008 Author:  Albertas Gimbutas,  Vilnius University (LT)
00009 e-mail:  albertasgim@gmail.com
00010 '''
00011 import cherrypy as cpy
00012 import sqlite3
00013 from os.path import isfile
00014 from jinja2 import Environment, FileSystemLoader, escape
00015 from app_utils import *
00016 
00017 env = Environment(loader=FileSystemLoader('templates'))
00018 
00019 
00020 class BrowseDB:
00021     """
00022     CherryPy application for release comparison browsing from SQLite3 database files.
00023     The SQLite3 database files have to placed in the same directory as this script.
00024     """
00025     @cpy.expose
00026     def default(self, db_name=None, release_title=None, st_test=None, file_id=None, *args, **kwargs):
00027         """CherryPy controller, which handles all Http requests."""
00028         if kwargs:
00029             threshold = float(kwargs['threshold'])
00030         else:
00031             threshold = None
00032 
00033         context = {'db_name':db_name, 'release_title':release_title,
00034                    'threshold': threshold, 'st_test':st_test,
00035                    'file_id':file_id, 'args':args, 'kwargs':kwargs}
00036         if not threshold:
00037             threshold = 1e-5
00038 
00039         db_list_temp = env.get_template('db_list.html')
00040         if not db_name:
00041             context['db_list'] = db_list_with_releases()
00042             return db_list_temp.render(context)
00043 
00044         if not isfile(db_name + '.db'):
00045             context['db_list'] = db_list_with_releases()
00046             context['error'] = 'Does not exist: %s.db' % db_name
00047             return db_list_temp.render(context)
00048 
00049         conn = sqlite3.connect(db_name + '.db')
00050         c = conn.cursor()
00051         if not release_title or not st_test:
00052             rel_list_temp = env.get_template('release_list.html')
00053             context['release_list'] = get_release_list(c)
00054             return rel_list_temp.render(context)
00055 
00056         if not file_id:
00057             rel_summary_temp = env.get_template('release_summary.html')
00058             context.update(get_release_summary_stats(c, release_title,
00059                                               st_test, threshold))
00060             return rel_summary_temp.render(context)
00061 
00062         dir_summary_temp = env.get_template('directory_summary.html')
00063         context.update(get_directory_summary_stats(c, args, file_id, threshold))
00064         return dir_summary_temp.render(context)
00065 
00066 
00067 if __name__ == '__main__':
00068     cpy.quickstart(BrowseDB())