/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Jelmer Vernooij
  • Date: 2008-10-22 15:50:24 UTC
  • Revision ID: jelmer@samba.org-20081022155024-z0qt44qmiwxgjmr8
Hide notify icon when not notifying.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
"""Graphical support for Bazaar using GTK.
16
16
 
17
17
This plugin includes:
18
 
gannotate         GTK+ annotate.
19
 
gbranch           GTK+ branching.
20
 
gcheckout         GTK+ checkout.
 
18
gannotate         GTK+ annotate. 
 
19
gbranch           GTK+ branching. 
 
20
gcheckout         GTK+ checkout. 
21
21
gcommit           GTK+ commit dialog.
22
 
gconflicts        GTK+ conflicts.
23
 
gdiff             Show differences in working tree in a GTK+ Window.
 
22
gconflicts        GTK+ conflicts. 
 
23
gdiff             Show differences in working tree in a GTK+ Window. 
24
24
ginit             Initialise a new branch.
 
25
ginfo             GTK+ branch info dialog
25
26
gloom             GTK+ loom browse dialog
26
27
gmerge            GTK+ merge dialog
27
 
gmissing          GTK+ missing revisions dialog.
28
 
gpreferences      GTK+ preferences dialog.
 
28
gmissing          GTK+ missing revisions dialog. 
 
29
gpreferences      GTK+ preferences dialog. 
29
30
gpush             GTK+ push.
30
31
gsend             GTK+ send merge directive.
31
32
gstatus           GTK+ status dialog.
32
33
gtags             Manage branch tags.
33
 
visualise         Graphically visualise this branch.
 
34
visualise         Graphically visualise this branch. 
34
35
"""
35
36
 
36
 
from __future__ import absolute_import
37
 
 
38
 
import os
39
37
import sys
40
38
 
41
 
if getattr(sys, "frozen", None) is not None: # we run bzr.exe
42
 
 
43
 
    # FIXME: Unless a better packaging solution is found, the following
44
 
    # provides a workaround for https://bugs.launchpad.net/bzr/+bug/388790 Also
45
 
    # see https://code.edge.launchpad.net/~vila/bzr-gtk/388790-windows-setup
46
 
    # for more details about while it's needed.
47
 
 
48
 
    # NOTE: _lib must be ahead of bzrlib or sax.saxutils (in olive) fails
49
 
    here = os.path.dirname(__file__)
50
 
    sys.path.insert(0, os.path.join(here, '_lib'))
51
 
    sys.path.append(os.path.join(here, '_lib/gtk-2.0'))
52
 
 
53
 
 
54
39
import bzrlib
55
 
import bzrlib.api
56
 
from bzrlib.commands import plugin_cmds
57
40
 
58
 
from bzrlib.plugins.gtk.info import (
59
 
    bzr_plugin_version as version_info,
60
 
    bzr_compatible_versions,
61
 
    )
 
41
version_info = (0, 96, 0, 'dev', 1)
62
42
 
63
43
if version_info[3] == 'final':
64
44
    version_string = '%d.%d.%d' % version_info[:3]
66
46
    version_string = '%d.%d.%d%s%d' % version_info
67
47
__version__ = version_string
68
48
 
69
 
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
70
 
 
 
49
required_bzrlib = (1, 6)
 
50
 
 
51
def check_bzrlib_version(desired):
 
52
    """Check that bzrlib is compatible.
 
53
 
 
54
    If version is < bzr-gtk version, assume incompatible.
 
55
    """
 
56
    bzrlib_version = bzrlib.version_info[:2]
 
57
    try:
 
58
        from bzrlib.trace import warning
 
59
    except ImportError:
 
60
        # get the message out any way we can
 
61
        from warnings import warn as warning
 
62
    if bzrlib_version < desired:
 
63
        from bzrlib.errors import BzrError
 
64
        warning('Installed Bazaar version %s is too old to be used with bzr-gtk'
 
65
                ' %s.' % (bzrlib.__version__, __version__))
 
66
        raise BzrError('Version mismatch: %r, %r' % (version_info, bzrlib.version_info) )
 
67
 
 
68
 
 
69
if version_info[2] == "final":
 
70
    check_bzrlib_version(required_bzrlib)
 
71
 
 
72
from bzrlib.trace import warning
71
73
if __name__ != 'bzrlib.plugins.gtk':
72
 
    from bzrlib.trace import warning
73
74
    warning("Not running as bzrlib.plugins.gtk, things may break.")
74
75
 
 
76
from bzrlib.lazy_import import lazy_import
 
77
lazy_import(globals(), """
 
78
from bzrlib import (
 
79
    branch,
 
80
    builtins,
 
81
    errors,
 
82
    merge_directive,
 
83
    workingtree,
 
84
    )
 
85
""")
 
86
 
 
87
from bzrlib.commands import Command, register_command, display_command
 
88
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
 
89
from bzrlib.option import Option
 
90
 
 
91
import os.path
 
92
 
 
93
def import_pygtk():
 
94
    try:
 
95
        import pygtk
 
96
    except ImportError:
 
97
        raise errors.BzrCommandError("PyGTK not installed.")
 
98
    pygtk.require('2.0')
 
99
    return pygtk
 
100
 
75
101
 
76
102
def set_ui_factory():
77
 
    from bzrlib.plugins.gtk.ui import GtkUIFactory
 
103
    import_pygtk()
 
104
    from ui import GtkUIFactory
78
105
    import bzrlib.ui
79
106
    bzrlib.ui.ui_factory = GtkUIFactory()
80
107
 
97
124
    return data_path(os.path.join('icons', *args))
98
125
 
99
126
 
100
 
commands = {
101
 
    "gannotate": ["gblame", "gpraise"],
102
 
    "gbranch": [],
103
 
    "gcheckout": [],
104
 
    "gcommit": ["gci"],
105
 
    "gconflicts": [],
106
 
    "gdiff": [],
107
 
    "ginit": [],
108
 
    "gmerge": [],
109
 
    "gmissing": [],
110
 
    "gpreferences": [],
111
 
    "gpush": [],
112
 
    "gsend": [],
113
 
    "gstatus": ["gst"],
114
 
    "gtags": [],
115
 
    "visualise": ["visualize", "vis", "viz", 'glog'],
116
 
    }
 
127
def open_display():
 
128
    pygtk = import_pygtk()
 
129
    try:
 
130
        import gtk
 
131
    except RuntimeError, e:
 
132
        if str(e) == "could not open display":
 
133
            raise NoDisplayError
 
134
    set_ui_factory()
 
135
    return gtk
 
136
 
 
137
 
 
138
class GTKCommand(Command):
 
139
    """Abstract class providing GTK specific run commands."""
 
140
 
 
141
    def run(self):
 
142
        open_display()
 
143
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
 
144
        dialog.run()
 
145
 
 
146
 
 
147
class cmd_gbranch(GTKCommand):
 
148
    """GTK+ branching.
 
149
    
 
150
    """
 
151
 
 
152
    def get_gtk_dialog(self, path):
 
153
        from bzrlib.plugins.gtk.branch import BranchDialog
 
154
        return BranchDialog(path)
 
155
 
 
156
 
 
157
class cmd_gcheckout(GTKCommand):
 
158
    """ GTK+ checkout.
 
159
    
 
160
    """
 
161
    
 
162
    def get_gtk_dialog(self, path):
 
163
        from bzrlib.plugins.gtk.checkout import CheckoutDialog
 
164
        return CheckoutDialog(path)
 
165
 
 
166
 
 
167
 
 
168
class cmd_gpush(GTKCommand):
 
169
    """ GTK+ push.
 
170
    
 
171
    """
 
172
    takes_args = [ "location?" ]
 
173
 
 
174
    def run(self, location="."):
 
175
        (br, path) = branch.Branch.open_containing(location)
 
176
        open_display()
 
177
        from bzrlib.plugins.gtk.push import PushDialog
 
178
        dialog = PushDialog(br.repository, br.last_revision(), br)
 
179
        dialog.run()
 
180
 
 
181
 
 
182
class cmd_gloom(GTKCommand):
 
183
    """ GTK+ loom.
 
184
    
 
185
    """
 
186
    takes_args = [ "location?" ]
 
187
 
 
188
    def run(self, location="."):
 
189
        try:
 
190
            (tree, path) = workingtree.WorkingTree.open_containing(location)
 
191
            br = tree.branch
 
192
        except NoWorkingTree, e:
 
193
            (br, path) = branch.Branch.open_containing(location)
 
194
            tree = None
 
195
        open_display()
 
196
        from bzrlib.plugins.gtk.loom import LoomDialog
 
197
        dialog = LoomDialog(br, tree)
 
198
        dialog.run()
 
199
 
 
200
 
 
201
class cmd_gdiff(GTKCommand):
 
202
    """Show differences in working tree in a GTK+ Window.
 
203
    
 
204
    Otherwise, all changes for the tree are listed.
 
205
    """
 
206
    takes_args = ['filename?']
 
207
    takes_options = ['revision']
 
208
 
 
209
    @display_command
 
210
    def run(self, revision=None, filename=None):
 
211
        set_ui_factory()
 
212
        wt = workingtree.WorkingTree.open_containing(".")[0]
 
213
        wt.lock_read()
 
214
        try:
 
215
            branch = wt.branch
 
216
            if revision is not None:
 
217
                if len(revision) == 1:
 
218
                    tree1 = wt
 
219
                    revision_id = revision[0].as_revision_id(tree1.branch)
 
220
                    tree2 = branch.repository.revision_tree(revision_id)
 
221
                elif len(revision) == 2:
 
222
                    revision_id_0 = revision[0].as_revision_id(branch)
 
223
                    tree2 = branch.repository.revision_tree(revision_id_0)
 
224
                    revision_id_1 = revision[1].as_revision_id(branch)
 
225
                    tree1 = branch.repository.revision_tree(revision_id_1)
 
226
            else:
 
227
                tree1 = wt
 
228
                tree2 = tree1.basis_tree()
 
229
 
 
230
            from diff import DiffWindow
 
231
            import gtk
 
232
            window = DiffWindow()
 
233
            window.connect("destroy", gtk.main_quit)
 
234
            window.set_diff("Working Tree", tree1, tree2)
 
235
            if filename is not None:
 
236
                tree_filename = wt.relpath(filename)
 
237
                try:
 
238
                    window.set_file(tree_filename)
 
239
                except NoSuchFile:
 
240
                    if (tree1.path2id(tree_filename) is None and 
 
241
                        tree2.path2id(tree_filename) is None):
 
242
                        raise NotVersionedError(filename)
 
243
                    raise BzrCommandError('No changes found for file "%s"' % 
 
244
                                          filename)
 
245
            window.show()
 
246
 
 
247
            gtk.main()
 
248
        finally:
 
249
            wt.unlock()
 
250
 
 
251
 
 
252
def start_viz_window(branch, revisions, limit=None):
 
253
    """Start viz on branch with revision revision.
 
254
    
 
255
    :return: The viz window object.
 
256
    """
 
257
    from bzrlib.plugins.gtk.viz import BranchWindow
 
258
    return BranchWindow(branch, revisions, limit)
 
259
 
 
260
 
 
261
class cmd_visualise(Command):
 
262
    """Graphically visualise this branch.
 
263
 
 
264
    Opens a graphical window to allow you to see the history of the branch
 
265
    and relationships between revisions in a visual manner,
 
266
 
 
267
    The default starting point is latest revision on the branch, you can
 
268
    specify a starting point with -r revision.
 
269
    """
 
270
    takes_options = [
 
271
        "revision",
 
272
        Option('limit', "Maximum number of revisions to display.",
 
273
               int, 'count')]
 
274
    takes_args = [ "locations*" ]
 
275
    aliases = [ "visualize", "vis", "viz" ]
 
276
 
 
277
    def run(self, locations_list, revision=None, limit=None):
 
278
        set_ui_factory()
 
279
        if locations_list is None:
 
280
            locations_list = ["."]
 
281
        revids = []
 
282
        for location in locations_list:
 
283
            (br, path) = branch.Branch.open_containing(location)
 
284
            if revision is None:
 
285
                revids.append(br.last_revision())
 
286
            else:
 
287
                revids.append(revision[0].as_revision_id(br))
 
288
        import gtk
 
289
        pp = start_viz_window(br, revids, limit)
 
290
        pp.connect("destroy", lambda w: gtk.main_quit())
 
291
        pp.show()
 
292
        gtk.main()
 
293
 
 
294
 
 
295
class cmd_gannotate(GTKCommand):
 
296
    """GTK+ annotate.
 
297
    
 
298
    Browse changes to FILENAME line by line in a GTK+ window.
 
299
    """
 
300
 
 
301
    takes_args = ["filename", "line?"]
 
302
    takes_options = [
 
303
        Option("all", help="Show annotations on all lines."),
 
304
        Option("plain", help="Don't highlight annotation lines."),
 
305
        Option("line", type=int, argname="lineno",
 
306
               help="Jump to specified line number."),
 
307
        "revision",
 
308
    ]
 
309
    aliases = ["gblame", "gpraise"]
 
310
    
 
311
    def run(self, filename, all=False, plain=False, line='1', revision=None):
 
312
        gtk = open_display()
 
313
 
 
314
        try:
 
315
            line = int(line)
 
316
        except ValueError:
 
317
            raise BzrCommandError('Line argument ("%s") is not a number.' % 
 
318
                                  line)
 
319
 
 
320
        from annotate.gannotate import GAnnotateWindow
 
321
        from annotate.config import GAnnotateConfig
 
322
        from bzrlib.bzrdir import BzrDir
 
323
 
 
324
        wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
 
325
        if wt is not None:
 
326
            tree = wt
 
327
        else:
 
328
            tree = br.basis_tree()
 
329
 
 
330
        file_id = tree.path2id(path)
 
331
 
 
332
        if file_id is None:
 
333
            raise NotVersionedError(filename)
 
334
        if revision is not None:
 
335
            if len(revision) != 1:
 
336
                raise BzrCommandError("Only 1 revion may be specified.")
 
337
            revision_id = revision[0].as_revision_id(br)
 
338
            tree = br.repository.revision_tree(revision_id)
 
339
        else:
 
340
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
 
341
 
 
342
        window = GAnnotateWindow(all, plain, branch=br)
 
343
        window.connect("destroy", lambda w: gtk.main_quit())
 
344
        config = GAnnotateConfig(window)
 
345
        window.show()
 
346
        br.lock_read()
 
347
        if wt is not None:
 
348
            wt.lock_read()
 
349
        try:
 
350
            window.annotate(tree, br, file_id)
 
351
            window.jump_to_line(line)
 
352
            gtk.main()
 
353
        finally:
 
354
            br.unlock()
 
355
            if wt is not None:
 
356
                wt.unlock()
 
357
 
 
358
 
 
359
 
 
360
class cmd_gcommit(GTKCommand):
 
361
    """GTK+ commit dialog
 
362
 
 
363
    Graphical user interface for committing revisions"""
 
364
 
 
365
    aliases = [ "gci" ]
 
366
    takes_args = []
 
367
    takes_options = []
 
368
 
 
369
    def run(self, filename=None):
 
370
        import os
 
371
        open_display()
 
372
        from commit import CommitDialog
 
373
        from bzrlib.errors import (BzrCommandError,
 
374
                                   NotBranchError,
 
375
                                   NoWorkingTree)
 
376
 
 
377
        wt = None
 
378
        br = None
 
379
        try:
 
380
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
 
381
            br = wt.branch
 
382
        except NoWorkingTree, e:
 
383
            from dialog import error_dialog
 
384
            error_dialog(_i18n('Directory does not have a working tree'),
 
385
                         _i18n('Operation aborted.'))
 
386
            return 1 # should this be retval=3?
 
387
 
 
388
        # It is a good habit to keep things locked for the duration, but it
 
389
        # could cause difficulties if someone wants to do things in another
 
390
        # window... We could lock_read() until we actually go to commit
 
391
        # changes... Just a thought.
 
392
        wt.lock_write()
 
393
        try:
 
394
            dlg = CommitDialog(wt)
 
395
            return dlg.run()
 
396
        finally:
 
397
            wt.unlock()
 
398
 
 
399
 
 
400
class cmd_gstatus(GTKCommand):
 
401
    """GTK+ status dialog
 
402
 
 
403
    Graphical user interface for showing status 
 
404
    information."""
 
405
    
 
406
    aliases = [ "gst" ]
 
407
    takes_args = ['PATH?']
 
408
    takes_options = ['revision']
 
409
 
 
410
    def run(self, path='.', revision=None):
 
411
        import os
 
412
        gtk = open_display()
 
413
        from status import StatusDialog
 
414
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
 
415
        
 
416
        if revision is not None:
 
417
            try:
 
418
                revision_id = revision[0].as_revision_id(wt.branch)
 
419
            except:
 
420
                from bzrlib.errors import BzrError
 
421
                raise BzrError('Revision %r doesn\'t exist' % revision[0].user_spec )
 
422
        else:
 
423
            revision_id = None
 
424
 
 
425
        status = StatusDialog(wt, wt_path, revision_id)
 
426
        status.connect("destroy", gtk.main_quit)
 
427
        status.run()
 
428
 
 
429
 
 
430
class cmd_gsend(GTKCommand):
 
431
    """GTK+ send merge directive.
 
432
 
 
433
    """
 
434
    def run(self):
 
435
        (br, path) = branch.Branch.open_containing(".")
 
436
        gtk = open_display()
 
437
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
 
438
        from StringIO import StringIO
 
439
        dialog = SendMergeDirectiveDialog(br)
 
440
        if dialog.run() == gtk.RESPONSE_OK:
 
441
            outf = StringIO()
 
442
            outf.writelines(dialog.get_merge_directive().to_lines())
 
443
            mail_client = br.get_config().get_mail_client()
 
444
            mail_client.compose_merge_request(dialog.get_mail_to(), "[MERGE]", 
 
445
                outf.getvalue())
 
446
 
 
447
            
 
448
 
 
449
 
 
450
class cmd_gconflicts(GTKCommand):
 
451
    """GTK+ conflicts.
 
452
    
 
453
    Select files from the list of conflicts and run an external utility to
 
454
    resolve them.
 
455
    """
 
456
    def run(self):
 
457
        (wt, path) = workingtree.WorkingTree.open_containing('.')
 
458
        open_display()
 
459
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
 
460
        dialog = ConflictsDialog(wt)
 
461
        dialog.run()
 
462
 
 
463
 
 
464
class cmd_gpreferences(GTKCommand):
 
465
    """ GTK+ preferences dialog.
 
466
 
 
467
    """
 
468
    def run(self):
 
469
        open_display()
 
470
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
 
471
        dialog = PreferencesWindow()
 
472
        dialog.run()
 
473
 
 
474
 
 
475
class cmd_ginfo(Command):
 
476
    """ GTK+ info dialog
 
477
    
 
478
    """
 
479
    def run(self):
 
480
        from bzrlib import workingtree
 
481
        from bzrlib.plugins.gtk.olive.info import InfoDialog
 
482
        wt = workingtree.WorkingTree.open_containing('.')[0]
 
483
        info = InfoDialog(wt.branch)
 
484
        info.display()
 
485
        info.window.run()
 
486
 
 
487
 
 
488
class cmd_gmerge(Command):
 
489
    """ GTK+ merge dialog
 
490
    
 
491
    """
 
492
    takes_args = ["merge_from_path?"]
 
493
    def run(self, merge_from_path=None):
 
494
        from bzrlib import workingtree
 
495
        from bzrlib.plugins.gtk.dialog import error_dialog
 
496
        from bzrlib.plugins.gtk.merge import MergeDialog
 
497
        
 
498
        (wt, path) = workingtree.WorkingTree.open_containing('.')
 
499
        old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
 
500
        delta = wt.changes_from(old_tree)
 
501
        if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
 
502
            error_dialog(_i18n('There are local changes in the branch'),
 
503
                         _i18n('Please commit or revert the changes before merging.'))
 
504
        else:
 
505
            parent_branch_path = wt.branch.get_parent()
 
506
            merge = MergeDialog(wt, path, parent_branch_path)
 
507
            response = merge.run()
 
508
            merge.destroy()
 
509
 
 
510
 
 
511
class cmd_gmissing(Command):
 
512
    """ GTK+ missing revisions dialog.
 
513
 
 
514
    """
 
515
    takes_args = ["other_branch?"]
 
516
    def run(self, other_branch=None):
 
517
        pygtk = import_pygtk()
 
518
        try:
 
519
            import gtk
 
520
        except RuntimeError, e:
 
521
            if str(e) == "could not open display":
 
522
                raise NoDisplayError
 
523
 
 
524
        from bzrlib.plugins.gtk.missing import MissingWindow
 
525
        from bzrlib.branch import Branch
 
526
 
 
527
        local_branch = Branch.open_containing(".")[0]
 
528
        if other_branch is None:
 
529
            other_branch = local_branch.get_parent()
 
530
            
 
531
            if other_branch is None:
 
532
                raise errors.BzrCommandError("No peer location known or specified.")
 
533
        remote_branch = Branch.open_containing(other_branch)[0]
 
534
        set_ui_factory()
 
535
        local_branch.lock_read()
 
536
        try:
 
537
            remote_branch.lock_read()
 
538
            try:
 
539
                dialog = MissingWindow(local_branch, remote_branch)
 
540
                dialog.run()
 
541
            finally:
 
542
                remote_branch.unlock()
 
543
        finally:
 
544
            local_branch.unlock()
 
545
 
 
546
 
 
547
class cmd_ginit(GTKCommand):
 
548
    def run(self):
 
549
        open_display()
 
550
        from initialize import InitDialog
 
551
        dialog = InitDialog(os.path.abspath(os.path.curdir))
 
552
        dialog.run()
 
553
 
 
554
 
 
555
class cmd_gtags(GTKCommand):
 
556
    def run(self):
 
557
        br = branch.Branch.open_containing('.')[0]
 
558
        
 
559
        gtk = open_display()
 
560
        from tags import TagsWindow
 
561
        window = TagsWindow(br)
 
562
        window.show()
 
563
        gtk.main()
 
564
 
 
565
 
 
566
commands = [
 
567
    cmd_gannotate, 
 
568
    cmd_gbranch,
 
569
    cmd_gcheckout, 
 
570
    cmd_gcommit, 
 
571
    cmd_gconflicts, 
 
572
    cmd_gdiff,
 
573
    cmd_ginit,
 
574
    cmd_ginfo,
 
575
    cmd_gmerge,
 
576
    cmd_gmissing, 
 
577
    cmd_gpreferences, 
 
578
    cmd_gpush, 
 
579
    cmd_gsend,
 
580
    cmd_gstatus,
 
581
    cmd_gtags,
 
582
    cmd_visualise
 
583
    ]
117
584
 
118
585
try:
119
586
    from bzrlib.plugins import loom
120
587
except ImportError:
121
588
    pass # Loom plugin doesn't appear to be present
122
589
else:
123
 
    commands["gloom"] = []
124
 
 
125
 
for cmd, aliases in commands.iteritems():
126
 
    plugin_cmds.register_lazy("cmd_%s" % cmd, aliases,
127
 
                              "bzrlib.plugins.gtk.commands")
128
 
 
129
 
def save_commit_messages(*args):
130
 
    from bzrlib.plugins.gtk import commitmsgs
131
 
    commitmsgs.save_commit_messages(*args)
132
 
 
133
 
try:
134
 
    from bzrlib.hooks import install_lazy_named_hook
135
 
except ImportError:
136
 
    from bzrlib.branch import Branch
137
 
    Branch.hooks.install_named_hook('post_uncommit',
138
 
                                    save_commit_messages,
139
 
                                    "Saving commit messages for gcommit")
140
 
else:
141
 
    install_lazy_named_hook("bzrlib.branch", "Branch.hooks",
142
 
        'post_uncommit', save_commit_messages, "Saving commit messages for gcommit")
143
 
 
144
 
try:
145
 
    from bzrlib.registry import register_lazy
146
 
except ImportError:
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')
152
 
else:
153
 
    register_lazy("bzrlib.config", "option_registry",
154
 
        'nautilus_integration', 'bzrlib.plugins.gtk.config',
155
 
        'opt_nautilus_integration')
156
 
 
157
 
 
158
 
def load_tests(basic_tests, module, loader):
159
 
    testmod_names = [
160
 
        'tests',
161
 
        ]
 
590
    commands.append(cmd_gloom)
 
591
 
 
592
for cmd in commands:
 
593
    register_command(cmd)
 
594
 
 
595
 
 
596
class cmd_gselftest(GTKCommand):
 
597
    """Version of selftest that displays a notification at the end"""
 
598
 
 
599
    takes_args = builtins.cmd_selftest.takes_args
 
600
    takes_options = builtins.cmd_selftest.takes_options
 
601
    _see_also = ['selftest']
 
602
 
 
603
    def run(self, *args, **kwargs):
 
604
        import cgi
 
605
        import sys
 
606
        default_encoding = sys.getdefaultencoding()
 
607
        # prevent gtk from blowing up later
 
608
        gtk = import_pygtk()
 
609
        # prevent gtk from messing with default encoding
 
610
        import pynotify
 
611
        if sys.getdefaultencoding() != default_encoding:
 
612
            reload(sys)
 
613
            sys.setdefaultencoding(default_encoding)
 
614
        result = builtins.cmd_selftest().run(*args, **kwargs)
 
615
        if result == 0:
 
616
            summary = 'Success'
 
617
            body = 'Selftest succeeded in "%s"' % os.getcwd()
 
618
        if result == 1:
 
619
            summary = 'Failure'
 
620
            body = 'Selftest failed in "%s"' % os.getcwd()
 
621
        pynotify.init("bzr gselftest")
 
622
        note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
 
623
        note.set_timeout(pynotify.EXPIRES_NEVER)
 
624
        note.show()
 
625
 
 
626
 
 
627
register_command(cmd_gselftest)
 
628
 
 
629
 
 
630
import gettext
 
631
gettext.install('olive-gtk')
 
632
 
 
633
# Let's create a specialized alias to protect '_' from being erased by other
 
634
# uses of '_' as an anonymous variable (think pdb for one).
 
635
_i18n = gettext.gettext
 
636
 
 
637
class NoDisplayError(BzrCommandError):
 
638
    """gtk could not find a proper display"""
 
639
 
 
640
    def __str__(self):
 
641
        return "No DISPLAY. Unable to run GTK+ application."
 
642
 
 
643
 
 
644
def test_suite():
 
645
    from unittest import TestSuite
 
646
    import tests
162
647
    import sys
163
648
    default_encoding = sys.getdefaultencoding()
164
649
    try:
165
 
        result = basic_tests
 
650
        result = TestSuite()
166
651
        try:
167
 
            import gi.repository.Gtk
168
 
        except ImportError:
169
 
            return basic_tests
170
 
        basic_tests.addTest(loader.loadTestsFromModuleNames(
171
 
                ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
 
652
            import_pygtk()
 
653
        except errors.BzrCommandError:
 
654
            return result
 
655
        result.addTest(tests.test_suite())
172
656
    finally:
173
657
        if sys.getdefaultencoding() != default_encoding:
174
658
            reload(sys)
175
659
            sys.setdefaultencoding(default_encoding)
176
 
    return basic_tests
177
 
 
 
660
    return result