~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Launchpad.net integration plugin for Bazaar."""
18
18
 
21
21
 
22
22
# see http://bazaar-vcs.org/Specs/BranchRegistrationTool
23
23
 
24
 
from bzrlib.branch import Branch
 
24
from bzrlib.lazy_import import lazy_import
 
25
lazy_import(globals(), """
 
26
import webbrowser
 
27
 
 
28
from bzrlib import (
 
29
    branch as _mod_branch,
 
30
    trace,
 
31
    )
 
32
""")
 
33
 
25
34
from bzrlib.commands import Command, Option, register_command
26
35
from bzrlib.directory_service import directories
27
 
from bzrlib.errors import BzrCommandError, NoPublicBranch, NotBranchError
 
36
from bzrlib.errors import (
 
37
    BzrCommandError,
 
38
    InvalidURL,
 
39
    NoPublicBranch,
 
40
    NotBranchError,
 
41
    )
28
42
from bzrlib.help_topics import topic_registry
 
43
from bzrlib.plugins.launchpad.lp_registration import (
 
44
    LaunchpadService,
 
45
    NotLaunchpadBranch,
 
46
    )
29
47
 
30
48
 
31
49
class cmd_register_branch(Command):
34
52
    This command lists a bzr branch in the directory of branches on
35
53
    launchpad.net.  Registration allows the branch to be associated with
36
54
    bugs or specifications.
37
 
    
 
55
 
38
56
    Before using this command you must register the product to which the
39
57
    branch belongs, and create an account for yourself on launchpad.net.
40
58
 
91
109
            DryRunLaunchpadService)
92
110
        if public_url is None:
93
111
            try:
94
 
                b = Branch.open_containing('.')[0]
 
112
                b = _mod_branch.Branch.open_containing('.')[0]
95
113
            except NotBranchError:
96
114
                raise BzrCommandError('register-branch requires a public '
97
115
                    'branch url - see bzr help register-branch.')
127
145
register_command(cmd_register_branch)
128
146
 
129
147
 
130
 
# XXX: Make notes to test this.
131
148
class cmd_launchpad_open(Command):
132
149
    """Open a Launchpad branch page in your web browser."""
133
150
 
139
156
        ]
140
157
    takes_args = ['location?']
141
158
 
 
159
    def _possible_locations(self, location):
 
160
        """Yield possible external locations for the branch at 'location'."""
 
161
        yield location
 
162
        try:
 
163
            branch = _mod_branch.Branch.open(location)
 
164
        except NotBranchError:
 
165
            return
 
166
        branch_url = branch.get_public_branch()
 
167
        if branch_url is not None:
 
168
            yield branch_url
 
169
        branch_url = branch.get_push_location()
 
170
        if branch_url is not None:
 
171
            yield branch_url
 
172
 
 
173
    def _get_web_url(self, service, location):
 
174
        for branch_url in self._possible_locations(location):
 
175
            try:
 
176
                return service.get_web_url_from_branch_url(branch_url)
 
177
            except (NotLaunchpadBranch, InvalidURL):
 
178
                pass
 
179
        raise NotLaunchpadBranch(branch_url)
 
180
 
142
181
    def run(self, location=None, dry_run=False):
143
 
        from bzrlib.plugins.launchpad.lp_registration import LaunchpadService
144
 
        from bzrlib.trace import note
145
 
        import webbrowser
146
182
        if location is None:
147
183
            location = u'.'
148
 
        branch = Branch.open(location)
149
 
        branch_url = branch.get_public_branch()
150
 
        if branch_url is None:
151
 
            raise NoPublicBranch(branch)
152
 
        service = LaunchpadService()
153
 
        web_url = service.get_web_url_from_branch_url(branch_url)
154
 
        note('Opening %s in web browser' % web_url)
 
184
        web_url = self._get_web_url(LaunchpadService(), location)
 
185
        trace.note('Opening %s in web browser' % web_url)
155
186
        if not dry_run:
156
187
            webbrowser.open(web_url)
157
188
 
195
226
                self.outf.write('No Launchpad user ID configured.\n')
196
227
                return 1
197
228
        else:
 
229
            name = name.lower()
198
230
            if check_account:
199
231
                account.check_lp_login(name)
200
232
            account.set_lp_login(name)