44
44
version_string = '%d.%d.%d%s%d' % version_info
45
45
__version__ = version_string
47
required_bzrlib = (1, 3)
49
47
def check_bzrlib_version(desired):
50
48
"""Check that bzrlib is compatible.
52
50
If version is < bzr-gtk version, assume incompatible.
51
If version == bzr-gtk version, assume completely compatible
52
If version == bzr-gtk version + 1, assume compatible, with deprecations
53
Otherwise, assume incompatible.
55
desired_plus = (desired[0], desired[1]+1)
54
56
bzrlib_version = bzrlib.version_info[:2]
57
if bzrlib_version == desired or (bzrlib_version == desired_plus and
58
bzrlib.version_info[3] == 'dev'):
56
61
from bzrlib.trace import warning
57
62
except ImportError:
62
67
warning('Installed Bazaar version %s is too old to be used with bzr-gtk'
63
68
' %s.' % (bzrlib.__version__, __version__))
64
69
raise BzrError('Version mismatch: %r, %r' % (version_info, bzrlib.version_info) )
71
warning('bzr-gtk is not up to date with installed bzr version %s.'
72
' \nThere should be a newer version available, e.g. %i.%i.'
73
% (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
67
76
if version_info[2] == "final":
68
check_bzrlib_version(required_bzrlib)
77
check_bzrlib_version(version_info[:2])
70
79
from bzrlib.trace import warning
71
80
if __name__ != 'bzrlib.plugins.gtk':
104
112
bzrlib.ui.ui_factory = GtkUIFactory()
108
return [os.path.dirname(__file__),
109
"/usr/share/bzr-gtk",
110
"/usr/local/share/bzr-gtk"]
113
def data_path(*args):
114
for basedir in data_basedirs():
115
path = os.path.join(basedir, *args)
116
if os.path.exists(path):
121
def icon_path(*args):
122
return data_path(os.path.join('icons', *args))
126
pygtk = import_pygtk()
129
except RuntimeError, e:
130
if str(e) == "could not open display":
116
return os.path.dirname(__file__)
136
119
class GTKCommand(Command):
137
120
"""Abstract class providing GTK specific run commands."""
122
def open_display(self):
123
pygtk = import_pygtk()
126
except RuntimeError, e:
127
if str(e) == "could not open display":
141
134
dialog = self.get_gtk_dialog(os.path.abspath('.'))
196
189
if revision is not None:
197
190
if len(revision) == 1:
199
revision_id = revision[0].as_revision_id(tree1.branch)
192
revision_id = revision[0].in_history(branch).rev_id
200
193
tree2 = branch.repository.revision_tree(revision_id)
201
194
elif len(revision) == 2:
202
revision_id_0 = revision[0].as_revision_id(branch)
195
revision_id_0 = revision[0].in_history(branch).rev_id
203
196
tree2 = branch.repository.revision_tree(revision_id_0)
204
revision_id_1 = revision[1].as_revision_id(branch)
197
revision_id_1 = revision[1].in_history(branch).rev_id
205
198
tree1 = branch.repository.revision_tree(revision_id_1)
232
def start_viz_window(branch, revisions, limit=None):
225
def start_viz_window(branch, revision, limit=None):
233
226
"""Start viz on branch with revision revision.
235
228
:return: The viz window object.
237
from viz import BranchWindow
238
return BranchWindow(branch, revisions, limit)
230
from viz.branchwin import BranchWindow
231
return BranchWindow(branch, revision, limit)
241
234
class cmd_visualise(Command):
252
245
Option('limit', "Maximum number of revisions to display.",
254
takes_args = [ "locations*" ]
247
takes_args = [ "location?" ]
255
248
aliases = [ "visualize", "vis", "viz" ]
257
def run(self, locations_list, revision=None, limit=None):
250
def run(self, location=".", revision=None, limit=None):
259
if locations_list is None:
260
locations_list = ["."]
262
for location in locations_list:
263
(br, path) = branch.Branch.open_containing(location)
265
revids.append(br.last_revision())
267
revids.append(revision[0].as_revision_id(br))
252
(br, path) = branch.Branch.open_containing(location)
254
revid = br.last_revision()
258
(revno, revid) = revision[0].in_history(br)
269
pp = start_viz_window(br, revids, limit)
261
pp = start_viz_window(br, revid, limit)
270
262
pp.connect("destroy", lambda w: gtk.main_quit())
314
306
if revision is not None:
315
307
if len(revision) != 1:
316
308
raise BzrCommandError("Only 1 revion may be specified.")
317
revision_id = revision[0].as_revision_id(br)
309
revision_id = revision[0].in_history(br).rev_id
318
310
tree = br.repository.revision_tree(revision_id)
320
312
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
322
window = GAnnotateWindow(all, plain, branch=br)
314
window = GAnnotateWindow(all, plain)
323
315
window.connect("destroy", lambda w: gtk.main_quit())
316
window.set_title(path + " - gannotate")
324
317
config = GAnnotateConfig(window)
386
379
aliases = [ "gst" ]
387
380
takes_args = ['PATH?']
388
takes_options = ['revision']
390
def run(self, path='.', revision=None):
383
def run(self, path='.'):
385
gtk = self.open_display()
393
386
from status import StatusDialog
394
387
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
396
if revision is not None:
398
revision_id = revision[0].as_revision_id(wt.branch)
400
from bzrlib.errors import BzrError
401
raise BzrError('Revision %r doesn\'t exist' % revision[0].user_spec )
405
status = StatusDialog(wt, wt_path, revision_id)
388
status = StatusDialog(wt, wt_path)
406
389
status.connect("destroy", gtk.main_quit)
450
433
from bzrlib.plugins.gtk.preferences import PreferencesWindow
451
434
dialog = PreferencesWindow()
455
class cmd_gmerge(Command):
456
""" GTK+ merge dialog
459
takes_args = ["merge_from_path?"]
460
def run(self, merge_from_path=None):
461
from bzrlib import workingtree
462
from bzrlib.plugins.gtk.dialog import error_dialog
463
from bzrlib.plugins.gtk.merge import MergeDialog
465
(wt, path) = workingtree.WorkingTree.open_containing('.')
466
old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
467
delta = wt.changes_from(old_tree)
468
if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
469
error_dialog(_i18n('There are local changes in the branch'),
470
_i18n('Please commit or revert the changes before merging.'))
472
parent_branch_path = wt.branch.get_parent()
473
merge = MergeDialog(wt, path, parent_branch_path)
474
response = merge.run()
478
438
class cmd_gmissing(Command):
479
439
""" GTK+ missing revisions dialog.
552
511
register_command(cmd)
514
class cmd_commit_notify(GTKCommand):
515
"""Run the bzr commit notifier.
517
This is a background program which will pop up a notification on the users
518
screen when a commit occurs.
522
from notify import NotifyPopupMenu
523
gtk = self.open_display()
524
menu = NotifyPopupMenu()
525
icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
526
icon.connect('popup-menu', menu.display)
532
from bzrlib.bzrdir import BzrDir
533
from bzrlib import errors
534
from bzrlib.osutils import format_date
535
from bzrlib.transport import get_transport
536
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
538
from bzrlib.plugins.dbus import activity
539
bus = dbus.SessionBus()
540
# get the object so we can subscribe to callbacks from it.
541
broadcast_service = bus.get_object(
542
activity.Broadcast.DBUS_NAME,
543
activity.Broadcast.DBUS_PATH)
545
def catch_branch(revision_id, urls):
546
# TODO: show all the urls, or perhaps choose the 'best'.
549
if isinstance(revision_id, unicode):
550
revision_id = revision_id.encode('utf8')
551
transport = get_transport(url)
552
a_dir = BzrDir.open_from_transport(transport)
553
branch = a_dir.open_branch()
554
revno = branch.revision_id_to_revno(revision_id)
555
revision = branch.repository.get_revision(revision_id)
556
summary = 'New revision %d in %s' % (revno, url)
557
body = 'Committer: %s\n' % revision.committer
558
body += 'Date: %s\n' % format_date(revision.timestamp,
561
body += revision.message
562
body = cgi.escape(body)
563
nw = pynotify.Notification(summary, body)
564
def start_viz(notification=None, action=None, data=None):
565
"""Start the viz program."""
566
pp = start_viz_window(branch, revision_id)
568
def start_branch(notification=None, action=None, data=None):
569
"""Start a Branch dialog"""
570
from bzrlib.plugins.gtk.branch import BranchDialog
571
bd = BranchDialog(remote_path=url)
573
nw.add_action("inspect", "Inspect", start_viz, None)
574
nw.add_action("branch", "Branch", start_branch, None)
580
broadcast_service.connect_to_signal("Revision", catch_branch,
581
dbus_interface=activity.Broadcast.DBUS_INTERFACE)
582
pynotify.init("bzr commit-notify")
585
register_command(cmd_commit_notify)
555
588
class cmd_gselftest(GTKCommand):
556
589
"""Version of selftest that displays a notification at the end"""