/ interfaces / web / cfbe.py
cfbe.py
 1  #!/usr/bin/env python
 2  
 3  import cherrypy
 4  import web
 5  from optparse import OptionParser
 6  from os import path
 7  
 8  module_dir = path.dirname(path.abspath(web.__file__))
 9  template_dir = path.join(module_dir, 'templates')
10  
11  def build_parser():
12      """Builds and returns the command line option parser."""
13      
14      usage = 'usage: %prog bug_directory'
15      parser = OptionParser(usage)
16      return parser
17  
18  def parse_arguments():
19      """Parse the command line arguments."""
20      
21      parser = build_parser()
22      (options, args) = parser.parse_args()
23      
24      if len(args) != 1:
25          parser.error('You need to specify a bug directory.')
26      
27      return { 'bug_root': args[0], }
28  
29  
30  config = path.join(module_dir, 'cfbe.config')
31  options = parse_arguments()
32  
33  WebInterface = web.WebInterface(path.abspath(options['bug_root']), template_dir)
34  
35  cherrypy.config.update({
36          'tools.encode.on': True,
37          'tools.encode.encoding': 'utf8',
38          'tools.staticdir.root': path.join(module_dir, 'static'),
39          })
40  app_config = { '/static': { 'tools.staticdir.on': True,
41                              'tools.staticdir.dir': '', } }
42  cherrypy.quickstart(WebInterface, '/', app_config)