~bzr/ubuntu/lucid/bzr/beta-ppa

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2010-07-02 07:29:40 UTC
  • mfrom: (129.1.7 packaging-karmic)
  • Revision ID: mbp@sourcefrog.net-20100702072940-hpzq5elg8wjve8rh
* PPA rebuild.
* PPA rebuild for Karmic.
* PPA rebuild for Jaunty.
* PPA rebuild for Hardy.
* From postinst, actually remove the example bash completion scripts.
  (LP: #249452)
* New upstream release.
* New upstream release.
* New upstream release.
* Revert change to Build-depends: Dapper does not have python-central.
  Should be python-support..
* Target ppa..
* Target ppa..
* Target ppa..
* Target ppa..
* New upstream release.
* Switch to dpkg-source 3.0 (quilt) format.
* Bump standards version to 3.8.4.
* Remove embedded copy of python-configobj. Closes: #555336
* Remove embedded copy of python-elementtree. Closes: #555343
* Change section from 'Devel' to 'Vcs'..
* Change section from 'Devel' to 'Vcs'..
* Change section from 'Devel' to 'Vcs'..
* Change section from 'Devel' to 'Vcs'..
* Change section from 'Devel' to 'Vcs'..
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* debian/control: Fix obsolete-relation-form-in-source
  lintian warning. 
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Split out docs into bzr-doc package.
* New upstream release.
* Added John Francesco Ferlito to Uploaders.
* Fix install path to quick-reference guide
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Fix FTBFS due to path changes, again.
* Fix FTBFS due to doc paths changing
* New upstream release.
* Fix FTBFS due to path changes, again.
* Fix FTBFS due to doc paths changing
* New upstream release.
* Fix FTBFS due to path changes, again.
* Fix FTBFS due to doc paths changing
* New upstream release.
* Fix FTBFS due to path changes, again, again.
* Fix FTBFS due to path changes, again.
* Fix FTBFS due to path changes.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Bump standards version to 3.8.3.
* Remove unused patch system.
* New upstream release.
* New upstream release.
* New upstream release.
* Fix copy and paste tab error in .install file
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
 + Fixes compatibility with Python 2.4. Closes: #537708
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream version.
* Bump standards version to 3.8.2.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Add python-pyrex to build-deps to ensure C extensions are always build.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Split documentation into bzr-doc package. ((LP: #385074)
* Multiple packaging changes to make us more linitan clean.
* New upstream release.
* Split documentation into bzr-doc package. ((LP: #385074)
* Multiple packaging changes to make us more linitan clean.
* New upstream release.
* Split documentation into bzr-doc package. ((LP: #385074)
* Multiple packaging changes to make us more linitan clean.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Fix API compatibility version. (Closes: #526233)
* New upstream release.
  + Fixes default format for upgrade command. (Closes: #464688)
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Add missing dependency on zlib development library. (Closes:
  #523595)
* Add zlib build-depends.
* Add zlib build-depends.
* Add zlib build-depends.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Move to section vcs.
* Bump standards version to 3.8.1.
* New upstream release.
* Remove temporary patch for missing .c files from distribution
* New upstream release.
* Remove temporary patch for missing .c files from distribution
* New upstream release.
* Remove temporary patch for missing .c files from distribution
* Add temporary patch for missing .c files from distribution
* Add temporary patch for missing .c files from distribution
* Add temporary patch for missing .c files from distribution
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Recommend ca-certificates. (Closes: #452024)
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Update watch file. bazaar now uses launchpad to host its sources.
* Remove patch for inventory root revision copy, applied upstream.
* New upstream release.
* New upstream release.
* New upstream release
* Force removal of files installed in error to /etc/bash_completion.d/
  (LP: #249452)
* New upstream release.
* New upstream release
* New upstream release.
* Bump standards version.
* Include patch for inventory root revision copy, required for bzr-svn.
* New upstream release.
* Remove unused lintian overrides.
* Correct the package version not to be native.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* New upstream release.
* Final 1.5 release.
* New upstream release.
* New upstream release.
* New upstream release.
* Add myself as a co-maintainer.
* Add a Dm-Upload-Allowed: yes header.
* New upstream bugfix release.
* New upstream release.
* Final 1.3 release.
* New upstream release.
* First release candidate of the upcoming 1.3 release.
* Rebuild to fix the problem caused by a build with a broken python-central.
* New upstream release.
* Rebuild for dapper PPA.
* Apply Lamont's patches to fix build-dependencies on dapper.
  (See: https://bugs.launchpad.net/bzr/+bug/189915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2010 Canonical Ltd
 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Launchpad.net integration plugin for Bazaar."""
 
18
 
 
19
# The XMLRPC server address can be overridden by setting the environment
 
20
# variable $BZR_LP_XMLRPL_URL
 
21
 
 
22
# see http://bazaar-vcs.org/Specs/BranchRegistrationTool
 
23
 
 
24
# Since we are a built-in plugin we share the bzrlib version
 
25
from bzrlib import version_info
 
26
 
 
27
from bzrlib.lazy_import import lazy_import
 
28
lazy_import(globals(), """
 
29
from bzrlib import (
 
30
    branch as _mod_branch,
 
31
    trace,
 
32
    )
 
33
""")
 
34
 
 
35
from bzrlib.commands import Command, Option, register_command
 
36
from bzrlib.directory_service import directories
 
37
from bzrlib.errors import (
 
38
    BzrCommandError,
 
39
    DependencyNotPresent,
 
40
    InvalidURL,
 
41
    NoPublicBranch,
 
42
    NotBranchError,
 
43
    )
 
44
from bzrlib.help_topics import topic_registry
 
45
 
 
46
 
 
47
class cmd_register_branch(Command):
 
48
    """Register a branch with launchpad.net.
 
49
 
 
50
    This command lists a bzr branch in the directory of branches on
 
51
    launchpad.net.  Registration allows the branch to be associated with
 
52
    bugs or specifications.
 
53
 
 
54
    Before using this command you must register the project to which the
 
55
    branch belongs, and create an account for yourself on launchpad.net.
 
56
 
 
57
    arguments:
 
58
        public_url: The publicly visible url for the branch to register.
 
59
                    This must be an http or https url (which Launchpad can read
 
60
                    from to access the branch). Local file urls, SFTP urls, and
 
61
                    bzr+ssh urls will not work.
 
62
                    If no public_url is provided, bzr will use the configured
 
63
                    public_url if there is one for the current branch, and
 
64
                    otherwise error.
 
65
 
 
66
    example:
 
67
        bzr register-branch http://foo.com/bzr/fooproject.mine \\
 
68
                --project fooproject
 
69
    """
 
70
    takes_args = ['public_url?']
 
71
    takes_options = [
 
72
         Option('project',
 
73
                'Launchpad project short name to associate with the branch.',
 
74
                unicode),
 
75
         Option('product',
 
76
                'Launchpad product short name to associate with the branch.', 
 
77
                unicode,
 
78
                hidden=True),
 
79
         Option('branch-name',
 
80
                'Short name for the branch; '
 
81
                'by default taken from the last component of the url.',
 
82
                unicode),
 
83
         Option('branch-title',
 
84
                'One-sentence description of the branch.',
 
85
                unicode),
 
86
         Option('branch-description',
 
87
                'Longer description of the purpose or contents of the branch.',
 
88
                unicode),
 
89
         Option('author',
 
90
                "Branch author's email address, if not yourself.",
 
91
                unicode),
 
92
         Option('link-bug',
 
93
                'The bug this branch fixes.',
 
94
                int),
 
95
         Option('dry-run',
 
96
                'Prepare the request but don\'t actually send it.')
 
97
        ]
 
98
 
 
99
 
 
100
    def run(self,
 
101
            public_url=None,
 
102
            project='',
 
103
            product=None,
 
104
            branch_name='',
 
105
            branch_title='',
 
106
            branch_description='',
 
107
            author='',
 
108
            link_bug=None,
 
109
            dry_run=False):
 
110
        from bzrlib.plugins.launchpad.lp_registration import (
 
111
            BranchRegistrationRequest, BranchBugLinkRequest,
 
112
            DryRunLaunchpadService, LaunchpadService)
 
113
        if public_url is None:
 
114
            try:
 
115
                b = _mod_branch.Branch.open_containing('.')[0]
 
116
            except NotBranchError:
 
117
                raise BzrCommandError('register-branch requires a public '
 
118
                    'branch url - see bzr help register-branch.')
 
119
            public_url = b.get_public_branch()
 
120
            if public_url is None:
 
121
                raise NoPublicBranch(b)
 
122
        if product is not None:
 
123
            project = product
 
124
            trace.note('--product is deprecated; please use --project.')
 
125
 
 
126
 
 
127
        rego = BranchRegistrationRequest(branch_url=public_url,
 
128
                                         branch_name=branch_name,
 
129
                                         branch_title=branch_title,
 
130
                                         branch_description=branch_description,
 
131
                                         product_name=project,
 
132
                                         author_email=author,
 
133
                                         )
 
134
        linko = BranchBugLinkRequest(branch_url=public_url,
 
135
                                     bug_id=link_bug)
 
136
        if not dry_run:
 
137
            service = LaunchpadService()
 
138
            # This gives back the xmlrpc url that can be used for future
 
139
            # operations on the branch.  It's not so useful to print to the
 
140
            # user since they can't do anything with it from a web browser; it
 
141
            # might be nice for the server to tell us about an html url as
 
142
            # well.
 
143
        else:
 
144
            # Run on service entirely in memory
 
145
            service = DryRunLaunchpadService()
 
146
        service.gather_user_credentials()
 
147
        rego.submit(service)
 
148
        if link_bug:
 
149
            linko.submit(service)
 
150
        print 'Branch registered.'
 
151
 
 
152
register_command(cmd_register_branch)
 
153
 
 
154
 
 
155
class cmd_launchpad_open(Command):
 
156
    """Open a Launchpad branch page in your web browser."""
 
157
 
 
158
    aliases = ['lp-open']
 
159
    takes_options = [
 
160
        Option('dry-run',
 
161
               'Do not actually open the browser. Just say the URL we would '
 
162
               'use.'),
 
163
        ]
 
164
    takes_args = ['location?']
 
165
 
 
166
    def _possible_locations(self, location):
 
167
        """Yield possible external locations for the branch at 'location'."""
 
168
        yield location
 
169
        try:
 
170
            branch = _mod_branch.Branch.open_containing(location)[0]
 
171
        except NotBranchError:
 
172
            return
 
173
        branch_url = branch.get_public_branch()
 
174
        if branch_url is not None:
 
175
            yield branch_url
 
176
        branch_url = branch.get_push_location()
 
177
        if branch_url is not None:
 
178
            yield branch_url
 
179
 
 
180
    def _get_web_url(self, service, location):
 
181
        from bzrlib.plugins.launchpad.lp_registration import (
 
182
            NotLaunchpadBranch)
 
183
        for branch_url in self._possible_locations(location):
 
184
            try:
 
185
                return service.get_web_url_from_branch_url(branch_url)
 
186
            except (NotLaunchpadBranch, InvalidURL):
 
187
                pass
 
188
        raise NotLaunchpadBranch(branch_url)
 
189
 
 
190
    def run(self, location=None, dry_run=False):
 
191
        from bzrlib.plugins.launchpad.lp_registration import (
 
192
            LaunchpadService)
 
193
        if location is None:
 
194
            location = u'.'
 
195
        web_url = self._get_web_url(LaunchpadService(), location)
 
196
        trace.note('Opening %s in web browser' % web_url)
 
197
        if not dry_run:
 
198
            import webbrowser   # this import should not be lazy
 
199
                                # otherwise bzr.exe lacks this module
 
200
            webbrowser.open(web_url)
 
201
 
 
202
register_command(cmd_launchpad_open)
 
203
 
 
204
 
 
205
class cmd_launchpad_login(Command):
 
206
    """Show or set the Launchpad user ID.
 
207
 
 
208
    When communicating with Launchpad, some commands need to know your
 
209
    Launchpad user ID.  This command can be used to set or show the
 
210
    user ID that Bazaar will use for such communication.
 
211
 
 
212
    :Examples:
 
213
      Show the Launchpad ID of the current user::
 
214
 
 
215
          bzr launchpad-login
 
216
 
 
217
      Set the Launchpad ID of the current user to 'bob'::
 
218
 
 
219
          bzr launchpad-login bob
 
220
    """
 
221
    aliases = ['lp-login']
 
222
    takes_args = ['name?']
 
223
    takes_options = [
 
224
        'verbose',
 
225
        Option('no-check',
 
226
               "Don't check that the user name is valid."),
 
227
        ]
 
228
 
 
229
    def run(self, name=None, no_check=False, verbose=False):
 
230
        # This is totally separate from any launchpadlib login system.
 
231
        from bzrlib.plugins.launchpad import account
 
232
        check_account = not no_check
 
233
 
 
234
        if name is None:
 
235
            username = account.get_lp_login()
 
236
            if username:
 
237
                if check_account:
 
238
                    account.check_lp_login(username)
 
239
                    if verbose:
 
240
                        self.outf.write(
 
241
                            "Launchpad user ID exists and has SSH keys.\n")
 
242
                self.outf.write(username + '\n')
 
243
            else:
 
244
                self.outf.write('No Launchpad user ID configured.\n')
 
245
                return 1
 
246
        else:
 
247
            name = name.lower()
 
248
            if check_account:
 
249
                account.check_lp_login(name)
 
250
                if verbose:
 
251
                    self.outf.write(
 
252
                        "Launchpad user ID exists and has SSH keys.\n")
 
253
            account.set_lp_login(name)
 
254
            if verbose:
 
255
                self.outf.write("Launchpad user ID set to '%s'.\n" % (name,))
 
256
 
 
257
register_command(cmd_launchpad_login)
 
258
 
 
259
 
 
260
# XXX: cmd_launchpad_mirror is untested
 
261
class cmd_launchpad_mirror(Command):
 
262
    """Ask Launchpad to mirror a branch now."""
 
263
 
 
264
    aliases = ['lp-mirror']
 
265
    takes_args = ['location?']
 
266
 
 
267
    def run(self, location='.'):
 
268
        from bzrlib.plugins.launchpad import lp_api
 
269
        from bzrlib.plugins.launchpad.lp_registration import LaunchpadService
 
270
        branch = _mod_branch.Branch.open(location)
 
271
        service = LaunchpadService()
 
272
        launchpad = lp_api.login(service)
 
273
        lp_branch = lp_api.load_branch(launchpad, branch)
 
274
        lp_branch.requestMirror()
 
275
 
 
276
 
 
277
register_command(cmd_launchpad_mirror)
 
278
 
 
279
 
 
280
def _register_directory():
 
281
    directories.register_lazy('lp:', 'bzrlib.plugins.launchpad.lp_directory',
 
282
                              'LaunchpadDirectory',
 
283
                              'Launchpad-based directory service',)
 
284
_register_directory()
 
285
 
 
286
 
 
287
def load_tests(basic_tests, module, loader):
 
288
    testmod_names = [
 
289
        'test_account',
 
290
        'test_register',
 
291
        'test_lp_api',
 
292
        'test_lp_directory',
 
293
        'test_lp_login',
 
294
        'test_lp_open',
 
295
        'test_lp_service',
 
296
        ]
 
297
    basic_tests.addTest(loader.loadTestsFromModuleNames(
 
298
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
 
299
    return basic_tests
 
300
 
 
301
 
 
302
_launchpad_help = """Integration with Launchpad.net
 
303
 
 
304
Launchpad.net provides free Bazaar branch hosting with integrated bug and
 
305
specification tracking.
 
306
 
 
307
The bzr client (through the plugin called 'launchpad') has special
 
308
features to communicate with Launchpad:
 
309
 
 
310
    * The launchpad-login command tells Bazaar your Launchpad user name. This
 
311
      is then used by the 'lp:' transport to download your branches using
 
312
      bzr+ssh://.
 
313
 
 
314
    * The 'lp:' transport uses Launchpad as a directory service: for example
 
315
      'lp:bzr' and 'lp:python' refer to the main branches of the relevant
 
316
      projects and may be branched, logged, etc. You can also use the 'lp:'
 
317
      transport to refer to specific branches, e.g. lp:~bzr/bzr/trunk.
 
318
 
 
319
    * The 'lp:' bug tracker alias can expand launchpad bug numbers to their
 
320
      URLs for use with 'bzr commit --fixes', e.g. 'bzr commit --fixes lp:12345'
 
321
      will record a revision property that marks that revision as fixing
 
322
      Launchpad bug 12345. When you push that branch to Launchpad it will
 
323
      automatically be linked to the bug report.
 
324
 
 
325
    * The register-branch command tells Launchpad about the url of a
 
326
      public branch.  Launchpad will then mirror the branch, display
 
327
      its contents and allow it to be attached to bugs and other
 
328
      objects.
 
329
 
 
330
For more information see http://help.launchpad.net/
 
331
"""
 
332
topic_registry.register('launchpad',
 
333
    _launchpad_help,
 
334
    'Using Bazaar with Launchpad.net')