1
# This program is free software; you can redistribute it and/or modify
2
# it under the terms of the GNU General Public License as published by
3
# the Free Software Foundation; either version 2 of the License, or
4
# (at your option) any later version.
6
# This program is distributed in the hope that it will be useful,
7
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
# GNU General Public License for more details.
11
# You should have received a copy of the GNU General Public License
12
# along with this program; if not, write to the Free Software
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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(), """
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
80
raise errors.BzrCommandError("PyGTK not installed.")
86
pygtk = import_pygtk()
87
from ui import GtkUIFactory
89
bzrlib.ui.ui_factory = GtkUIFactory()
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)
427
gettext.install('olive-gtk')
429
class NoDisplayError(BzrCommandError):
430
"""gtk could not find a proper display"""
433
return "No DISPLAY. Unable to run GTK+ application."
436
from unittest import TestSuite
439
default_encoding = sys.getdefaultencoding()
442
result.addTest(tests.test_suite())
445
sys.setdefaultencoding(default_encoding)