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.15.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]
171
if revision is not None:
172
if len(revision) == 1:
174
revision_id = revision[0].in_history(branch).rev_id
175
tree2 = branch.repository.revision_tree(revision_id)
176
elif len(revision) == 2:
177
revision_id_0 = revision[0].in_history(branch).rev_id
178
tree2 = branch.repository.revision_tree(revision_id_0)
179
revision_id_1 = revision[1].in_history(branch).rev_id
180
tree1 = branch.repository.revision_tree(revision_id_1)
183
tree2 = tree1.basis_tree()
185
from diff import DiffWindow
187
window = DiffWindow()
188
window.connect("destroy", gtk.main_quit)
189
window.set_diff("Working Tree", tree1, tree2)
190
if filename is not None:
191
tree_filename = wt.relpath(filename)
193
window.set_file(tree_filename)
195
if (tree1.inventory.path2id(tree_filename) is None and
196
tree2.inventory.path2id(tree_filename) is None):
197
raise NotVersionedError(filename)
198
raise BzrCommandError('No changes found for file "%s"' %
204
register_command(cmd_gdiff)
206
class cmd_visualise(Command):
207
"""Graphically visualise this branch.
209
Opens a graphical window to allow you to see the history of the branch
210
and relationships between revisions in a visual manner,
212
The default starting point is latest revision on the branch, you can
213
specify a starting point with -r revision.
217
Option('limit', "maximum number of revisions to display",
219
takes_args = [ "location?" ]
220
aliases = [ "visualize", "vis", "viz" ]
222
def run(self, location=".", revision=None, limit=None):
224
(br, path) = branch.Branch.open_containing(location)
226
br.repository.lock_read()
229
revid = br.last_revision()
233
(revno, revid) = revision[0].in_history(br)
235
from viz.branchwin import BranchWindow
239
pp.set_branch(br, revid, limit)
240
pp.connect("destroy", lambda w: gtk.main_quit())
244
br.repository.unlock()
248
register_command(cmd_visualise)
250
class cmd_gannotate(Command):
253
Browse changes to FILENAME line by line in a GTK+ window.
256
takes_args = ["filename", "line?"]
258
Option("all", help="show annotations on all lines"),
259
Option("plain", help="don't highlight annotation lines"),
260
Option("line", type=int, argname="lineno",
261
help="jump to specified line number"),
264
aliases = ["gblame", "gpraise"]
266
def run(self, filename, all=False, plain=False, line='1', revision=None):
267
pygtk = import_pygtk()
271
except RuntimeError, e:
272
if str(e) == "could not open display":
279
raise BzrCommandError('Line argument ("%s") is not a number.' %
282
from annotate.gannotate import GAnnotateWindow
283
from annotate.config import GAnnotateConfig
286
(tree, path) = workingtree.WorkingTree.open_containing(filename)
288
except errors.NoWorkingTree:
289
(br, path) = branch.Branch.open_containing(filename)
290
tree = br.basis_tree()
292
file_id = tree.path2id(path)
295
raise NotVersionedError(filename)
296
if revision is not None:
297
if len(revision) != 1:
298
raise BzrCommandError("Only 1 revion may be specified.")
299
revision_id = revision[0].in_history(br).rev_id
300
tree = br.repository.revision_tree(revision_id)
302
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
304
window = GAnnotateWindow(all, plain)
305
window.connect("destroy", lambda w: gtk.main_quit())
306
window.set_title(path + " - gannotate")
307
config = GAnnotateConfig(window)
311
window.annotate(tree, br, file_id)
314
window.jump_to_line(line)
318
register_command(cmd_gannotate)
320
class cmd_gcommit(Command):
321
"""GTK+ commit dialog
323
Graphical user interface for committing revisions"""
329
def run(self, filename=None):
331
pygtk = import_pygtk()
335
except RuntimeError, e:
336
if str(e) == "could not open display":
340
from commit import CommitDialog
341
from bzrlib.commit import Commit
342
from bzrlib.errors import (BzrCommandError,
352
(wt, path) = workingtree.WorkingTree.open_containing(filename)
354
except NotBranchError, e:
356
except NoWorkingTree, e:
359
(br, path) = branch.Branch.open_containing(path)
360
except NotBranchError, e:
364
commit = CommitDialog(wt, path, not br)
367
register_command(cmd_gcommit)
369
class cmd_gstatus(Command):
370
"""GTK+ status dialog
372
Graphical user interface for showing status
376
takes_args = ['PATH?']
379
def run(self, path='.'):
381
pygtk = import_pygtk()
385
except RuntimeError, e:
386
if str(e) == "could not open display":
390
from status import StatusDialog
391
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
392
status = StatusDialog(wt, wt_path)
393
status.connect("destroy", gtk.main_quit)
396
register_command(cmd_gstatus)
398
class cmd_gconflicts(Command):
403
(wt, path) = workingtree.WorkingTree.open_containing('.')
405
pygtk = import_pygtk()
408
except RuntimeError, e:
409
if str(e) == "could not open display":
412
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
415
dialog = ConflictsDialog(wt)
418
register_command(cmd_gconflicts)
421
gettext.install('olive-gtk')
423
class NoDisplayError(BzrCommandError):
424
"""gtk could not find a proper display"""
427
return "No DISPLAY. Unable to run GTK+ application."
430
from unittest import TestSuite
433
result.addTest(tests.test_suite())