~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

  • Committer: John Arbash Meinel
  • Date: 2011-02-09 21:17:32 UTC
  • mto: This revision was merged to the branch mainline in revision 426.
  • Revision ID: john@arbash-meinel.com-20110209211732-ysrgacmnoygm891e
Start working on some code to do load testing of loggerhead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
 
2
# Copyright (C) 2008, 2009 Canonical Ltd.
2
3
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
3
4
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
4
5
#
17
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
#
19
20
 
20
 
import time
21
 
 
22
 
import turbogears
23
 
from cherrypy import InternalError
 
21
import urllib
 
22
 
 
23
try:
 
24
    import simplejson
 
25
except ImportError:
 
26
    import json as simplejson
 
27
 
 
28
from paste.httpexceptions import HTTPServerError
24
29
 
25
30
from loggerhead import util
26
 
 
27
 
 
28
 
class ChangeLogUI (object):
29
 
    
30
 
    def __init__(self, branch):
31
 
        # BranchView object
32
 
        self._branch = branch
33
 
        self.log = branch.log
34
 
        
35
 
    @util.strip_whitespace
36
 
    @turbogears.expose(html='loggerhead.templates.changelog')
37
 
    def default(self, *args, **kw):
38
 
        z = time.time()
39
 
        h = self._branch.get_history()
40
 
        config = self._branch.config
41
 
 
42
 
        h._branch.lock_read()
 
31
from loggerhead.controllers import TemplatedBranchView
 
32
 
 
33
 
 
34
class ChangeLogUI(TemplatedBranchView):
 
35
 
 
36
    template_path = 'loggerhead.templates.changelog'
 
37
 
 
38
    def get_values(self, path, kwargs, headers):
 
39
        history = self._history
 
40
        revid = self.get_revid()
 
41
        filter_file_id = kwargs.get('filter_file_id', None)
 
42
        query = kwargs.get('q', None)
 
43
        start_revid = history.fix_revid(kwargs.get('start_revid', None))
 
44
        orig_start_revid = start_revid
 
45
        pagesize = 20#int(config.get('pagesize', '20'))
 
46
        search_failed = False
 
47
 
 
48
        if filter_file_id is None and path is not None:
 
49
            filter_file_id = history.get_file_id(revid, path)
 
50
 
43
51
        try:
44
 
            if len(args) > 0:
45
 
                revid = h.fix_revid(args[0])
 
52
            revid, start_revid, revid_list = history.get_view(
 
53
                revid, start_revid, filter_file_id, query)
 
54
            util.set_context(kwargs)
 
55
 
 
56
            if (query is not None) and (len(revid_list) == 0):
 
57
                search_failed = True
 
58
 
 
59
            if len(revid_list) == 0:
 
60
                scan_list = revid_list
46
61
            else:
47
 
                revid = None
48
 
 
49
 
            filter_file_id = kw.get('filter_file_id', None)
50
 
            query = kw.get('q', None)
51
 
            start_revid = h.fix_revid(kw.get('start_revid', None))
52
 
            orig_start_revid = start_revid
53
 
            pagesize = int(config.get('pagesize', '20'))
54
 
            search_failed = False
55
 
 
56
 
            try:
57
 
                revid, start_revid, revid_list = h.get_view(
58
 
                    revid, start_revid, filter_file_id, query)
59
 
                kw['start_revid'] = start_revid
60
 
                util.set_context(kw)
61
 
 
62
 
                if (query is not None) and (len(revid_list) == 0):
63
 
                    search_failed = True
64
 
 
65
 
                if len(revid_list) == 0:
66
 
                    scan_list = revid_list
 
62
                if revid in revid_list: # XXX is this always true?
 
63
                    i = revid_list.index(revid)
67
64
                else:
68
 
                    if revid in revid_list: # XXX is this always true?
69
 
                        i = revid_list.index(revid)
70
 
                    else:
71
 
                        i = None
72
 
                    scan_list = revid_list[i:]
73
 
                change_list = scan_list[:pagesize]
74
 
                changes = list(h.get_changes(change_list))
75
 
                h.add_changes(changes)
76
 
            except:
77
 
                self.log.exception('Exception fetching changes')
78
 
                raise InternalError('Could not fetch changes')
79
 
 
80
 
            navigation = util.Container(
81
 
                pagesize=pagesize, revid=revid, start_revid=start_revid,
82
 
                revid_list=revid_list, filter_file_id=filter_file_id,
83
 
                scan_url='/changes', branch=self._branch, feed=True)
84
 
            if query is not None:
85
 
                navigation.query = query
86
 
            util.fill_in_navigation(navigation)
87
 
 
88
 
            # add parent & merge-point branch-nick info, in case it's useful
89
 
            h.get_branch_nicks(changes)
90
 
 
91
 
            # does every change on this page have the same committer?  if so,
92
 
            # tell the template to show committer info in the "details block"
93
 
            # instead of on each line.
94
 
            all_same_author = True
95
 
 
96
 
            if changes:
97
 
                author = changes[0].author
98
 
                for e in changes[1:]:
99
 
                    if e.author != author:
100
 
                        all_same_author = False
101
 
                        break
102
 
 
103
 
            vals = {
104
 
                'branch': self._branch,
105
 
                'changes': changes,
106
 
                'util': util,
107
 
                'history': h,
108
 
                'revid': revid,
109
 
                'navigation': navigation,
110
 
                'filter_file_id': filter_file_id,
111
 
                'start_revid': start_revid,
112
 
                'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
113
 
                'query': query,
114
 
                'search_failed': search_failed,
115
 
                'all_same_author': all_same_author,
116
 
            }
117
 
            h.flush_cache()
118
 
            self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
119
 
            return vals
120
 
        finally:
121
 
            h._branch.unlock()
 
65
                    i = None
 
66
                scan_list = revid_list[i:]
 
67
            change_list = scan_list[:pagesize]
 
68
            changes = list(history.get_changes(change_list))
 
69
            data = {}
 
70
            for i, c in enumerate(changes):
 
71
                c.index = i
 
72
                data[str(i)] = urllib.quote(urllib.quote(c.revid, safe=''))
 
73
        except:
 
74
            self.log.exception('Exception fetching changes')
 
75
            raise HTTPServerError('Could not fetch changes')
 
76
 
 
77
        navigation = util.Container(
 
78
            pagesize=pagesize, revid=revid, start_revid=start_revid,
 
79
            revid_list=revid_list, filter_file_id=filter_file_id,
 
80
            scan_url='/changes', branch=self._branch, feed=True, history=history)
 
81
        if query is not None:
 
82
            navigation.query = query
 
83
        util.fill_in_navigation(navigation)
 
84
 
 
85
        # Directory Breadcrumbs
 
86
        directory_breadcrumbs = (
 
87
            util.directory_breadcrumbs(
 
88
                self._branch.friendly_name,
 
89
                self._branch.is_root,
 
90
                'changes'))
 
91
 
 
92
        show_tag_col = False
 
93
        for change in changes:
 
94
            if change.tags is not None:
 
95
                show_tag_col = True
 
96
                break
 
97
 
 
98
        return {
 
99
            'branch': self._branch,
 
100
            'changes': changes,
 
101
            'show_tag_col': show_tag_col,
 
102
            'data': simplejson.dumps(data),
 
103
            'util': util,
 
104
            'history': history,
 
105
            'revid': revid,
 
106
            'navigation': navigation,
 
107
            'filter_file_id': filter_file_id,
 
108
            'start_revid': start_revid,
 
109
            'viewing_from': (orig_start_revid is not None) and
 
110
                            (orig_start_revid != history.last_revid),
 
111
            'query': query,
 
112
            'search_failed': search_failed,
 
113
            'url': self._branch.context_url,
 
114
            'directory_breadcrumbs': directory_breadcrumbs,
 
115
        }