~launchpad-pqm/launchpad/devel

8687.15.17 by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3691.160.1 by James Henstridge
Add support for Bazaar branch references to branch, product and product series pages
3
3691.160.3 by James Henstridge
changes from spiv's review
4
"""Browser code used to implement virtual '.bzr' directories."""
5
3691.160.1 by James Henstridge
Add support for Bazaar branch references to branch, product and product series pages
6
__metaclass__ = type
7
__all__ = [
8
    'BranchRef'
9
    ]
10
11
from zope.interface import implements
12
from zope.publisher.interfaces.browser import IBrowserPublisher
3691.160.3 by James Henstridge
changes from spiv's review
13
3691.160.1 by James Henstridge
Add support for Bazaar branch references to branch, product and product series pages
14
from canonical.config import config
14600.2.2 by Curtis Hovey
Moved webapp to lp.services.
15
from lp.services.webapp import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
16
    Navigation,
17
    stepthrough,
18
    stepto,
19
    )
8138.1.2 by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing.
20
from lp.code.interfaces.branchref import IBranchRef
3691.160.1 by James Henstridge
Add support for Bazaar branch references to branch, product and product series pages
21
22
23
class BranchRef:
24
    implements(IBranchRef)
25
26
    def __init__(self, branch):
27
        self.branch = branch
28
29
4664.1.1 by Curtis Hovey
Normalized comments for bug 3732.
30
# XXX jamesh 2006-09-26:
3691.160.2 by James Henstridge
add a comment about switching to HTTP redirects in the future
31
# Eventually we will be able to change this to serve a simple HTTP
32
# redirect for 'branch-format' and have bzr do the rest.  However,
33
# current Bazaar releases would continue to request branch data files
34
# at this location.
35
#
36
# Synthesising a branch reference provides the desired behaviour with
37
# current Bazaar releases, however.
38
3691.160.1 by James Henstridge
Add support for Bazaar branch references to branch, product and product series pages
39
class BranchRefNavigation(Navigation):
40
41
    usedfor = IBranchRef
42
43
    @stepto('branch-format')
44
    def branch_format(self):
45
        return StaticContentView('Bazaar-NG meta directory, format 1\n')
46
47
    @stepthrough('branch')
48
    def traverse_branch(self, name):
49
        if name == 'format':
50
            return StaticContentView('Bazaar-NG Branch Reference Format 1\n')
51
        elif name == 'location':
4813.8.1 by Tim Penhey
Lots of url moving on the branch index page.
52
            return StaticContentView(config.codehosting.supermirror_root +
3691.160.1 by James Henstridge
Add support for Bazaar branch references to branch, product and product series pages
53
                                     self.context.branch.unique_name)
54
        else:
55
            return None
56
57
58
class StaticContentView:
59
    implements(IBrowserPublisher)
60
61
    def __init__(self, contents):
62
        self.contents = contents
63
64
    def __call__(self):
65
        return self.contents
66
67
    def browserDefault(self, request):
68
        return self, ()