/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: 2007-07-15 18:12:57 UTC
  • Revision ID: jelmer@samba.org-20070715181257-g264qus2zyi3v39z
Add RevisionSelectionBox widget, use in TagDialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
#
1
3
# This program is free software; you can redistribute it and/or modify
2
4
# it under the terms of the GNU General Public License as published by
3
5
# the Free Software Foundation; either version 2 of the License, or
12
14
# along with this program; if not, write to the Free Software
13
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
16
 
15
 
"""GTK+ frontends to Bazaar commands """
 
17
"""Graphical support for Bazaar using GTK.
 
18
 
 
19
This plugin includes:
 
20
commit-notify     Start the graphical notifier of commits.
 
21
gannotate         GTK+ annotate. 
 
22
gbranch           GTK+ branching. 
 
23
gcheckout         GTK+ checkout. 
 
24
gcommit           GTK+ commit dialog 
 
25
gconflicts        GTK+ push. 
 
26
gdiff             Show differences in working tree in a GTK+ Window. 
 
27
ginit             Initialise a new branch.
 
28
gmissing          GTK+ missing revisions dialog. 
 
29
gpreferences      GTK+ preferences dialog. 
 
30
gpush             GTK+ push. 
 
31
gstatus           GTK+ status dialog 
 
32
gtags             Manage branch tags.
 
33
visualise         Graphically visualise this branch. 
 
34
"""
16
35
 
17
36
import bzrlib
18
37
 
19
 
__version__ = '0.15.0'
 
38
__version__ = '0.18.0'
20
39
version_info = tuple(int(n) for n in __version__.split('.'))
21
40
 
22
41
 
30
49
    """
31
50
    desired_plus = (desired[0], desired[1]+1)
32
51
    bzrlib_version = bzrlib.version_info[:2]
33
 
    if bzrlib_version == desired:
 
52
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
 
53
                                     bzrlib.version_info[3] == 'dev'):
34
54
        return
35
55
    try:
36
56
        from bzrlib.trace import warning
38
58
        # get the message out any way we can
39
59
        from warnings import warn as warning
40
60
    if bzrlib_version < desired:
 
61
        from bzrlib.errors import BzrError
41
62
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
42
63
                ' %s.' % (bzrlib.__version__, __version__))
43
 
        # Not using BzrNewError, because it may not exist.
44
 
        raise Exception, ('Version mismatch', version_info)
 
64
        raise BzrError('Version mismatch: %r' % version_info)
45
65
    else:
46
66
        warning('bzr-gtk is not up to date with installed bzr version %s.'
47
67
                ' \nThere should be a newer version available, e.g. %i.%i.' 
48
68
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
49
 
        if bzrlib_version != desired_plus:
50
 
            raise Exception, 'Version mismatch'
51
69
 
52
70
 
53
71
check_bzrlib_version(version_info[:2])
56
74
if __name__ != 'bzrlib.plugins.gtk':
57
75
    warning("Not running as bzrlib.plugins.gtk, things may break.")
58
76
 
59
 
from bzrlib import errors
 
77
from bzrlib.lazy_import import lazy_import
 
78
lazy_import(globals(), """
 
79
from bzrlib import (
 
80
    branch,
 
81
    errors,
 
82
    workingtree,
 
83
    )
 
84
""")
 
85
 
60
86
from bzrlib.commands import Command, register_command, display_command
61
87
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
62
 
from bzrlib.commands import Command, register_command
63
88
from bzrlib.option import Option
64
 
from bzrlib.branch import Branch
65
 
from bzrlib.workingtree import WorkingTree
66
 
from bzrlib.bzrdir import BzrDir
67
89
 
68
90
import os.path
69
91
 
77
99
 
78
100
 
79
101
def set_ui_factory():
80
 
    pygtk = import_pygtk()
 
102
    import_pygtk()
81
103
    from ui import GtkUIFactory
82
104
    import bzrlib.ui
83
105
    bzrlib.ui.ui_factory = GtkUIFactory()
84
106
 
85
107
 
86
 
class cmd_gbranch(Command):
 
108
class GTKCommand(Command):
 
109
    """Abstract class providing GTK specific run commands."""
 
110
 
 
111
    def open_display(self):
 
112
        pygtk = import_pygtk()
 
113
        try:
 
114
            import gtk
 
115
        except RuntimeError, e:
 
116
            if str(e) == "could not open display":
 
117
                raise NoDisplayError
 
118
        set_ui_factory()
 
119
        return gtk
 
120
 
 
121
    def run(self):
 
122
        self.open_display()
 
123
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
 
124
        dialog.run()
 
125
 
 
126
 
 
127
class cmd_gbranch(GTKCommand):
87
128
    """GTK+ branching.
88
129
    
89
130
    """
90
131
 
91
 
    def run(self):
92
 
        pygtk = import_pygtk()
93
 
        try:
94
 
            import gtk
95
 
        except RuntimeError, e:
96
 
            if str(e) == "could not open display":
97
 
                raise NoDisplayError
98
 
 
 
132
    def get_gtk_dialog(self, path):
99
133
        from bzrlib.plugins.gtk.branch import BranchDialog
100
 
 
101
 
        set_ui_factory()
102
 
        dialog = BranchDialog(os.path.abspath('.'))
103
 
        dialog.run()
104
 
 
105
 
register_command(cmd_gbranch)
106
 
 
107
 
class cmd_gcheckout(Command):
 
134
        return BranchDialog(path)
 
135
 
 
136
 
 
137
class cmd_gcheckout(GTKCommand):
108
138
    """ GTK+ checkout.
109
139
    
110
140
    """
111
141
    
112
 
    def run(self):
113
 
        pygtk = import_pygtk()
114
 
        try:
115
 
            import gtk
116
 
        except RuntimeError, e:
117
 
            if str(e) == "could not open display":
118
 
                raise NoDisplayError
119
 
 
 
142
    def get_gtk_dialog(self, path):
120
143
        from bzrlib.plugins.gtk.checkout import CheckoutDialog
121
 
 
122
 
        set_ui_factory()
123
 
        dialog = CheckoutDialog(os.path.abspath('.'))
124
 
        dialog.run()
125
 
 
126
 
register_command(cmd_gcheckout)
127
 
 
128
 
class cmd_gpush(Command):
 
144
        return CheckoutDialog(path)
 
145
 
 
146
 
 
147
 
 
148
class cmd_gpush(GTKCommand):
129
149
    """ GTK+ push.
130
150
    
131
151
    """
132
152
    takes_args = [ "location?" ]
133
 
    
 
153
 
134
154
    def run(self, location="."):
135
 
        (branch, path) = Branch.open_containing(location)
136
 
        
137
 
        pygtk = import_pygtk()
138
 
        try:
139
 
            import gtk
140
 
        except RuntimeError, e:
141
 
            if str(e) == "could not open display":
142
 
                raise NoDisplayError
143
 
 
 
155
        (br, path) = branch.Branch.open_containing(location)
 
156
        self.open_display()
144
157
        from push import PushDialog
145
 
 
146
 
        set_ui_factory()
147
 
        dialog = PushDialog(branch)
 
158
        dialog = PushDialog(br)
148
159
        dialog.run()
149
160
 
150
 
register_command(cmd_gpush)
151
 
 
152
 
class cmd_gdiff(Command):
 
161
 
 
162
 
 
163
class cmd_gdiff(GTKCommand):
153
164
    """Show differences in working tree in a GTK+ Window.
154
165
    
155
166
    Otherwise, all changes for the tree are listed.
160
171
    @display_command
161
172
    def run(self, revision=None, filename=None):
162
173
        set_ui_factory()
163
 
        wt = WorkingTree.open_containing(".")[0]
164
 
        branch = wt.branch
165
 
        if revision is not None:
166
 
            if len(revision) == 1:
 
174
        wt = workingtree.WorkingTree.open_containing(".")[0]
 
175
        wt.lock_read()
 
176
        try:
 
177
            branch = wt.branch
 
178
            if revision is not None:
 
179
                if len(revision) == 1:
 
180
                    tree1 = wt
 
181
                    revision_id = revision[0].in_history(branch).rev_id
 
182
                    tree2 = branch.repository.revision_tree(revision_id)
 
183
                elif len(revision) == 2:
 
184
                    revision_id_0 = revision[0].in_history(branch).rev_id
 
185
                    tree2 = branch.repository.revision_tree(revision_id_0)
 
186
                    revision_id_1 = revision[1].in_history(branch).rev_id
 
187
                    tree1 = branch.repository.revision_tree(revision_id_1)
 
188
            else:
167
189
                tree1 = wt
168
 
                revision_id = revision[0].in_history(branch).rev_id
169
 
                tree2 = branch.repository.revision_tree(revision_id)
170
 
            elif len(revision) == 2:
171
 
                revision_id_0 = revision[0].in_history(branch).rev_id
172
 
                tree2 = branch.repository.revision_tree(revision_id_0)
173
 
                revision_id_1 = revision[1].in_history(branch).rev_id
174
 
                tree1 = branch.repository.revision_tree(revision_id_1)
175
 
        else:
176
 
            tree1 = wt
177
 
            tree2 = tree1.basis_tree()
178
 
 
179
 
        from viz.diff import DiffWindow
180
 
        import gtk
181
 
        window = DiffWindow()
182
 
        window.connect("destroy", lambda w: gtk.main_quit())
183
 
        window.set_diff("Working Tree", tree1, tree2)
184
 
        if filename is not None:
185
 
            tree_filename = wt.relpath(filename)
186
 
            try:
187
 
                window.set_file(tree_filename)
188
 
            except NoSuchFile:
189
 
                if (tree1.inventory.path2id(tree_filename) is None and 
190
 
                    tree2.inventory.path2id(tree_filename) is None):
191
 
                    raise NotVersionedError(filename)
192
 
                raise BzrCommandError('No changes found for file "%s"' % 
193
 
                                      filename)
194
 
        window.show()
195
 
 
196
 
        gtk.main()
197
 
 
198
 
register_command(cmd_gdiff)
 
190
                tree2 = tree1.basis_tree()
 
191
 
 
192
            from diff import DiffWindow
 
193
            import gtk
 
194
            window = DiffWindow()
 
195
            window.connect("destroy", gtk.main_quit)
 
196
            window.set_diff("Working Tree", tree1, tree2)
 
197
            if filename is not None:
 
198
                tree_filename = wt.relpath(filename)
 
199
                try:
 
200
                    window.set_file(tree_filename)
 
201
                except NoSuchFile:
 
202
                    if (tree1.path2id(tree_filename) is None and 
 
203
                        tree2.path2id(tree_filename) is None):
 
204
                        raise NotVersionedError(filename)
 
205
                    raise BzrCommandError('No changes found for file "%s"' % 
 
206
                                          filename)
 
207
            window.show()
 
208
 
 
209
            gtk.main()
 
210
        finally:
 
211
            wt.unlock()
 
212
 
 
213
 
 
214
def start_viz_window(branch, revision, limit=None):
 
215
    """Start viz on branch with revision revision.
 
216
    
 
217
    :return: The viz window object.
 
218
    """
 
219
    from viz.branchwin import BranchWindow
 
220
    branch.lock_read()
 
221
    pp = BranchWindow()
 
222
    pp.set_branch(branch, revision, limit)
 
223
    # cleanup locks when the window is closed
 
224
    pp.connect("destroy", lambda w: branch.unlock())
 
225
    return pp
 
226
 
199
227
 
200
228
class cmd_visualise(Command):
201
229
    """Graphically visualise this branch.
208
236
    """
209
237
    takes_options = [
210
238
        "revision",
211
 
        Option('limit', "maximum number of revisions to display",
 
239
        Option('limit', "Maximum number of revisions to display.",
212
240
               int, 'count')]
213
241
    takes_args = [ "location?" ]
214
242
    aliases = [ "visualize", "vis", "viz" ]
215
243
 
216
244
    def run(self, location=".", revision=None, limit=None):
217
245
        set_ui_factory()
218
 
        (branch, path) = Branch.open_containing(location)
219
 
        branch.lock_read()
220
 
        branch.repository.lock_read()
 
246
        (br, path) = branch.Branch.open_containing(location)
 
247
        br.lock_read()
221
248
        try:
222
249
            if revision is None:
223
 
                revid = branch.last_revision()
 
250
                revid = br.last_revision()
224
251
                if revid is None:
225
252
                    return
226
253
            else:
227
 
                (revno, revid) = revision[0].in_history(branch)
 
254
                (revno, revid) = revision[0].in_history(br)
228
255
 
229
 
            from viz.bzrkapp import BzrkApp
230
 
                
231
 
            app = BzrkApp()
232
 
            app.show(branch, revid, limit)
 
256
            import gtk
 
257
            pp = start_viz_window(br, revid, limit)
 
258
            pp.connect("destroy", lambda w: gtk.main_quit())
 
259
            pp.show()
 
260
            gtk.main()
233
261
        finally:
234
 
            branch.repository.unlock()
235
 
            branch.unlock()
236
 
        app.main()
237
 
 
238
 
 
239
 
register_command(cmd_visualise)
240
 
 
241
 
class cmd_gannotate(Command):
 
262
            br.unlock()
 
263
 
 
264
 
 
265
class cmd_gannotate(GTKCommand):
242
266
    """GTK+ annotate.
243
267
    
244
268
    Browse changes to FILENAME line by line in a GTK+ window.
246
270
 
247
271
    takes_args = ["filename", "line?"]
248
272
    takes_options = [
249
 
        Option("all", help="show annotations on all lines"),
250
 
        Option("plain", help="don't highlight annotation lines"),
 
273
        Option("all", help="Show annotations on all lines."),
 
274
        Option("plain", help="Don't highlight annotation lines."),
251
275
        Option("line", type=int, argname="lineno",
252
 
               help="jump to specified line number"),
 
276
               help="Jump to specified line number."),
253
277
        "revision",
254
278
    ]
255
279
    aliases = ["gblame", "gpraise"]
256
280
    
257
281
    def run(self, filename, all=False, plain=False, line='1', revision=None):
258
 
        pygtk = import_pygtk()
259
 
 
260
 
        try:
261
 
            import gtk
262
 
        except RuntimeError, e:
263
 
            if str(e) == "could not open display":
264
 
                raise NoDisplayError
265
 
        set_ui_factory()
 
282
        gtk = self.open_display()
266
283
 
267
284
        try:
268
285
            line = int(line)
272
289
 
273
290
        from annotate.gannotate import GAnnotateWindow
274
291
        from annotate.config import GAnnotateConfig
 
292
        from bzrlib.bzrdir import BzrDir
275
293
 
276
 
        try:
277
 
            (tree, path) = WorkingTree.open_containing(filename)
278
 
            branch = tree.branch
279
 
        except errors.NoWorkingTree:
280
 
            (branch, path) = Branch.open_containing(filename)
281
 
            tree = branch.basis_tree()
 
294
        wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
 
295
        if wt is not None:
 
296
            tree = wt
 
297
        else:
 
298
            tree = br.basis_tree()
282
299
 
283
300
        file_id = tree.path2id(path)
284
301
 
287
304
        if revision is not None:
288
305
            if len(revision) != 1:
289
306
                raise BzrCommandError("Only 1 revion may be specified.")
290
 
            revision_id = revision[0].in_history(branch).rev_id
291
 
            tree = branch.repository.revision_tree(revision_id)
 
307
            revision_id = revision[0].in_history(br).rev_id
 
308
            tree = br.repository.revision_tree(revision_id)
292
309
        else:
293
310
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
294
311
 
297
314
        window.set_title(path + " - gannotate")
298
315
        config = GAnnotateConfig(window)
299
316
        window.show()
300
 
        branch.lock_read()
 
317
        br.lock_read()
 
318
        if wt is not None:
 
319
            wt.lock_read()
301
320
        try:
302
 
            window.annotate(tree, branch, file_id)
 
321
            window.annotate(tree, br, file_id)
 
322
            window.jump_to_line(line)
 
323
            gtk.main()
303
324
        finally:
304
 
            branch.unlock()
305
 
        window.jump_to_line(line)
306
 
        
307
 
        gtk.main()
308
 
 
309
 
register_command(cmd_gannotate)
310
 
 
311
 
class cmd_gcommit(Command):
 
325
            br.unlock()
 
326
            if wt is not None:
 
327
                wt.unlock()
 
328
 
 
329
 
 
330
 
 
331
class cmd_gcommit(GTKCommand):
312
332
    """GTK+ commit dialog
313
333
 
314
334
    Graphical user interface for committing revisions"""
319
339
 
320
340
    def run(self, filename=None):
321
341
        import os
322
 
        pygtk = import_pygtk()
323
 
 
324
 
        try:
325
 
            import gtk
326
 
        except RuntimeError, e:
327
 
            if str(e) == "could not open display":
328
 
                raise NoDisplayError
329
 
 
330
 
        set_ui_factory()
 
342
        self.open_display()
331
343
        from commit import CommitDialog
332
 
        from bzrlib.commit import Commit
333
344
        from bzrlib.errors import (BzrCommandError,
334
345
                                   NotBranchError,
335
 
                                   NoWorkingTree,
336
 
                                   PointlessCommit,
337
 
                                   ConflictsInTree,
338
 
                                   StrictCommitFailed)
 
346
                                   NoWorkingTree)
339
347
 
340
348
        wt = None
341
 
        branch = None
 
349
        br = None
342
350
        try:
343
 
            (wt, path) = WorkingTree.open_containing(filename)
344
 
            branch = wt.branch
345
 
        except NotBranchError, e:
346
 
            path = e.path
 
351
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
 
352
            br = wt.branch
347
353
        except NoWorkingTree, e:
348
354
            path = e.base
349
 
            try:
350
 
                (branch, path) = Branch.open_containing(path)
351
 
            except NotBranchError, e:
352
 
                path = e.path
353
 
 
354
 
 
355
 
        commit = CommitDialog(wt, path, not branch)
 
355
            (br, path) = branch.Branch.open_containing(path)
 
356
 
 
357
        commit = CommitDialog(wt, path, not br)
356
358
        commit.run()
357
359
 
358
 
register_command(cmd_gcommit)
 
360
 
 
361
 
 
362
class cmd_gstatus(GTKCommand):
 
363
    """GTK+ status dialog
 
364
 
 
365
    Graphical user interface for showing status 
 
366
    information."""
 
367
    
 
368
    aliases = [ "gst" ]
 
369
    takes_args = ['PATH?']
 
370
    takes_options = []
 
371
 
 
372
    def run(self, path='.'):
 
373
        import os
 
374
        gtk = self.open_display()
 
375
        from status import StatusDialog
 
376
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
 
377
        status = StatusDialog(wt, wt_path)
 
378
        status.connect("destroy", gtk.main_quit)
 
379
        status.run()
 
380
 
 
381
 
 
382
 
 
383
class cmd_gconflicts(GTKCommand):
 
384
    """ GTK+ push.
 
385
    
 
386
    """
 
387
    def run(self):
 
388
        (wt, path) = workingtree.WorkingTree.open_containing('.')
 
389
        self.open_display()
 
390
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
 
391
        dialog = ConflictsDialog(wt)
 
392
        dialog.run()
 
393
 
 
394
 
 
395
 
 
396
class cmd_gpreferences(GTKCommand):
 
397
    """ GTK+ preferences dialog.
 
398
 
 
399
    """
 
400
    def run(self):
 
401
        self.open_display()
 
402
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
 
403
        dialog = PreferencesWindow()
 
404
        dialog.run()
 
405
 
 
406
 
 
407
 
 
408
class cmd_gmissing(Command):
 
409
    """ GTK+ missing revisions dialog.
 
410
 
 
411
    """
 
412
    takes_args = ["other_branch?"]
 
413
    def run(self, other_branch=None):
 
414
        pygtk = import_pygtk()
 
415
        try:
 
416
            import gtk
 
417
        except RuntimeError, e:
 
418
            if str(e) == "could not open display":
 
419
                raise NoDisplayError
 
420
 
 
421
        from bzrlib.plugins.gtk.missing import MissingWindow
 
422
        from bzrlib.branch import Branch
 
423
 
 
424
        local_branch = Branch.open_containing(".")[0]
 
425
        if other_branch is None:
 
426
            other_branch = local_branch.get_parent()
 
427
            
 
428
            if other_branch is None:
 
429
                raise errors.BzrCommandError("No peer location known or specified.")
 
430
        remote_branch = Branch.open_containing(other_branch)[0]
 
431
        set_ui_factory()
 
432
        local_branch.lock_read()
 
433
        try:
 
434
            remote_branch.lock_read()
 
435
            try:
 
436
                dialog = MissingWindow(local_branch, remote_branch)
 
437
                dialog.run()
 
438
            finally:
 
439
                remote_branch.unlock()
 
440
        finally:
 
441
            local_branch.unlock()
 
442
 
 
443
 
 
444
class cmd_ginit(GTKCommand):
 
445
    def run(self):
 
446
        self.open_display()
 
447
        from initialize import InitDialog
 
448
        dialog = InitDialog(os.path.abspath(os.path.curdir))
 
449
        dialog.run()
 
450
 
 
451
 
 
452
class cmd_gtags(GTKCommand):
 
453
    def run(self):
 
454
        br = branch.Branch.open_containing('.')[0]
 
455
        
 
456
        gtk = self.open_display()
 
457
        from tags import TagsWindow
 
458
        window = TagsWindow(br)
 
459
        window.show()
 
460
        gtk.main()
 
461
 
 
462
 
 
463
commands = [
 
464
    cmd_gmissing, 
 
465
    cmd_gpreferences, 
 
466
    cmd_gconflicts, 
 
467
    cmd_gstatus,
 
468
    cmd_gcommit, 
 
469
    cmd_gannotate, 
 
470
    cmd_visualise, 
 
471
    cmd_gdiff,
 
472
    cmd_gpush, 
 
473
    cmd_gcheckout, 
 
474
    cmd_gbranch,
 
475
    cmd_ginit,
 
476
    cmd_gtags
 
477
    ]
 
478
 
 
479
for cmd in commands:
 
480
    register_command(cmd)
 
481
 
 
482
 
 
483
class cmd_commit_notify(GTKCommand):
 
484
    """Run the bzr commit notifier.
 
485
 
 
486
    This is a background program which will pop up a notification on the users
 
487
    screen when a commit occurs.
 
488
    """
 
489
 
 
490
    def run(self):
 
491
        from notify import NotifyPopupMenu
 
492
        gtk = self.open_display()
 
493
        menu = NotifyPopupMenu()
 
494
        icon = gtk.status_icon_new_from_file("bzr-icon-64.png")
 
495
        icon.connect('popup-menu', menu.display)
 
496
 
 
497
        import cgi
 
498
        import dbus
 
499
        import dbus.service
 
500
        import pynotify
 
501
        from bzrlib.bzrdir import BzrDir
 
502
        from bzrlib import errors
 
503
        from bzrlib.osutils import format_date
 
504
        from bzrlib.transport import get_transport
 
505
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
 
506
            import dbus.glib
 
507
        from bzrlib.plugins.dbus import activity
 
508
        bus = dbus.SessionBus()
 
509
        # get the object so we can subscribe to callbacks from it.
 
510
        broadcast_service = bus.get_object(
 
511
            activity.Broadcast.DBUS_NAME,
 
512
            activity.Broadcast.DBUS_PATH)
 
513
 
 
514
        def catch_branch(revision_id, urls):
 
515
            # TODO: show all the urls, or perhaps choose the 'best'.
 
516
            url = urls[0]
 
517
            try:
 
518
                if isinstance(revision_id, unicode):
 
519
                    revision_id = revision_id.encode('utf8')
 
520
                transport = get_transport(url)
 
521
                a_dir = BzrDir.open_from_transport(transport)
 
522
                branch = a_dir.open_branch()
 
523
                revno = branch.revision_id_to_revno(revision_id)
 
524
                revision = branch.repository.get_revision(revision_id)
 
525
                summary = 'New revision %d in %s' % (revno, url)
 
526
                body  = 'Committer: %s\n' % revision.committer
 
527
                body += 'Date: %s\n' % format_date(revision.timestamp,
 
528
                    revision.timezone)
 
529
                body += '\n'
 
530
                body += revision.message
 
531
                body = cgi.escape(body)
 
532
                nw = pynotify.Notification(summary, body)
 
533
                def start_viz(notification=None, action=None, data=None):
 
534
                    """Start the viz program."""
 
535
                    pp = start_viz_window(branch, revision_id)
 
536
                    pp.show()
 
537
                def start_branch(notification=None, action=None, data=None):
 
538
                    """Start a Branch dialog"""
 
539
                    from bzrlib.plugins.gtk.branch import BranchDialog
 
540
                    bd = BranchDialog(remote_path=url)
 
541
                    bd.run()
 
542
                nw.add_action("inspect", "Inspect", start_viz, None)
 
543
                nw.add_action("branch", "Branch", start_branch, None)
 
544
                nw.set_timeout(5000)
 
545
                nw.show()
 
546
            except Exception, e:
 
547
                print e
 
548
                raise
 
549
        broadcast_service.connect_to_signal("Revision", catch_branch,
 
550
            dbus_interface=activity.Broadcast.DBUS_INTERFACE)
 
551
        pynotify.init("bzr commit-notify")
 
552
        gtk.main()
 
553
 
 
554
register_command(cmd_commit_notify)
 
555
 
 
556
 
 
557
import gettext
 
558
gettext.install('olive-gtk')
 
559
 
359
560
 
360
561
class NoDisplayError(BzrCommandError):
361
562
    """gtk could not find a proper display"""
363
564
    def __str__(self):
364
565
        return "No DISPLAY. Unable to run GTK+ application."
365
566
 
 
567
 
366
568
def test_suite():
367
569
    from unittest import TestSuite
368
570
    import tests
369
 
    result = TestSuite()
370
 
    result.addTest(tests.test_suite())
 
571
    import sys
 
572
    default_encoding = sys.getdefaultencoding()
 
573
    try:
 
574
        result = TestSuite()
 
575
        result.addTest(tests.test_suite())
 
576
    finally:
 
577
        if sys.getdefaultencoding() != default_encoding:
 
578
            reload(sys)
 
579
            sys.setdefaultencoding(default_encoding)
371
580
    return result