aboutsummaryrefslogtreecommitdiffstats
path: root/cfbe.py
blob: 56badfd282084a596d56aa0e1cfa26011987557b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python

import cherrypy
import cherryflavoredbugseverywhere
from libbe import bugdir
from jinja2 import Environment, FileSystemLoader
from datetime import datetime
from optparse import OptionParser
from os import path

module_dir = path.dirname(path.abspath(cherryflavoredbugseverywhere.__file__))

def datetimeformat(value, format='%B %d, %Y at %I:%M %p'):
    """Takes a timestamp and revormats it into a human-readable string."""
    return datetime.fromtimestamp(value).strftime(format)


template_root = path.join(module_dir, 'templates')
env = Environment(loader=FileSystemLoader(template_root))
env.filters['datetimeformat'] = datetimeformat

WebInterface = cherryflavoredbugseverywhere.web.WebInterface(path.abspath(options['bug_root']))

def build_parser():
    """Builds and returns the command line option parser."""
    
    usage = 'usage: %prog bug_directory'
    parser = OptionParser(usage)
    return parser

def parse_arguments():
    """Parse the command line arguments."""
    
    parser = build_parser()
    (options, args) = parser.parse_args()
    
    if len(args) != 1:
        parser.error('You need to specify a bug directory.')
    
    return { 'bug_root': args[0], }


config = path.join(module_dir, 'cfbe.config')
options = parse_arguments()
cherrypy.quickstart(WebInterface, '/', config)