~thumper/bzr/alias-command

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/__init__.py

  • Committer: Tim Penhey
  • Date: 2008-04-20 08:48:04 UTC
  • mfrom: (2900.1.474 +trunk)
  • Revision ID: tim@penhey.net-20080420084804-fw6m8ezw4n7pnmo1
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006 - 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
"""Launchpad.net integration plugin for Bazaar
18
 
 
19
 
To install this file, put the 'bzr_lp' directory, or a symlink to it,
20
 
in your ~/.bazaar/plugins/ directory.
21
 
"""
 
17
"""Launchpad.net integration plugin for Bazaar."""
22
18
 
23
19
# The XMLRPC server address can be overridden by setting the environment
24
20
# variable $BZR_LP_XMLRPL_URL
25
21
 
26
22
# see http://bazaar-vcs.org/Specs/BranchRegistrationTool
27
23
 
 
24
from bzrlib.branch import Branch
28
25
from bzrlib.commands import Command, Option, register_command
29
 
from bzrlib.transport import register_lazy_transport
 
26
from bzrlib.directory_service import directories
 
27
from bzrlib.errors import BzrCommandError, NoPublicBranch, NotBranchError
30
28
from bzrlib.help_topics import topic_registry
31
29
 
32
30
 
41
39
    branch belongs, and create an account for yourself on launchpad.net.
42
40
 
43
41
    arguments:
44
 
        branch_url: The publicly visible url for the branch.
45
 
                    This must be an http or https url, not a local file
46
 
                    path.
 
42
        public_url: The publicly visible url for the branch to register.
 
43
                    This must be an http or https url (which Launchpad can read
 
44
                    from to access the branch). Local file urls, SFTP urls, and
 
45
                    bzr+ssh urls will not work.
 
46
                    If no public_url is provided, bzr will use the configured
 
47
                    public_url if there is one for the current branch, and
 
48
                    otherwise error.
47
49
 
48
50
    example:
49
51
        bzr register-branch http://foo.com/bzr/fooproduct.mine \\
50
52
                --product fooproduct
51
53
    """
52
 
    takes_args = ['branch_url']
 
54
    takes_args = ['public_url?']
53
55
    takes_options = [
54
56
         Option('product',
55
57
                'Launchpad product short name to associate with the branch.',
75
77
        ]
76
78
 
77
79
 
78
 
    def run(self, 
79
 
            branch_url, 
 
80
    def run(self,
 
81
            public_url=None,
80
82
            product='',
81
83
            branch_name='',
82
84
            branch_title='',
84
86
            author='',
85
87
            link_bug=None,
86
88
            dry_run=False):
87
 
        from lp_registration import (
 
89
        from bzrlib.plugins.launchpad.lp_registration import (
88
90
            LaunchpadService, BranchRegistrationRequest, BranchBugLinkRequest,
89
91
            DryRunLaunchpadService)
90
 
        rego = BranchRegistrationRequest(branch_url=branch_url,
 
92
        if public_url is None:
 
93
            try:
 
94
                b = Branch.open_containing('.')[0]
 
95
            except NotBranchError:
 
96
                raise BzrCommandError('register-branch requires a public '
 
97
                    'branch url - see bzr help register-branch.')
 
98
            public_url = b.get_public_branch()
 
99
            if public_url is None:
 
100
                raise NoPublicBranch(b)
 
101
 
 
102
        rego = BranchRegistrationRequest(branch_url=public_url,
91
103
                                         branch_name=branch_name,
92
104
                                         branch_title=branch_title,
93
105
                                         branch_description=branch_description,
94
106
                                         product_name=product,
95
107
                                         author_email=author,
96
108
                                         )
97
 
        linko = BranchBugLinkRequest(branch_url=branch_url,
 
109
        linko = BranchBugLinkRequest(branch_url=public_url,
98
110
                                     bug_id=link_bug)
99
111
        if not dry_run:
100
112
            service = LaunchpadService()
114
126
 
115
127
register_command(cmd_register_branch)
116
128
 
117
 
register_lazy_transport(
118
 
    'lp:',
119
 
    'bzrlib.plugins.launchpad.lp_indirect',
120
 
    'launchpad_transport_indirect')
121
 
 
122
 
register_lazy_transport(
123
 
    'lp://',
124
 
    'bzrlib.plugins.launchpad.lp_indirect',
125
 
    'launchpad_transport_indirect')
 
129
 
 
130
class cmd_launchpad_login(Command):
 
131
    """Show or set the Launchpad user ID.
 
132
 
 
133
    When communicating with Launchpad, some commands need to know your
 
134
    Launchpad user ID.  This command can be used to set or show the
 
135
    user ID that Bazaar will use for such communication.
 
136
 
 
137
    :Examples:
 
138
      Show the Launchpad ID of the current user::
 
139
 
 
140
          bzr launchpad-login
 
141
 
 
142
      Set the Launchpad ID of the current user to 'bob'::
 
143
 
 
144
          bzr launchpad-login bob
 
145
    """
 
146
    aliases = ['lp-login']
 
147
    takes_args = ['name?']
 
148
    takes_options = [
 
149
        Option('no-check',
 
150
               "Don't check that the user name is valid."),
 
151
        ]
 
152
 
 
153
    def run(self, name=None, no_check=False):
 
154
        from bzrlib.plugins.launchpad import account
 
155
        check_account = not no_check
 
156
 
 
157
        if name is None:
 
158
            username = account.get_lp_login()
 
159
            if username:
 
160
                if check_account:
 
161
                    account.check_lp_login(username)
 
162
                self.outf.write(username + '\n')
 
163
            else:
 
164
                self.outf.write('No Launchpad user ID configured.\n')
 
165
                return 1
 
166
        else:
 
167
            if check_account:
 
168
                account.check_lp_login(name)
 
169
            account.set_lp_login(name)
 
170
 
 
171
register_command(cmd_launchpad_login)
 
172
 
 
173
 
 
174
def _register_directory():
 
175
    directories.register_lazy('lp:', 'bzrlib.plugins.launchpad.lp_directory',
 
176
                              'LaunchpadDirectory',
 
177
                              'Launchpad-based directory service',)
 
178
_register_directory()
 
179
 
126
180
 
127
181
def test_suite():
128
182
    """Called by bzrlib to fetch tests for this plugin"""
129
183
    from unittest import TestSuite, TestLoader
130
 
    import test_register
131
 
    import test_lp_indirect
 
184
    from bzrlib.plugins.launchpad import (
 
185
         test_account, test_lp_directory, test_lp_service, test_register,
 
186
         )
132
187
 
133
188
    loader = TestLoader()
134
189
    suite = TestSuite()
135
 
    for m in [test_register, test_lp_indirect]:
136
 
        suite.addTests(loader.loadTestsFromModule(m))
 
190
    for module in [
 
191
        test_account,
 
192
        test_register,
 
193
        test_lp_directory,
 
194
        test_lp_service,
 
195
        ]:
 
196
        suite.addTests(loader.loadTestsFromModule(module))
137
197
    return suite
138
198
 
139
199
_launchpad_help = """Integration with Launchpad.net
141
201
Launchpad.net provides free Bazaar branch hosting with integrated bug and
142
202
specification tracking.
143
203
 
144
 
The bzr client (through the plugin called 'launchpad') has two special
 
204
The bzr client (through the plugin called 'launchpad') has special
145
205
features to communicate with Launchpad:
146
206
 
147
 
    * The register-branch command tells launchpad about the url of a 
 
207
    * The launchpad-login command tells Bazaar your Launchpad user name. This
 
208
      is then used by the 'lp:' transport to download your branches using
 
209
      bzr+ssh://.
 
210
 
 
211
    * The register-branch command tells Launchpad about the url of a
148
212
      public branch.  Launchpad will then mirror the branch, display
149
 
      its contents and allow it to be attached to bugs and other 
 
213
      its contents and allow it to be attached to bugs and other
150
214
      objects.
151
215
 
152
 
    * The 'lp:' transport uses Launchpad as a directory service: 
153
 
      for example 'lp:bzr' and 'lp:python' refer to the main branches of the
154
 
      relevant projects and may be branched, logged, etc.  (Only read access
155
 
      is supported at present.)
 
216
    * The 'lp:' transport uses Launchpad as a directory service: for example
 
217
      'lp:bzr' and 'lp:python' refer to the main branches of the relevant
 
218
      projects and may be branched, logged, etc. You can also use the 'lp:'
 
219
      transport to refer to specific branches, e.g. lp:///~bzr/bzr/trunk.
156
220
 
157
221
For more information see http://help.launchpad.net/
158
222
"""