~snaggen/loggerhead/project_view_and_user_branches

« back to all changes in this revision

Viewing changes to loggerhead/controllers/__init__.py

  • Committer: Martin Albisetti
  • Date: 2008-07-22 00:40:03 UTC
  • mfrom: (182 loggerhead.search_integration)
  • mto: This revision was merged to the branch mainline in revision 187.
  • Revision ID: argentina@gmail.com-20080722004003-lx1fp0tthpp6kl92
Merged from trunk, resolved billions of conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
    template_path = None
57
57
 
58
 
    def __init__(self, branch):
 
58
    def __init__(self, branch, history):
59
59
        self._branch = branch
 
60
        self._history = history
60
61
        self.log = branch.log
61
62
 
62
63
    def __call__(self, environ, start_response):
63
64
        z = time.time()
64
 
        h = self._branch.history
 
65
        h = self._history
65
66
        kw = dict(parse_querystring(environ))
66
67
        util.set_context(kw)
67
 
 
68
 
        h._branch.lock_read()
69
 
        try:
70
 
            args = []
71
 
            while 1:
72
 
                arg = path_info_pop(environ)
73
 
                if arg is None:
74
 
                    break
75
 
                args.append(arg)
76
 
 
77
 
            vals = {
78
 
                'branch': self._branch,
79
 
                'util': util,
80
 
                'history': h,
81
 
                'url': self._branch.context_url,
82
 
            }
83
 
            vals.update(templatefunctions)
84
 
            headers = {}
85
 
            vals.update(self.get_values(h, args, kw, headers))
86
 
 
87
 
            self.log.info('Getting information for %s: %r secs' % (
88
 
                self.__class__.__name__, time.time() - z,))
89
 
            if 'Content-Type' not in headers:
90
 
                headers['Content-Type'] = 'text/html'
91
 
            writer = start_response("200 OK", headers.items())
92
 
            template = load_template(self.template_path)
93
 
            z = time.time()
94
 
            w = BufferingWriter(writer, 8192)
95
 
            template.expand_into(w, **vals)
96
 
            w.flush()
97
 
            self.log.info('Rendering %s: %r secs, %s bytes, %s (%2.1f%%) bytes saved' % (
98
 
                self.__class__.__name__, time.time() - z, w.bytes, w.bytes_saved, 100.0*w.bytes_saved/w.bytes))
99
 
            return []
100
 
        finally:
101
 
            h._branch.unlock()
 
68
        args = []
 
69
        while 1:
 
70
            arg = path_info_pop(environ)
 
71
            if arg is None:
 
72
                break
 
73
            args.append(arg)
 
74
 
 
75
        vals = {
 
76
            'branch': self._branch,
 
77
            'util': util,
 
78
            'history': h,
 
79
            'url': self._branch.context_url,
 
80
        }
 
81
        vals.update(templatefunctions)
 
82
        headers = {}
 
83
        vals.update(self.get_values(h, args, kw, headers))
 
84
 
 
85
        self.log.info('Getting information for %s: %r secs' % (
 
86
            self.__class__.__name__, time.time() - z,))
 
87
        if 'Content-Type' not in headers:
 
88
            headers['Content-Type'] = 'text/html'
 
89
        writer = start_response("200 OK", headers.items())
 
90
        template = load_template(self.template_path)
 
91
        z = time.time()
 
92
        w = BufferingWriter(writer, 8192)
 
93
        template.expand_into(w, **vals)
 
94
        w.flush()
 
95
        self.log.info('Rendering %s: %r secs, %s bytes, %s (%2.1f%%) bytes saved' % (
 
96
            self.__class__.__name__, time.time() - z, w.bytes, w.bytes_saved, 100.0*w.bytes_saved/w.bytes))
 
97
        return []