56
38
# get the message out any way we can
57
39
from warnings import warn as warning
58
40
if bzrlib_version < desired:
59
from bzrlib.errors import BzrError
60
41
warning('Installed bzr version %s is too old to be used with bzr-gtk'
61
42
' %s.' % (bzrlib.__version__, __version__))
62
raise BzrError('Version mismatch: %r' % (version_info,) )
43
# Not using BzrNewError, because it may not exist.
44
raise Exception, ('Version mismatch', version_info)
64
46
warning('bzr-gtk is not up to date with installed bzr version %s.'
65
47
' \nThere should be a newer version available, e.g. %i.%i.'
66
48
% (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
49
if bzrlib_version != desired_plus:
50
raise Exception, 'Version mismatch'
69
53
check_bzrlib_version(version_info[:2])
71
from bzrlib.trace import warning
72
if __name__ != 'bzrlib.plugins.gtk':
73
warning("Not running as bzrlib.plugins.gtk, things may break.")
75
from bzrlib.lazy_import import lazy_import
76
lazy_import(globals(), """
55
from bzrlib import errors
85
56
from bzrlib.commands import Command, register_command, display_command
86
57
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
58
from bzrlib.commands import Command, register_command
87
59
from bzrlib.option import Option
60
from bzrlib.branch import Branch
61
from bzrlib.workingtree import WorkingTree
62
from bzrlib.bzrdir import BzrDir
100
75
def set_ui_factory():
102
from ui import GtkUIFactory
76
pygtk = import_pygtk()
77
from olive.ui import GtkUIFactory
104
79
bzrlib.ui.ui_factory = GtkUIFactory()
108
return os.path.dirname(__file__)
111
class GTKCommand(Command):
112
"""Abstract class providing GTK specific run commands."""
114
def open_display(self):
115
pygtk = import_pygtk()
118
except RuntimeError, e:
119
if str(e) == "could not open display":
126
dialog = self.get_gtk_dialog(os.path.abspath('.'))
130
class cmd_gbranch(GTKCommand):
82
class cmd_gbranch(Command):
131
83
"""GTK+ branching.
135
def get_gtk_dialog(self, path):
136
from bzrlib.plugins.gtk.branch import BranchDialog
137
return BranchDialog(path)
140
class cmd_gcheckout(GTKCommand):
145
def get_gtk_dialog(self, path):
146
from bzrlib.plugins.gtk.checkout import CheckoutDialog
147
return CheckoutDialog(path)
151
class cmd_gpush(GTKCommand):
155
takes_args = [ "location?" ]
157
def run(self, location="."):
158
(br, path) = branch.Branch.open_containing(location)
160
from push import PushDialog
161
dialog = PushDialog(br.repository, br.last_revision(), br)
166
class cmd_gdiff(GTKCommand):
88
pygtk = import_pygtk()
91
except RuntimeError, e:
92
if str(e) == "could not open display":
95
from bzrlib.plugins.gtk.olive.branch import BranchDialog
98
dialog = BranchDialog(os.path.abspath('.'))
99
dialog.window.connect("destroy", lambda w: gtk.main_quit())
104
register_command(cmd_gbranch)
106
class cmd_gdiff(Command):
167
107
"""Show differences in working tree in a GTK+ Window.
169
109
Otherwise, all changes for the tree are listed.
175
115
def run(self, revision=None, filename=None):
177
wt = workingtree.WorkingTree.open_containing(".")[0]
181
if revision is not None:
182
if len(revision) == 1:
184
revision_id = revision[0].in_history(branch).rev_id
185
tree2 = branch.repository.revision_tree(revision_id)
186
elif len(revision) == 2:
187
revision_id_0 = revision[0].in_history(branch).rev_id
188
tree2 = branch.repository.revision_tree(revision_id_0)
189
revision_id_1 = revision[1].in_history(branch).rev_id
190
tree1 = branch.repository.revision_tree(revision_id_1)
117
wt = WorkingTree.open_containing(".")[0]
119
if revision is not None:
120
if len(revision) == 1:
193
tree2 = tree1.basis_tree()
195
from diff import DiffWindow
197
window = DiffWindow()
198
window.connect("destroy", gtk.main_quit)
199
window.set_diff("Working Tree", tree1, tree2)
200
if filename is not None:
201
tree_filename = wt.relpath(filename)
203
window.set_file(tree_filename)
205
if (tree1.path2id(tree_filename) is None and
206
tree2.path2id(tree_filename) is None):
207
raise NotVersionedError(filename)
208
raise BzrCommandError('No changes found for file "%s"' %
217
def start_viz_window(branch, revision, limit=None):
218
"""Start viz on branch with revision revision.
220
:return: The viz window object.
222
from viz.branchwin import BranchWindow
225
pp.set_branch(branch, revision, limit)
226
# cleanup locks when the window is closed
227
pp.connect("destroy", lambda w: branch.unlock())
122
revision_id = revision[0].in_history(branch).rev_id
123
tree2 = branch.repository.revision_tree(revision_id)
124
elif len(revision) == 2:
125
revision_id_0 = revision[0].in_history(branch).rev_id
126
tree2 = branch.repository.revision_tree(revision_id_0)
127
revision_id_1 = revision[1].in_history(branch).rev_id
128
tree1 = branch.repository.revision_tree(revision_id_1)
131
tree2 = tree1.basis_tree()
133
from viz.diffwin import DiffWindow
135
window = DiffWindow()
136
window.connect("destroy", lambda w: gtk.main_quit())
137
window.set_diff("Working Tree", tree1, tree2)
138
if filename is not None:
139
tree_filename = wt.relpath(filename)
141
window.set_file(tree_filename)
143
if (tree1.inventory.path2id(tree_filename) is None and
144
tree2.inventory.path2id(tree_filename) is None):
145
raise NotVersionedError(filename)
146
raise BzrCommandError('No changes found for file "%s"' %
152
register_command(cmd_gdiff)
231
154
class cmd_visualise(Command):
232
155
"""Graphically visualise this branch.
240
163
takes_options = [
242
Option('limit', "Maximum number of revisions to display.",
165
Option('limit', "maximum number of revisions to display",
244
167
takes_args = [ "location?" ]
245
168
aliases = [ "visualize", "vis", "viz" ]
247
170
def run(self, location=".", revision=None, limit=None):
249
(br, path) = branch.Branch.open_containing(location)
172
(branch, path) = Branch.open_containing(location)
174
branch.repository.lock_read()
252
176
if revision is None:
253
revid = br.last_revision()
177
revid = branch.last_revision()
254
178
if revid is None:
257
(revno, revid) = revision[0].in_history(br)
181
(revno, revid) = revision[0].in_history(branch)
260
pp = start_viz_window(br, revid, limit)
261
pp.connect("destroy", lambda w: gtk.main_quit())
183
from viz.bzrkapp import BzrkApp
186
app.show(branch, revid, limit)
268
class cmd_gannotate(GTKCommand):
188
branch.repository.unlock()
193
register_command(cmd_visualise)
195
class cmd_gannotate(Command):
269
196
"""GTK+ annotate.
271
198
Browse changes to FILENAME line by line in a GTK+ window.
317
251
window.set_title(path + " - gannotate")
318
252
config = GAnnotateConfig(window)
324
window.annotate(tree, br, file_id)
325
window.jump_to_line(line)
256
window.annotate(tree, branch, file_id)
334
class cmd_gcommit(GTKCommand):
259
window.jump_to_line(line)
263
register_command(cmd_gannotate)
265
class cmd_gcommit(Command):
335
266
"""GTK+ commit dialog
337
268
Graphical user interface for committing revisions"""
341
271
takes_options = []
343
273
def run(self, filename=None):
346
from commit import CommitDialog
275
pygtk = import_pygtk()
279
except RuntimeError, e:
280
if str(e) == "could not open display":
284
from olive.commit import CommitDialog
285
from bzrlib.commit import Commit
347
286
from bzrlib.errors import (BzrCommandError,
354
(wt, path) = workingtree.WorkingTree.open_containing(filename)
296
(wt, path) = WorkingTree.open_containing(filename)
298
except NotBranchError, e:
356
300
except NoWorkingTree, e:
358
(br, path) = branch.Branch.open_containing(path)
360
commit = CommitDialog(wt, path, not br)
303
(branch, path) = Branch.open_containing(path)
304
except NotBranchError, e:
308
commit = CommitDialog(wt, path, not branch)
365
class cmd_gstatus(GTKCommand):
366
"""GTK+ status dialog
368
Graphical user interface for showing status
372
takes_args = ['PATH?']
375
def run(self, path='.'):
377
gtk = self.open_display()
378
from status import StatusDialog
379
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
380
status = StatusDialog(wt, wt_path)
381
status.connect("destroy", gtk.main_quit)
386
class cmd_gconflicts(GTKCommand):
389
Select files from the list of conflicts and run an external utility to
393
(wt, path) = workingtree.WorkingTree.open_containing('.')
395
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
396
dialog = ConflictsDialog(wt)
401
class cmd_gpreferences(GTKCommand):
402
""" GTK+ preferences dialog.
407
from bzrlib.plugins.gtk.preferences import PreferencesWindow
408
dialog = PreferencesWindow()
413
class cmd_gmissing(Command):
414
""" GTK+ missing revisions dialog.
417
takes_args = ["other_branch?"]
418
def run(self, other_branch=None):
419
pygtk = import_pygtk()
422
except RuntimeError, e:
423
if str(e) == "could not open display":
426
from bzrlib.plugins.gtk.missing import MissingWindow
427
from bzrlib.branch import Branch
429
local_branch = Branch.open_containing(".")[0]
430
if other_branch is None:
431
other_branch = local_branch.get_parent()
433
if other_branch is None:
434
raise errors.BzrCommandError("No peer location known or specified.")
435
remote_branch = Branch.open_containing(other_branch)[0]
437
local_branch.lock_read()
439
remote_branch.lock_read()
441
dialog = MissingWindow(local_branch, remote_branch)
444
remote_branch.unlock()
446
local_branch.unlock()
449
class cmd_ginit(GTKCommand):
452
from initialize import InitDialog
453
dialog = InitDialog(os.path.abspath(os.path.curdir))
457
class cmd_gtags(GTKCommand):
459
br = branch.Branch.open_containing('.')[0]
461
gtk = self.open_display()
462
from tags import TagsWindow
463
window = TagsWindow(br)
485
register_command(cmd)
488
class cmd_commit_notify(GTKCommand):
489
"""Run the bzr commit notifier.
491
This is a background program which will pop up a notification on the users
492
screen when a commit occurs.
496
from notify import NotifyPopupMenu
497
gtk = self.open_display()
498
menu = NotifyPopupMenu()
499
icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
500
icon.connect('popup-menu', menu.display)
506
from bzrlib.bzrdir import BzrDir
507
from bzrlib import errors
508
from bzrlib.osutils import format_date
509
from bzrlib.transport import get_transport
510
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
512
from bzrlib.plugins.dbus import activity
513
bus = dbus.SessionBus()
514
# get the object so we can subscribe to callbacks from it.
515
broadcast_service = bus.get_object(
516
activity.Broadcast.DBUS_NAME,
517
activity.Broadcast.DBUS_PATH)
519
def catch_branch(revision_id, urls):
520
# TODO: show all the urls, or perhaps choose the 'best'.
523
if isinstance(revision_id, unicode):
524
revision_id = revision_id.encode('utf8')
525
transport = get_transport(url)
526
a_dir = BzrDir.open_from_transport(transport)
527
branch = a_dir.open_branch()
528
revno = branch.revision_id_to_revno(revision_id)
529
revision = branch.repository.get_revision(revision_id)
530
summary = 'New revision %d in %s' % (revno, url)
531
body = 'Committer: %s\n' % revision.committer
532
body += 'Date: %s\n' % format_date(revision.timestamp,
535
body += revision.message
536
body = cgi.escape(body)
537
nw = pynotify.Notification(summary, body)
538
def start_viz(notification=None, action=None, data=None):
539
"""Start the viz program."""
540
pp = start_viz_window(branch, revision_id)
542
def start_branch(notification=None, action=None, data=None):
543
"""Start a Branch dialog"""
544
from bzrlib.plugins.gtk.branch import BranchDialog
545
bd = BranchDialog(remote_path=url)
547
nw.add_action("inspect", "Inspect", start_viz, None)
548
nw.add_action("branch", "Branch", start_branch, None)
554
broadcast_service.connect_to_signal("Revision", catch_branch,
555
dbus_interface=activity.Broadcast.DBUS_INTERFACE)
556
pynotify.init("bzr commit-notify")
559
register_command(cmd_commit_notify)
562
class cmd_gselftest(GTKCommand):
563
"""Version of selftest that displays a notification at the end"""
565
takes_args = builtins.cmd_selftest.takes_args
566
takes_options = builtins.cmd_selftest.takes_options
567
_see_also = ['selftest']
569
def run(self, *args, **kwargs):
572
default_encoding = sys.getdefaultencoding()
573
# prevent gtk from blowing up later
575
# prevent gtk from messing with default encoding
577
if sys.getdefaultencoding() != default_encoding:
579
sys.setdefaultencoding(default_encoding)
580
result = builtins.cmd_selftest().run(*args, **kwargs)
583
body = 'Selftest succeeded in "%s"' % os.getcwd()
586
body = 'Selftest failed in "%s"' % os.getcwd()
587
pynotify.init("bzr gselftest")
588
note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
589
note.set_timeout(pynotify.EXPIRES_NEVER)
593
register_command(cmd_gselftest)
597
gettext.install('olive-gtk')
311
register_command(cmd_gcommit)
600
313
class NoDisplayError(BzrCommandError):
601
314
"""gtk could not find a proper display"""