Debian Codegraph @

lib/extra/bugurl.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 # Copyright (C) 2008 Lukáš Lalinský <[email protected]om>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 from breezy import commands, errors, trace, bugtracker
21 from breezy.config import GlobalConfig
22 from breezy.branch import Branch
23 from breezy.option import Option
24
25 from breezy.plugins.qbrz.lib.bugs import FakeBranchForBugs
26
27
28 class cmd_bug_url(commands.Command):
29 """Print full URL to a specific bug, or open it in your browser."""
30
31 takes_args = ['bug_id']
32 takes_options = [
33 Option('open', help='Open the URL in a web browser.'),
34 ]
35
36 def run(self, bug_id, open=False):
37 # we import from qbrz.lib.util here because that module
38 # has dependency on PyQt4 (see bug #327487)
39 from breezy.plugins.qbrz.lib.util import open_browser, url_for_display
40 try:
41 branch = Branch.open_containing('.')[0]
42 except errors.NotBranchError:
43 branch = FakeBranchForBugs()
44 tokens = bug_id.split(':')
45 if len(tokens) != 2:
46 raise errors.BzrCommandError("Invalid bug %s. Must be in the form of 'tag:id'." % bug_id)
47 tag, tag_bug_id = tokens
48 try:
49 bug_url = bugtracker.get_bug_url(tag, branch, tag_bug_id)
50 except errors.UnknownBugTrackerAbbreviation:
51 raise errors.BzrCommandError('Unrecognized bug %s.' % bug_id)
52 except errors.MalformedBugIdentifier:
53 raise errors.BzrCommandError("Invalid bug identifier for %s." % bug_id)
54 self.outf.write(url_for_display(bug_url) + "\n")
55 if open:
56 open_browser(bug_url)