/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: Daniel Schierbeck
  • Date: 2008-01-13 14:15:20 UTC
  • mto: (423.1.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 429.
  • Revision ID: daniel.schierbeck@gmail.com-20080113141520-ol1on2ju8h833rh0
Moved the branch window class to the viz package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
# along with this program; if not, write to the Free Software
13
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
14
 
15
 
"""GTK+ frontends to Bazaar commands """
 
15
"""Graphical support for Bazaar using GTK.
 
16
 
 
17
This plugin includes:
 
18
commit-notify     Start the graphical notifier of commits.
 
19
gannotate         GTK+ annotate. 
 
20
gbranch           GTK+ branching. 
 
21
gcheckout         GTK+ checkout. 
 
22
gcommit           GTK+ commit dialog.
 
23
gconflicts        GTK+ conflicts. 
 
24
gdiff             Show differences in working tree in a GTK+ Window. 
 
25
ginit             Initialise a new branch.
 
26
gmissing          GTK+ missing revisions dialog. 
 
27
gpreferences      GTK+ preferences dialog. 
 
28
gpush             GTK+ push.
 
29
gsend             GTK+ send merge directive.
 
30
gstatus           GTK+ status dialog.
 
31
gtags             Manage branch tags.
 
32
visualise         Graphically visualise this branch. 
 
33
"""
 
34
 
 
35
import sys
16
36
 
17
37
import bzrlib
18
38
 
19
 
__version__ = '0.17.0'
20
 
version_info = tuple(int(n) for n in __version__.split('.'))
21
 
 
 
39
version_info = (0, 94, 0, 'dev', 0)
 
40
 
 
41
if version_info[3] == 'final':
 
42
    version_string = '%d.%d.%d' % version_info[:3]
 
43
else:
 
44
    version_string = '%d.%d.%d%s%d' % version_info
 
45
__version__ = version_string
 
46
 
 
47
required_bzrlib = (1, 0)
22
48
 
23
49
def check_bzrlib_version(desired):
24
50
    """Check that bzrlib is compatible.
25
51
 
26
52
    If version is < bzr-gtk version, assume incompatible.
27
 
    If version == bzr-gtk version, assume completely compatible
28
 
    If version == bzr-gtk version + 1, assume compatible, with deprecations
29
 
    Otherwise, assume incompatible.
30
53
    """
31
 
    desired_plus = (desired[0], desired[1]+1)
32
54
    bzrlib_version = bzrlib.version_info[:2]
33
 
    if bzrlib_version == desired:
34
 
        return
35
55
    try:
36
56
        from bzrlib.trace import warning
37
57
    except ImportError:
38
58
        # get the message out any way we can
39
59
        from warnings import warn as warning
40
60
    if bzrlib_version < desired:
41
 
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
 
61
        from bzrlib.errors import BzrError
 
62
        warning('Installed Bazaar version %s is too old to be used with bzr-gtk'
42
63
                ' %s.' % (bzrlib.__version__, __version__))
43
 
        raise BzrError('Version mismatch: %r' % version_info)
44
 
    else:
45
 
        warning('bzr-gtk is not up to date with installed bzr version %s.'
46
 
                ' \nThere should be a newer version available, e.g. %i.%i.' 
47
 
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
48
 
        if bzrlib_version != desired_plus:
49
 
            raise Exception, 'Version mismatch'
50
 
 
51
 
 
52
 
check_bzrlib_version(version_info[:2])
 
64
        raise BzrError('Version mismatch: %r, %r' % (version_info, bzrlib.version_info) )
 
65
 
 
66
 
 
67
if version_info[2] == "final":
 
68
    check_bzrlib_version(required_bzrlib)
53
69
 
54
70
from bzrlib.trace import warning
55
71
if __name__ != 'bzrlib.plugins.gtk':
59
75
lazy_import(globals(), """
60
76
from bzrlib import (
61
77
    branch,
 
78
    builtins,
62
79
    errors,
63
80
    workingtree,
64
81
    )
86
103
    bzrlib.ui.ui_factory = GtkUIFactory()
87
104
 
88
105
 
 
106
def data_path():
 
107
    return os.path.dirname(__file__)
 
108
 
 
109
 
89
110
class GTKCommand(Command):
90
111
    """Abstract class providing GTK specific run commands."""
91
112
 
136
157
        (br, path) = branch.Branch.open_containing(location)
137
158
        self.open_display()
138
159
        from push import PushDialog
139
 
        dialog = PushDialog(br)
 
160
        dialog = PushDialog(br.repository, br.last_revision(), br)
140
161
        dialog.run()
141
162
 
142
163
 
192
213
            wt.unlock()
193
214
 
194
215
 
 
216
def start_viz_window(branch, revision, limit=None):
 
217
    """Start viz on branch with revision revision.
 
218
    
 
219
    :return: The viz window object.
 
220
    """
 
221
    from viz import BranchWindow
 
222
    return BranchWindow(branch, revision, limit)
 
223
 
 
224
 
195
225
class cmd_visualise(Command):
196
226
    """Graphically visualise this branch.
197
227
 
203
233
    """
204
234
    takes_options = [
205
235
        "revision",
206
 
        Option('limit', "maximum number of revisions to display",
 
236
        Option('limit', "Maximum number of revisions to display.",
207
237
               int, 'count')]
208
238
    takes_args = [ "location?" ]
209
239
    aliases = [ "visualize", "vis", "viz" ]
211
241
    def run(self, location=".", revision=None, limit=None):
212
242
        set_ui_factory()
213
243
        (br, path) = branch.Branch.open_containing(location)
214
 
        br.lock_read()
215
 
        br.repository.lock_read()
216
 
        try:
217
 
            if revision is None:
218
 
                revid = br.last_revision()
219
 
                if revid is None:
220
 
                    return
221
 
            else:
222
 
                (revno, revid) = revision[0].in_history(br)
 
244
        if revision is None:
 
245
            revid = br.last_revision()
 
246
            if revid is None:
 
247
                return
 
248
        else:
 
249
            (revno, revid) = revision[0].in_history(br)
223
250
 
224
 
            from viz.branchwin import BranchWindow
225
 
            import gtk
226
 
                
227
 
            pp = BranchWindow()
228
 
            pp.set_branch(br, revid, limit)
229
 
            pp.connect("destroy", lambda w: gtk.main_quit())
230
 
            pp.show()
231
 
            gtk.main()
232
 
        finally:
233
 
            br.repository.unlock()
234
 
            br.unlock()
 
251
        import gtk
 
252
        pp = start_viz_window(br, revid, limit)
 
253
        pp.connect("destroy", lambda w: gtk.main_quit())
 
254
        pp.show()
 
255
        gtk.main()
235
256
 
236
257
 
237
258
class cmd_gannotate(GTKCommand):
242
263
 
243
264
    takes_args = ["filename", "line?"]
244
265
    takes_options = [
245
 
        Option("all", help="show annotations on all lines"),
246
 
        Option("plain", help="don't highlight annotation lines"),
 
266
        Option("all", help="Show annotations on all lines."),
 
267
        Option("plain", help="Don't highlight annotation lines."),
247
268
        Option("line", type=int, argname="lineno",
248
 
               help="jump to specified line number"),
 
269
               help="Jump to specified line number."),
249
270
        "revision",
250
271
    ]
251
272
    aliases = ["gblame", "gpraise"]
304
325
    """GTK+ commit dialog
305
326
 
306
327
    Graphical user interface for committing revisions"""
307
 
    
 
328
 
308
329
    aliases = [ "gci" ]
309
330
    takes_args = []
310
331
    takes_options = []
323
344
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
324
345
            br = wt.branch
325
346
        except NoWorkingTree, e:
326
 
            path = e.base
327
 
            (br, path) = branch.Branch.open_containing(path)
328
 
 
329
 
        commit = CommitDialog(wt, path, not br)
330
 
        commit.run()
331
 
 
 
347
            from dialog import error_dialog
 
348
            error_dialog(_('Directory does not have a working tree'),
 
349
                         _('Operation aborted.'))
 
350
            return 1 # should this be retval=3?
 
351
 
 
352
        # It is a good habit to keep things locked for the duration, but it
 
353
        # could cause difficulties if someone wants to do things in another
 
354
        # window... We could lock_read() until we actually go to commit
 
355
        # changes... Just a thought.
 
356
        wt.lock_write()
 
357
        try:
 
358
            dlg = CommitDialog(wt)
 
359
            return dlg.run()
 
360
        finally:
 
361
            wt.unlock()
332
362
 
333
363
 
334
364
class cmd_gstatus(GTKCommand):
351
381
        status.run()
352
382
 
353
383
 
 
384
class cmd_gsend(GTKCommand):
 
385
    """GTK+ send merge directive.
 
386
 
 
387
    """
 
388
    def run(self):
 
389
        (br, path) = branch.Branch.open_containing(".")
 
390
        gtk = self.open_display()
 
391
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
 
392
        from StringIO import StringIO
 
393
        dialog = SendMergeDirectiveDialog(br)
 
394
        if dialog.run() == gtk.RESPONSE_OK:
 
395
            outf = StringIO()
 
396
            outf.writelines(dialog.get_merge_directive().to_lines())
 
397
            mail_client = br.get_config().get_mail_client()
 
398
            mail_client.compose_merge_request(dialog.get_mail_to(), "[MERGE]", 
 
399
                outf.getvalue())
 
400
 
 
401
            
 
402
 
354
403
 
355
404
class cmd_gconflicts(GTKCommand):
356
 
    """ GTK+ push.
 
405
    """GTK+ conflicts.
357
406
    
 
407
    Select files from the list of conflicts and run an external utility to
 
408
    resolve them.
358
409
    """
359
410
    def run(self):
360
411
        (wt, path) = workingtree.WorkingTree.open_containing('.')
364
415
        dialog.run()
365
416
 
366
417
 
367
 
 
368
418
class cmd_gpreferences(GTKCommand):
369
419
    """ GTK+ preferences dialog.
370
420
 
376
426
        dialog.run()
377
427
 
378
428
 
379
 
 
380
429
class cmd_gmissing(Command):
381
430
    """ GTK+ missing revisions dialog.
382
431
 
433
482
 
434
483
 
435
484
commands = [
 
485
    cmd_gannotate, 
 
486
    cmd_gbranch,
 
487
    cmd_gcheckout, 
 
488
    cmd_gcommit, 
 
489
    cmd_gconflicts, 
 
490
    cmd_gdiff,
 
491
    cmd_ginit,
436
492
    cmd_gmissing, 
437
493
    cmd_gpreferences, 
438
 
    cmd_gconflicts, 
 
494
    cmd_gpush, 
 
495
    cmd_gsend,
439
496
    cmd_gstatus,
440
 
    cmd_gcommit, 
441
 
    cmd_gannotate, 
442
 
    cmd_visualise, 
443
 
    cmd_gdiff,
444
 
    cmd_gpush, 
445
 
    cmd_gcheckout, 
446
 
    cmd_gbranch,
447
 
    cmd_ginit,
448
 
    cmd_gtags
 
497
    cmd_gtags,
 
498
    cmd_visualise
449
499
    ]
450
500
 
451
501
for cmd in commands:
460
510
    """
461
511
 
462
512
    def run(self):
 
513
        from notify import NotifyPopupMenu
463
514
        gtk = self.open_display()
 
515
        menu = NotifyPopupMenu()
 
516
        icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
 
517
        icon.connect('popup-menu', menu.display)
 
518
 
464
519
        import cgi
465
520
        import dbus
466
521
        import dbus.service
477
532
        broadcast_service = bus.get_object(
478
533
            activity.Broadcast.DBUS_NAME,
479
534
            activity.Broadcast.DBUS_PATH)
 
535
 
480
536
        def catch_branch(revision_id, urls):
481
537
            # TODO: show all the urls, or perhaps choose the 'best'.
482
538
            url = urls[0]
496
552
                body += revision.message
497
553
                body = cgi.escape(body)
498
554
                nw = pynotify.Notification(summary, body)
 
555
                def start_viz(notification=None, action=None, data=None):
 
556
                    """Start the viz program."""
 
557
                    pp = start_viz_window(branch, revision_id)
 
558
                    pp.show()
 
559
                def start_branch(notification=None, action=None, data=None):
 
560
                    """Start a Branch dialog"""
 
561
                    from bzrlib.plugins.gtk.branch import BranchDialog
 
562
                    bd = BranchDialog(remote_path=url)
 
563
                    bd.run()
 
564
                nw.add_action("inspect", "Inspect", start_viz, None)
 
565
                nw.add_action("branch", "Branch", start_branch, None)
499
566
                nw.set_timeout(5000)
500
567
                nw.show()
501
568
            except Exception, e:
509
576
register_command(cmd_commit_notify)
510
577
 
511
578
 
 
579
class cmd_gselftest(GTKCommand):
 
580
    """Version of selftest that displays a notification at the end"""
 
581
 
 
582
    takes_args = builtins.cmd_selftest.takes_args
 
583
    takes_options = builtins.cmd_selftest.takes_options
 
584
    _see_also = ['selftest']
 
585
 
 
586
    def run(self, *args, **kwargs):
 
587
        import cgi
 
588
        import sys
 
589
        default_encoding = sys.getdefaultencoding()
 
590
        # prevent gtk from blowing up later
 
591
        gtk = import_pygtk()
 
592
        # prevent gtk from messing with default encoding
 
593
        import pynotify
 
594
        if sys.getdefaultencoding() != default_encoding:
 
595
            reload(sys)
 
596
            sys.setdefaultencoding(default_encoding)
 
597
        result = builtins.cmd_selftest().run(*args, **kwargs)
 
598
        if result == 0:
 
599
            summary = 'Success'
 
600
            body = 'Selftest succeeded in "%s"' % os.getcwd()
 
601
        if result == 1:
 
602
            summary = 'Failure'
 
603
            body = 'Selftest failed in "%s"' % os.getcwd()
 
604
        pynotify.init("bzr gselftest")
 
605
        note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
 
606
        note.set_timeout(pynotify.EXPIRES_NEVER)
 
607
        note.show()
 
608
 
 
609
 
 
610
register_command(cmd_gselftest)
 
611
 
 
612
 
 
613
class cmd_test_gtk(GTKCommand):
 
614
    """Version of selftest that just runs the gtk test suite."""
 
615
 
 
616
    takes_options = ['verbose',
 
617
                     Option('one', short_name='1',
 
618
                            help='Stop when one test fails.'),
 
619
                     Option('benchmark', help='Run the benchmarks.'),
 
620
                     Option('lsprof-timed',
 
621
                     help='Generate lsprof output for benchmarked'
 
622
                          ' sections of code.'),
 
623
                     Option('list-only',
 
624
                     help='List the tests instead of running them.'),
 
625
                     Option('randomize', type=str, argname="SEED",
 
626
                     help='Randomize the order of tests using the given'
 
627
                          ' seed or "now" for the current time.'),
 
628
                    ]
 
629
    takes_args = ['testspecs*']
 
630
 
 
631
    def run(self, verbose=None, one=False, benchmark=None,
 
632
            lsprof_timed=None, list_only=False, randomize=None,
 
633
            testspecs_list=None):
 
634
        from bzrlib import __path__ as bzrlib_path
 
635
        from bzrlib.tests import selftest
 
636
 
 
637
        print '%10s: %s' % ('bzrlib', bzrlib_path[0])
 
638
        if benchmark:
 
639
            print 'No benchmarks yet'
 
640
            return 3
 
641
 
 
642
            test_suite_factory = bench_suite
 
643
            if verbose is None:
 
644
                verbose = True
 
645
            # TODO: should possibly lock the history file...
 
646
            benchfile = open(".perf_history", "at", buffering=1)
 
647
        else:
 
648
            test_suite_factory = test_suite
 
649
            if verbose is None:
 
650
                verbose = False
 
651
            benchfile = None
 
652
 
 
653
        if testspecs_list is not None:
 
654
            pattern = '|'.join(testspecs_list)
 
655
        else:
 
656
            pattern = ".*"
 
657
 
 
658
        try:
 
659
            result = selftest(verbose=verbose,
 
660
                              pattern=pattern,
 
661
                              stop_on_failure=one,
 
662
                              test_suite_factory=test_suite_factory,
 
663
                              lsprof_timed=lsprof_timed,
 
664
                              bench_history=benchfile,
 
665
                              list_only=list_only,
 
666
                              random_seed=randomize,
 
667
                             )
 
668
        finally:
 
669
            if benchfile is not None:
 
670
                benchfile.close()
 
671
 
 
672
register_command(cmd_test_gtk)
 
673
 
 
674
 
512
675
import gettext
513
676
gettext.install('olive-gtk')
514
677
 
527
690
    default_encoding = sys.getdefaultencoding()
528
691
    try:
529
692
        result = TestSuite()
 
693
        try:
 
694
            import_pygtk()
 
695
        except errors.BzrCommandError:
 
696
            return result
530
697
        result.addTest(tests.test_suite())
531
698
    finally:
532
699
        if sys.getdefaultencoding() != default_encoding: