97
121
return data_path(os.path.join('icons', *args))
101
"gannotate": ["gblame", "gpraise"],
115
"visualise": ["visualize", "vis", "viz", 'glog'],
119
from bzrlib.plugins import loom
121
pass # Loom plugin doesn't appear to be present
123
commands["gloom"] = []
125
for cmd, aliases in commands.iteritems():
126
plugin_cmds.register_lazy("cmd_%s" % cmd, aliases,
127
"bzrlib.plugins.gtk.commands")
129
def save_commit_messages(*args):
130
from bzrlib.plugins.gtk import commitmsgs
131
commitmsgs.save_commit_messages(*args)
134
from bzrlib.hooks import install_lazy_named_hook
136
from bzrlib.branch import Branch
137
Branch.hooks.install_named_hook('post_uncommit',
138
save_commit_messages,
139
"Saving commit messages for gcommit")
141
install_lazy_named_hook("bzrlib.branch", "Branch.hooks",
142
'post_uncommit', save_commit_messages, "Saving commit messages for gcommit")
145
from bzrlib.registry import register_lazy
147
from bzrlib import config
148
option_registry = getattr(config, "option_registry", None)
149
if option_registry is not None:
150
config.option_registry.register_lazy('nautilus_integration',
151
'bzrlib.plugins.gtk.config', 'opt_nautilus_integration')
153
register_lazy("bzrlib.config", "option_registry",
154
'nautilus_integration', 'bzrlib.plugins.gtk.config',
155
'opt_nautilus_integration')
158
def load_tests(basic_tests, module, loader):
125
pygtk = import_pygtk()
128
except RuntimeError, e:
129
if str(e) == "could not open display":
135
class GTKCommand(Command):
136
"""Abstract class providing GTK specific run commands."""
140
dialog = self.get_gtk_dialog(os.path.abspath('.'))
144
class cmd_gbranch(GTKCommand):
149
def get_gtk_dialog(self, path):
150
from bzrlib.plugins.gtk.branch import BranchDialog
151
return BranchDialog(path)
154
class cmd_gcheckout(GTKCommand):
159
def get_gtk_dialog(self, path):
160
from bzrlib.plugins.gtk.checkout import CheckoutDialog
161
return CheckoutDialog(path)
165
class cmd_gpush(GTKCommand):
169
takes_args = [ "location?" ]
171
def run(self, location="."):
172
(br, path) = branch.Branch.open_containing(location)
174
from push import PushDialog
175
dialog = PushDialog(br.repository, br.last_revision(), br)
180
class cmd_gdiff(GTKCommand):
181
"""Show differences in working tree in a GTK+ Window.
183
Otherwise, all changes for the tree are listed.
185
takes_args = ['filename?']
186
takes_options = ['revision']
189
def run(self, revision=None, filename=None):
191
wt = workingtree.WorkingTree.open_containing(".")[0]
195
if revision is not None:
196
if len(revision) == 1:
198
revision_id = revision[0].as_revision_id(tree1.branch)
199
tree2 = branch.repository.revision_tree(revision_id)
200
elif len(revision) == 2:
201
revision_id_0 = revision[0].as_revision_id(branch)
202
tree2 = branch.repository.revision_tree(revision_id_0)
203
revision_id_1 = revision[1].as_revision_id(branch)
204
tree1 = branch.repository.revision_tree(revision_id_1)
207
tree2 = tree1.basis_tree()
209
from diff import DiffWindow
211
window = DiffWindow()
212
window.connect("destroy", gtk.main_quit)
213
window.set_diff("Working Tree", tree1, tree2)
214
if filename is not None:
215
tree_filename = wt.relpath(filename)
217
window.set_file(tree_filename)
219
if (tree1.path2id(tree_filename) is None and
220
tree2.path2id(tree_filename) is None):
221
raise NotVersionedError(filename)
222
raise BzrCommandError('No changes found for file "%s"' %
231
def start_viz_window(branch, revisions, limit=None):
232
"""Start viz on branch with revision revision.
234
:return: The viz window object.
236
from viz import BranchWindow
237
return BranchWindow(branch, revisions, limit)
240
class cmd_visualise(Command):
241
"""Graphically visualise this branch.
243
Opens a graphical window to allow you to see the history of the branch
244
and relationships between revisions in a visual manner,
246
The default starting point is latest revision on the branch, you can
247
specify a starting point with -r revision.
251
Option('limit', "Maximum number of revisions to display.",
253
takes_args = [ "locations*" ]
254
aliases = [ "visualize", "vis", "viz" ]
256
def run(self, locations_list, revision=None, limit=None):
258
if locations_list is None:
259
locations_list = ["."]
261
for location in locations_list:
262
(br, path) = branch.Branch.open_containing(location)
264
revids.append(br.last_revision())
266
revids.append(revision[0].as_revision_id(br))
268
pp = start_viz_window(br, revids, limit)
269
pp.connect("destroy", lambda w: gtk.main_quit())
274
class cmd_gannotate(GTKCommand):
277
Browse changes to FILENAME line by line in a GTK+ window.
280
takes_args = ["filename", "line?"]
282
Option("all", help="Show annotations on all lines."),
283
Option("plain", help="Don't highlight annotation lines."),
284
Option("line", type=int, argname="lineno",
285
help="Jump to specified line number."),
288
aliases = ["gblame", "gpraise"]
290
def run(self, filename, all=False, plain=False, line='1', revision=None):
296
raise BzrCommandError('Line argument ("%s") is not a number.' %
299
from annotate.gannotate import GAnnotateWindow
300
from annotate.config import GAnnotateConfig
301
from bzrlib.bzrdir import BzrDir
303
wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
307
tree = br.basis_tree()
309
file_id = tree.path2id(path)
312
raise NotVersionedError(filename)
313
if revision is not None:
314
if len(revision) != 1:
315
raise BzrCommandError("Only 1 revion may be specified.")
316
revision_id = revision[0].as_revision_id(br)
317
tree = br.repository.revision_tree(revision_id)
319
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
321
window = GAnnotateWindow(all, plain, branch=br)
322
window.connect("destroy", lambda w: gtk.main_quit())
323
config = GAnnotateConfig(window)
329
window.annotate(tree, br, file_id)
330
window.jump_to_line(line)
339
class cmd_gcommit(GTKCommand):
340
"""GTK+ commit dialog
342
Graphical user interface for committing revisions"""
348
def run(self, filename=None):
351
from commit import CommitDialog
352
from bzrlib.errors import (BzrCommandError,
359
(wt, path) = workingtree.WorkingTree.open_containing(filename)
361
except NoWorkingTree, e:
362
from dialog import error_dialog
363
error_dialog(_i18n('Directory does not have a working tree'),
364
_i18n('Operation aborted.'))
365
return 1 # should this be retval=3?
367
# It is a good habit to keep things locked for the duration, but it
368
# could cause difficulties if someone wants to do things in another
369
# window... We could lock_read() until we actually go to commit
370
# changes... Just a thought.
373
dlg = CommitDialog(wt)
379
class cmd_gstatus(GTKCommand):
380
"""GTK+ status dialog
382
Graphical user interface for showing status
386
takes_args = ['PATH?']
387
takes_options = ['revision']
389
def run(self, path='.', revision=None):
392
from status import StatusDialog
393
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
395
if revision is not None:
397
revision_id = revision[0].as_revision_id(wt.branch)
399
from bzrlib.errors import BzrError
400
raise BzrError('Revision %r doesn\'t exist' % revision[0].user_spec )
404
status = StatusDialog(wt, wt_path, revision_id)
405
status.connect("destroy", gtk.main_quit)
409
class cmd_gsend(GTKCommand):
410
"""GTK+ send merge directive.
414
(br, path) = branch.Branch.open_containing(".")
416
from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
417
from StringIO import StringIO
418
dialog = SendMergeDirectiveDialog(br)
419
if dialog.run() == gtk.RESPONSE_OK:
421
outf.writelines(dialog.get_merge_directive().to_lines())
422
mail_client = br.get_config().get_mail_client()
423
mail_client.compose_merge_request(dialog.get_mail_to(), "[MERGE]",
429
class cmd_gconflicts(GTKCommand):
432
Select files from the list of conflicts and run an external utility to
436
(wt, path) = workingtree.WorkingTree.open_containing('.')
438
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
439
dialog = ConflictsDialog(wt)
443
class cmd_gpreferences(GTKCommand):
444
""" GTK+ preferences dialog.
449
from bzrlib.plugins.gtk.preferences import PreferencesWindow
450
dialog = PreferencesWindow()
454
class cmd_gmissing(Command):
455
""" GTK+ missing revisions dialog.
458
takes_args = ["other_branch?"]
459
def run(self, other_branch=None):
460
pygtk = import_pygtk()
463
except RuntimeError, e:
464
if str(e) == "could not open display":
467
from bzrlib.plugins.gtk.missing import MissingWindow
468
from bzrlib.branch import Branch
470
local_branch = Branch.open_containing(".")[0]
471
if other_branch is None:
472
other_branch = local_branch.get_parent()
474
if other_branch is None:
475
raise errors.BzrCommandError("No peer location known or specified.")
476
remote_branch = Branch.open_containing(other_branch)[0]
478
local_branch.lock_read()
480
remote_branch.lock_read()
482
dialog = MissingWindow(local_branch, remote_branch)
485
remote_branch.unlock()
487
local_branch.unlock()
490
class cmd_ginit(GTKCommand):
493
from initialize import InitDialog
494
dialog = InitDialog(os.path.abspath(os.path.curdir))
498
class cmd_gtags(GTKCommand):
500
br = branch.Branch.open_containing('.')[0]
503
from tags import TagsWindow
504
window = TagsWindow(br)
527
register_command(cmd)
530
class cmd_gselftest(GTKCommand):
531
"""Version of selftest that displays a notification at the end"""
533
takes_args = builtins.cmd_selftest.takes_args
534
takes_options = builtins.cmd_selftest.takes_options
535
_see_also = ['selftest']
537
def run(self, *args, **kwargs):
540
default_encoding = sys.getdefaultencoding()
541
# prevent gtk from blowing up later
543
# prevent gtk from messing with default encoding
545
if sys.getdefaultencoding() != default_encoding:
547
sys.setdefaultencoding(default_encoding)
548
result = builtins.cmd_selftest().run(*args, **kwargs)
551
body = 'Selftest succeeded in "%s"' % os.getcwd()
554
body = 'Selftest failed in "%s"' % os.getcwd()
555
pynotify.init("bzr gselftest")
556
note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
557
note.set_timeout(pynotify.EXPIRES_NEVER)
561
register_command(cmd_gselftest)
564
class cmd_test_gtk(GTKCommand):
565
"""Version of selftest that just runs the gtk test suite."""
567
takes_options = ['verbose',
568
Option('one', short_name='1',
569
help='Stop when one test fails.'),
570
Option('benchmark', help='Run the benchmarks.'),
571
Option('lsprof-timed',
572
help='Generate lsprof output for benchmarked'
573
' sections of code.'),
575
help='List the tests instead of running them.'),
576
Option('randomize', type=str, argname="SEED",
577
help='Randomize the order of tests using the given'
578
' seed or "now" for the current time.'),
580
takes_args = ['testspecs*']
582
def run(self, verbose=None, one=False, benchmark=None,
583
lsprof_timed=None, list_only=False, randomize=None,
584
testspecs_list=None):
585
from bzrlib import __path__ as bzrlib_path
586
from bzrlib.tests import selftest
588
print '%10s: %s' % ('bzrlib', bzrlib_path[0])
590
print 'No benchmarks yet'
593
test_suite_factory = bench_suite
596
# TODO: should possibly lock the history file...
597
benchfile = open(".perf_history", "at", buffering=1)
599
test_suite_factory = test_suite
604
if testspecs_list is not None:
605
pattern = '|'.join(testspecs_list)
610
result = selftest(verbose=verbose,
613
test_suite_factory=test_suite_factory,
614
lsprof_timed=lsprof_timed,
615
bench_history=benchfile,
617
random_seed=randomize,
620
if benchfile is not None:
623
register_command(cmd_test_gtk)
628
gettext.install('olive-gtk')
630
# Let's create a specialized alias to protect '_' from being erased by other
631
# uses of '_' as an anonymous variable (think pdb for one).
632
_i18n = gettext.gettext
634
class NoDisplayError(BzrCommandError):
635
"""gtk could not find a proper display"""
638
return "No DISPLAY. Unable to run GTK+ application."
642
from unittest import TestSuite
163
645
default_encoding = sys.getdefaultencoding()
167
import gi.repository.Gtk
170
basic_tests.addTest(loader.loadTestsFromModuleNames(
171
["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
650
except errors.BzrCommandError:
652
result.addTest(tests.test_suite())
173
654
if sys.getdefaultencoding() != default_encoding:
175
656
sys.setdefaultencoding(default_encoding)