12
12
# along with this program; if not, write to the Free Software
13
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
"""Graphical support for Bazaar using GTK.
18
gannotate GTK+ annotate.
19
gbranch GTK+ branching.
20
gcheckout GTK+ checkout.
21
gcommit GTK+ commit dialog.
22
gconflicts GTK+ conflicts.
23
gdiff Show differences in working tree in a GTK+ Window.
24
ginit Initialise a new branch.
25
ginfo GTK+ branch info dialog
26
gloom GTK+ loom browse dialog
27
gmerge GTK+ merge dialog
28
gmissing GTK+ missing revisions dialog.
29
gpreferences GTK+ preferences dialog.
31
gsend GTK+ send merge directive.
32
gstatus GTK+ status dialog.
33
gtags Manage branch tags.
34
visualise Graphically visualise this branch.
40
if getattr(sys, "frozen", None) is not None: # we run bzr.exe
42
# FIXME: Unless a better packaging solution is found, the following
43
# provides a workaround for https://bugs.launchpad.net/bzr/+bug/388790 Also
44
# see https://code.edge.launchpad.net/~vila/bzr-gtk/388790-windows-setup
45
# for more details about while it's needed.
47
# NOTE: _lib must be ahead of bzrlib or sax.saxutils (in olive) fails
48
here = os.path.dirname(__file__)
49
sys.path.insert(0, os.path.join(here, '_lib'))
50
sys.path.append(os.path.join(here, '_lib/gtk-2.0'))
15
"""GTK+ frontends to Bazaar commands """
19
__version__ = '0.16.0'
20
version_info = tuple(int(n) for n in __version__.split('.'))
23
def check_bzrlib_version(desired):
24
"""Check that bzrlib is compatible.
26
If version is < bzr-gtk version, assume incompatible.
27
If version == bzr-gtk version, assume completely compatible
28
If version == bzr-gtk version + 1, assume compatible, with deprecations
29
Otherwise, assume incompatible.
31
desired_plus = (desired[0], desired[1]+1)
32
bzrlib_version = bzrlib.version_info[:2]
33
if bzrlib_version == desired:
36
from bzrlib.trace import warning
38
# get the message out any way we can
39
from warnings import warn as warning
40
if bzrlib_version < desired:
41
warning('Installed bzr version %s is too old to be used with bzr-gtk'
42
' %s.' % (bzrlib.__version__, __version__))
43
# Not using BzrNewError, because it may not exist.
44
raise Exception, ('Version mismatch', version_info)
46
warning('bzr-gtk is not up to date with installed bzr version %s.'
47
' \nThere should be a newer version available, e.g. %i.%i.'
48
% (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
49
if bzrlib_version != desired_plus:
50
raise Exception, 'Version mismatch'
53
check_bzrlib_version(version_info[:2])
55
from bzrlib.trace import warning
56
if __name__ != 'bzrlib.plugins.gtk':
57
warning("Not running as bzrlib.plugins.gtk, things may break.")
59
from bzrlib.lazy_import import lazy_import
60
lazy_import(globals(), """
55
61
from bzrlib import (
60
from bzrlib.commands import plugin_cmds
63
version_info = (0, 98, 0, 'dev', 1)
65
if version_info[3] == 'final':
66
version_string = '%d.%d.%d' % version_info[:3]
68
version_string = '%d.%d.%d%s%d' % version_info
69
__version__ = version_string
71
COMPATIBLE_BZR_VERSIONS = [(1, 6, 0), (1, 7, 0), (1, 8, 0), (1, 9, 0),
72
(1, 10, 0), (1, 11, 0), (1, 12, 0), (1, 13, 0),
78
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
80
if __name__ != 'bzrlib.plugins.gtk':
81
from bzrlib.trace import warning
82
warning("Not running as bzrlib.plugins.gtk, things may break.")
68
from bzrlib.commands import Command, register_command, display_command
69
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
70
from bzrlib.commands import Command, register_command
71
from bzrlib.option import Option
72
from bzrlib.bzrdir import BzrDir
84
76
def import_pygtk():
93
85
def set_ui_factory():
86
pygtk = import_pygtk()
95
87
from ui import GtkUIFactory
97
89
bzrlib.ui.ui_factory = GtkUIFactory()
101
return [os.path.dirname(__file__),
102
"/usr/share/bzr-gtk",
103
"/usr/local/share/bzr-gtk"]
106
def data_path(*args):
107
for basedir in data_basedirs():
108
path = os.path.join(basedir, *args)
109
if os.path.exists(path):
114
def icon_path(*args):
115
return data_path(os.path.join('icons', *args))
119
pygtk = import_pygtk()
122
except RuntimeError, e:
123
if str(e) == "could not open display":
130
"gannotate": ["gblame", "gpraise"],
146
"visualise": ["visualize", "vis", "viz"],
150
from bzrlib.plugins import loom
152
pass # Loom plugin doesn't appear to be present
154
commands["gloom"] = []
156
for cmd, aliases in commands.iteritems():
157
plugin_cmds.register_lazy("cmd_%s" % cmd, aliases,
158
"bzrlib.plugins.gtk.commands")
160
def save_commit_messages(*args):
161
from bzrlib.plugins.gtk import commit
162
commit.save_commit_messages(*args)
164
branch.Branch.hooks.install_named_hook('post_uncommit',
165
save_commit_messages,
166
"Saving commit messages for gcommit")
92
class cmd_gbranch(Command):
98
pygtk = import_pygtk()
101
except RuntimeError, e:
102
if str(e) == "could not open display":
105
from bzrlib.plugins.gtk.branch import BranchDialog
108
dialog = BranchDialog(os.path.abspath('.'))
111
register_command(cmd_gbranch)
113
class cmd_gcheckout(Command):
119
pygtk = import_pygtk()
122
except RuntimeError, e:
123
if str(e) == "could not open display":
126
from bzrlib.plugins.gtk.checkout import CheckoutDialog
129
dialog = CheckoutDialog(os.path.abspath('.'))
132
register_command(cmd_gcheckout)
134
class cmd_gpush(Command):
138
takes_args = [ "location?" ]
140
def run(self, location="."):
141
(br, path) = branch.Branch.open_containing(location)
143
pygtk = import_pygtk()
146
except RuntimeError, e:
147
if str(e) == "could not open display":
150
from push import PushDialog
153
dialog = PushDialog(br)
156
register_command(cmd_gpush)
158
class cmd_gdiff(Command):
159
"""Show differences in working tree in a GTK+ Window.
161
Otherwise, all changes for the tree are listed.
163
takes_args = ['filename?']
164
takes_options = ['revision']
167
def run(self, revision=None, filename=None):
169
wt = workingtree.WorkingTree.open_containing(".")[0]
173
if revision is not None:
174
if len(revision) == 1:
176
revision_id = revision[0].in_history(branch).rev_id
177
tree2 = branch.repository.revision_tree(revision_id)
178
elif len(revision) == 2:
179
revision_id_0 = revision[0].in_history(branch).rev_id
180
tree2 = branch.repository.revision_tree(revision_id_0)
181
revision_id_1 = revision[1].in_history(branch).rev_id
182
tree1 = branch.repository.revision_tree(revision_id_1)
185
tree2 = tree1.basis_tree()
187
from diff import DiffWindow
189
window = DiffWindow()
190
window.connect("destroy", gtk.main_quit)
191
window.set_diff("Working Tree", tree1, tree2)
192
if filename is not None:
193
tree_filename = wt.relpath(filename)
195
window.set_file(tree_filename)
197
if (tree1.inventory.path2id(tree_filename) is None and
198
tree2.inventory.path2id(tree_filename) is None):
199
raise NotVersionedError(filename)
200
raise BzrCommandError('No changes found for file "%s"' %
208
register_command(cmd_gdiff)
210
class cmd_visualise(Command):
211
"""Graphically visualise this branch.
213
Opens a graphical window to allow you to see the history of the branch
214
and relationships between revisions in a visual manner,
216
The default starting point is latest revision on the branch, you can
217
specify a starting point with -r revision.
221
Option('limit', "maximum number of revisions to display",
223
takes_args = [ "location?" ]
224
aliases = [ "visualize", "vis", "viz" ]
226
def run(self, location=".", revision=None, limit=None):
228
(br, path) = branch.Branch.open_containing(location)
230
br.repository.lock_read()
233
revid = br.last_revision()
237
(revno, revid) = revision[0].in_history(br)
239
from viz.branchwin import BranchWindow
243
pp.set_branch(br, revid, limit)
244
pp.connect("destroy", lambda w: gtk.main_quit())
248
br.repository.unlock()
252
register_command(cmd_visualise)
254
class cmd_gannotate(Command):
257
Browse changes to FILENAME line by line in a GTK+ window.
260
takes_args = ["filename", "line?"]
262
Option("all", help="show annotations on all lines"),
263
Option("plain", help="don't highlight annotation lines"),
264
Option("line", type=int, argname="lineno",
265
help="jump to specified line number"),
268
aliases = ["gblame", "gpraise"]
270
def run(self, filename, all=False, plain=False, line='1', revision=None):
271
pygtk = import_pygtk()
275
except RuntimeError, e:
276
if str(e) == "could not open display":
283
raise BzrCommandError('Line argument ("%s") is not a number.' %
286
from annotate.gannotate import GAnnotateWindow
287
from annotate.config import GAnnotateConfig
289
wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
293
tree = br.basis_tree()
295
file_id = tree.path2id(path)
298
raise NotVersionedError(filename)
299
if revision is not None:
300
if len(revision) != 1:
301
raise BzrCommandError("Only 1 revion may be specified.")
302
revision_id = revision[0].in_history(br).rev_id
303
tree = br.repository.revision_tree(revision_id)
305
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
307
window = GAnnotateWindow(all, plain)
308
window.connect("destroy", lambda w: gtk.main_quit())
309
window.set_title(path + " - gannotate")
310
config = GAnnotateConfig(window)
316
window.annotate(tree, br, file_id)
317
window.jump_to_line(line)
324
register_command(cmd_gannotate)
326
class cmd_gcommit(Command):
327
"""GTK+ commit dialog
329
Graphical user interface for committing revisions"""
335
def run(self, filename=None):
337
pygtk = import_pygtk()
341
except RuntimeError, e:
342
if str(e) == "could not open display":
346
from commit import CommitDialog
347
from bzrlib.commit import Commit
348
from bzrlib.errors import (BzrCommandError,
358
(wt, path) = workingtree.WorkingTree.open_containing(filename)
360
except NotBranchError, e:
362
except NoWorkingTree, e:
365
(br, path) = branch.Branch.open_containing(path)
366
except NotBranchError, e:
370
commit = CommitDialog(wt, path, not br)
373
register_command(cmd_gcommit)
375
class cmd_gstatus(Command):
376
"""GTK+ status dialog
378
Graphical user interface for showing status
382
takes_args = ['PATH?']
385
def run(self, path='.'):
387
pygtk = import_pygtk()
391
except RuntimeError, e:
392
if str(e) == "could not open display":
396
from status import StatusDialog
397
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
398
status = StatusDialog(wt, wt_path)
399
status.connect("destroy", gtk.main_quit)
402
register_command(cmd_gstatus)
404
class cmd_gconflicts(Command):
409
(wt, path) = workingtree.WorkingTree.open_containing('.')
411
pygtk = import_pygtk()
414
except RuntimeError, e:
415
if str(e) == "could not open display":
418
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
421
dialog = ConflictsDialog(wt)
424
register_command(cmd_gconflicts)
169
427
gettext.install('olive-gtk')
171
# Let's create a specialized alias to protect '_' from being erased by other
172
# uses of '_' as an anonymous variable (think pdb for one).
173
_i18n = gettext.gettext
175
class NoDisplayError(errors.BzrCommandError):
429
class NoDisplayError(BzrCommandError):
176
430
"""gtk could not find a proper display"""
178
432
def __str__(self):
179
433
return "No DISPLAY. Unable to run GTK+ application."
182
credential_store_registry = getattr(config, "credential_store_registry", None)
183
if credential_store_registry is not None:
185
credential_store_registry.register_lazy(
186
"gnome-keyring", "bzrlib.plugins.gtk.keyring", "GnomeKeyringCredentialStore",
187
help="The GNOME Keyring.", fallback=True)
189
# Fallback credentials stores were introduced in Bazaar 1.15
190
credential_store_registry.register_lazy(
191
"gnome-keyring", "bzrlib.plugins.gtk.keyring", "GnomeKeyringCredentialStore",
192
help="The GNOME Keyring.")
195
def load_tests(basic_tests, module, loader):
436
from unittest import TestSuite
200
439
default_encoding = sys.getdefaultencoding()
205
except errors.BzrCommandError:
207
basic_tests.addTest(loader.loadTestsFromModuleNames(
208
["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
442
result.addTest(tests.test_suite())
210
if sys.getdefaultencoding() != default_encoding:
212
sys.setdefaultencoding(default_encoding)
445
sys.setdefaultencoding(default_encoding)