/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
1
# Copyright (C) 2006, 2007 Canonical Ltd
0.4.1 by Martin Pool
Start lp-register command
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
2245.8.3 by Martin Pool
Start adding indirection transport
17
"""Launchpad.net integration plugin for Bazaar
18
19
This adds two features:
20
21
  * A register-branch command that tells launchpad about the existence
22
    of a branch
23
24
  * A lp: transport that uses Launchpad as a directory to find a branch
0.4.1 by Martin Pool
Start lp-register command
25
26
To install this file, put the 'bzr_lp' directory, or a symlink to it,
27
in your ~/.bazaar/plugins/ directory.
28
"""
29
0.4.17 by Martin Pool
Allow xmlrpc service url to be overridden by $BZR_LP_XMLRPC_URL
30
# The XMLRPC server address can be overridden by setting the environment
31
# variable $BZR_LP_XMLRPL_URL
32
0.4.9 by Martin Pool
Don't transmit non-standard xmlrpc <nil> value.
33
# see http://bazaar-vcs.org/Specs/BranchRegistrationTool
34
0.4.1 by Martin Pool
Start lp-register command
35
from bzrlib.commands import Command, Option, register_command
2245.8.3 by Martin Pool
Start adding indirection transport
36
from bzrlib.transport import register_lazy_transport
0.4.1 by Martin Pool
Start lp-register command
37
0.4.4 by Martin Pool
Start forming xmlrpc requests
38
39
0.4.2 by Martin Pool
Rename command to 'register-branch'
40
class cmd_register_branch(Command):
41
    """Register a branch with launchpad.net.
0.4.1 by Martin Pool
Start lp-register command
42
43
    This command lists a bzr branch in the directory of branches on
44
    launchpad.net.  Registration allows the bug to be associated with
45
    bugs or specifications.
46
    
0.4.15 by Martin Pool
(register-branch) Add command-line options
47
    Before using this command you must register the product to which the
0.4.1 by Martin Pool
Start lp-register command
48
    branch belongs, and create an account for yourself on launchpad.net.
0.4.3 by Martin Pool
More command line processing
49
50
    arguments:
51
        branch_url: The publicly visible url for the branch.
52
                    This must be an http or https url, not a local file
53
                    path.
54
55
    example:
0.4.15 by Martin Pool
(register-branch) Add command-line options
56
        bzr register-branch http://foo.com/bzr/fooproduct.mine \\
57
                --product fooproduct
0.4.1 by Martin Pool
Start lp-register command
58
    """
0.4.3 by Martin Pool
More command line processing
59
    takes_args = ['branch_url']
0.4.15 by Martin Pool
(register-branch) Add command-line options
60
    takes_options = \
61
        [Option('product', 
62
                'launchpad product short name to associate with the branch',
63
                unicode),
64
         Option('branch-name',
65
                'short name for the branch; '
66
                'by default taken from the last component of the url',
67
                unicode),
68
         Option('branch-title',
69
                'one-sentence description of the branch',
70
                unicode),
71
         Option('branch-description',
72
                'longer description of the purpose or contents of the branch',
73
                unicode),
0.4.16 by Martin Pool
(register-branch) Add --author option and respect --dry-run
74
         Option('author', 
75
                'email of the branch\'s author, if not yourself',
76
                unicode),
0.4.19 by test at canonical
add possibility to link to a bug when registering a branch. factor out some common functionality from BranchRegistrationRequest.
77
         Option('link-bug',
78
                'the bug this branch fixes',
79
                int),
0.4.15 by Martin Pool
(register-branch) Add command-line options
80
         Option('dry-run',
81
                'prepare the request but don\'t actually send it')
82
        ]
83
84
85
    def run(self, 
86
            branch_url, 
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
87
            product='',
0.4.15 by Martin Pool
(register-branch) Add command-line options
88
            branch_name='',
89
            branch_title='',
90
            branch_description='',
0.4.16 by Martin Pool
(register-branch) Add --author option and respect --dry-run
91
            author='',
0.4.19 by test at canonical
add possibility to link to a bug when registering a branch. factor out some common functionality from BranchRegistrationRequest.
92
            link_bug=None,
0.4.15 by Martin Pool
(register-branch) Add command-line options
93
            dry_run=False):
0.4.19 by test at canonical
add possibility to link to a bug when registering a branch. factor out some common functionality from BranchRegistrationRequest.
94
        from lp_registration import (
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
95
            LaunchpadService, BranchRegistrationRequest, BranchBugLinkRequest,
96
            DryRunLaunchpadService)
97
        rego = BranchRegistrationRequest(branch_url=branch_url,
0.4.15 by Martin Pool
(register-branch) Add command-line options
98
                                         branch_name=branch_name,
99
                                         branch_title=branch_title,
100
                                         branch_description=branch_description,
101
                                         product_name=product,
0.4.16 by Martin Pool
(register-branch) Add --author option and respect --dry-run
102
                                         author_email=author,
0.4.15 by Martin Pool
(register-branch) Add command-line options
103
                                         )
0.4.19 by test at canonical
add possibility to link to a bug when registering a branch. factor out some common functionality from BranchRegistrationRequest.
104
        linko = BranchBugLinkRequest(branch_url=branch_url,
105
                                     bug_id=link_bug)
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
106
        if not dry_run:
107
            service = LaunchpadService()
108
            # This gives back the xmlrpc url that can be used for future
109
            # operations on the branch.  It's not so useful to print to the
110
            # user since they can't do anything with it from a web browser; it
111
            # might be nice for the server to tell us about an html url as
112
            # well.
113
        else:
114
            # Run on service entirely in memory
115
            service = DryRunLaunchpadService()
0.4.19 by test at canonical
add possibility to link to a bug when registering a branch. factor out some common functionality from BranchRegistrationRequest.
116
        service.gather_user_credentials()
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
117
        branch_object_url = rego.submit(service)
118
        if link_bug:
119
            link_bug_url = linko.submit(service)
120
        print 'Branch registered.'
0.4.1 by Martin Pool
Start lp-register command
121
0.4.2 by Martin Pool
Rename command to 'register-branch'
122
register_command(cmd_register_branch)
2245.8.4 by Martin Pool
lp:/// indirection works
123
2245.8.3 by Martin Pool
Start adding indirection transport
124
register_lazy_transport(
2245.8.5 by Martin Pool
Add short-form lp:PRODUCT url form
125
    'lp:',
126
    'bzrlib.plugins.launchpad.lp_indirect',
127
    'launchpad_transport_indirect')
128
129
register_lazy_transport(
2245.8.3 by Martin Pool
Start adding indirection transport
130
    'lp://',
131
    'bzrlib.plugins.launchpad.lp_indirect',
2245.8.4 by Martin Pool
lp:/// indirection works
132
    'launchpad_transport_indirect')
0.4.1 by Martin Pool
Start lp-register command
133
134
def test_suite():
135
    """Called by bzrlib to fetch tests for this plugin"""
136
    from unittest import TestSuite, TestLoader
137
    import test_register
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
138
    import test_lp_indirect
139
140
    loader = TestLoader()
141
    suite = TestSuite()
142
    for m in [test_register, test_lp_indirect]:
143
        suite.addTests(loader.loadTestsFromModule(m))
144
    return suite