/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-06-29 16:24:24 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629162424-48a6rrjmmpejfcyr
Stop emitting no longer used revisions-loaded message.

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
commit-notify     Start the graphical notifier of commits.
18
19
gannotate         GTK+ annotate. 
19
20
gbranch           GTK+ branching. 
20
21
gcheckout         GTK+ checkout. 
22
23
gconflicts        GTK+ conflicts. 
23
24
gdiff             Show differences in working tree in a GTK+ Window. 
24
25
ginit             Initialise a new branch.
25
 
ginfo             GTK+ branch info dialog
26
 
gloom             GTK+ loom browse dialog
27
 
gmerge            GTK+ merge dialog
28
26
gmissing          GTK+ missing revisions dialog. 
29
27
gpreferences      GTK+ preferences dialog. 
30
28
gpush             GTK+ push.
38
36
 
39
37
import bzrlib
40
38
 
41
 
version_info = (0, 96, 0, 'dev', 1)
 
39
version_info = (0, 95, 0, 'dev', 1)
42
40
 
43
41
if version_info[3] == 'final':
44
42
    version_string = '%d.%d.%d' % version_info[:3]
46
44
    version_string = '%d.%d.%d%s%d' % version_info
47
45
__version__ = version_string
48
46
 
49
 
required_bzrlib = (1, 6)
 
47
required_bzrlib = (1, 3)
50
48
 
51
49
def check_bzrlib_version(desired):
52
50
    """Check that bzrlib is compatible.
106
104
    bzrlib.ui.ui_factory = GtkUIFactory()
107
105
 
108
106
 
109
 
def data_basedirs():
110
 
    return [os.path.dirname(__file__),
 
107
def data_path():
 
108
    return os.path.dirname(__file__)
 
109
 
 
110
 
 
111
def icon_path(*args):
 
112
    basedirs = [os.path.join(data_path()),
111
113
             "/usr/share/bzr-gtk", 
112
114
             "/usr/local/share/bzr-gtk"]
113
 
 
114
 
 
115
 
def data_path(*args):
116
 
    for basedir in data_basedirs():
117
 
        path = os.path.join(basedir, *args)
 
115
    for basedir in basedirs:
 
116
        path = os.path.join(basedir, 'icons', *args)
118
117
        if os.path.exists(path):
119
118
            return path
120
119
    return None
121
120
 
122
121
 
123
 
def icon_path(*args):
124
 
    return data_path(os.path.join('icons', *args))
125
 
 
126
 
 
127
122
def open_display():
128
123
    pygtk = import_pygtk()
129
124
    try:
174
169
    def run(self, location="."):
175
170
        (br, path) = branch.Branch.open_containing(location)
176
171
        open_display()
177
 
        from bzrlib.plugins.gtk.push import PushDialog
 
172
        from push import PushDialog
178
173
        dialog = PushDialog(br.repository, br.last_revision(), br)
179
174
        dialog.run()
180
175
 
181
176
 
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
177
 
201
178
class cmd_gdiff(GTKCommand):
202
179
    """Show differences in working tree in a GTK+ Window.
254
231
    
255
232
    :return: The viz window object.
256
233
    """
257
 
    from bzrlib.plugins.gtk.viz import BranchWindow
 
234
    from viz import BranchWindow
258
235
    return BranchWindow(branch, revisions, limit)
259
236
 
260
237
 
472
449
        dialog.run()
473
450
 
474
451
 
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
452
class cmd_gmissing(Command):
512
453
    """ GTK+ missing revisions dialog.
513
454
 
571
512
    cmd_gconflicts, 
572
513
    cmd_gdiff,
573
514
    cmd_ginit,
574
 
    cmd_ginfo,
575
 
    cmd_gmerge,
576
515
    cmd_gmissing, 
577
516
    cmd_gpreferences, 
578
517
    cmd_gpush, 
582
521
    cmd_visualise
583
522
    ]
584
523
 
585
 
try:
586
 
    from bzrlib.plugins import loom
587
 
except ImportError:
588
 
    pass # Loom plugin doesn't appear to be present
589
 
else:
590
 
    commands.append(cmd_gloom)
591
 
 
592
524
for cmd in commands:
593
525
    register_command(cmd)
594
526
 
595
527
 
 
528
class cmd_commit_notify(GTKCommand):
 
529
    """Run the bzr commit notifier.
 
530
 
 
531
    This is a background program which will pop up a notification on the users
 
532
    screen when a commit occurs.
 
533
    """
 
534
 
 
535
    def run(self):
 
536
        from notify import NotifyPopupMenu
 
537
        gtk = open_display()
 
538
        menu = NotifyPopupMenu()
 
539
        icon = gtk.status_icon_new_from_file(icon_path("bzr-icon-64.png"))
 
540
        icon.connect('popup-menu', menu.display)
 
541
 
 
542
        import cgi
 
543
        import dbus
 
544
        import dbus.service
 
545
        import pynotify
 
546
        from bzrlib.bzrdir import BzrDir
 
547
        from bzrlib import errors
 
548
        from bzrlib.osutils import format_date
 
549
        from bzrlib.transport import get_transport
 
550
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
 
551
            import dbus.glib
 
552
        BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast"
 
553
        bus = dbus.SessionBus()
 
554
 
 
555
        def catch_branch(revision_id, urls):
 
556
            # TODO: show all the urls, or perhaps choose the 'best'.
 
557
            url = urls[0]
 
558
            try:
 
559
                if isinstance(revision_id, unicode):
 
560
                    revision_id = revision_id.encode('utf8')
 
561
                transport = get_transport(url)
 
562
                a_dir = BzrDir.open_from_transport(transport)
 
563
                branch = a_dir.open_branch()
 
564
                revno = branch.revision_id_to_revno(revision_id)
 
565
                revision = branch.repository.get_revision(revision_id)
 
566
                summary = 'New revision %d in %s' % (revno, url)
 
567
                body  = 'Committer: %s\n' % revision.committer
 
568
                body += 'Date: %s\n' % format_date(revision.timestamp,
 
569
                    revision.timezone)
 
570
                body += '\n'
 
571
                body += revision.message
 
572
                body = cgi.escape(body)
 
573
                nw = pynotify.Notification(summary, body)
 
574
                def start_viz(notification=None, action=None, data=None):
 
575
                    """Start the viz program."""
 
576
                    pp = start_viz_window(branch, revision_id)
 
577
                    pp.show()
 
578
                def start_branch(notification=None, action=None, data=None):
 
579
                    """Start a Branch dialog"""
 
580
                    from bzrlib.plugins.gtk.branch import BranchDialog
 
581
                    bd = BranchDialog(remote_path=url)
 
582
                    bd.run()
 
583
                nw.add_action("inspect", "Inspect", start_viz, None)
 
584
                nw.add_action("branch", "Branch", start_branch, None)
 
585
                nw.set_timeout(5000)
 
586
                nw.show()
 
587
            except Exception, e:
 
588
                print e
 
589
                raise
 
590
        bus.add_signal_receiver(catch_branch,
 
591
                                dbus_interface=BROADCAST_INTERFACE,
 
592
                                signal_name="Revision")
 
593
        pynotify.init("bzr commit-notify")
 
594
        gtk.main()
 
595
 
 
596
register_command(cmd_commit_notify)
 
597
 
 
598
 
596
599
class cmd_gselftest(GTKCommand):
597
600
    """Version of selftest that displays a notification at the end"""
598
601
 
627
630
register_command(cmd_gselftest)
628
631
 
629
632
 
 
633
class cmd_test_gtk(GTKCommand):
 
634
    """Version of selftest that just runs the gtk test suite."""
 
635
 
 
636
    takes_options = ['verbose',
 
637
                     Option('one', short_name='1',
 
638
                            help='Stop when one test fails.'),
 
639
                     Option('benchmark', help='Run the benchmarks.'),
 
640
                     Option('lsprof-timed',
 
641
                     help='Generate lsprof output for benchmarked'
 
642
                          ' sections of code.'),
 
643
                     Option('list-only',
 
644
                     help='List the tests instead of running them.'),
 
645
                     Option('randomize', type=str, argname="SEED",
 
646
                     help='Randomize the order of tests using the given'
 
647
                          ' seed or "now" for the current time.'),
 
648
                    ]
 
649
    takes_args = ['testspecs*']
 
650
 
 
651
    def run(self, verbose=None, one=False, benchmark=None,
 
652
            lsprof_timed=None, list_only=False, randomize=None,
 
653
            testspecs_list=None):
 
654
        from bzrlib import __path__ as bzrlib_path
 
655
        from bzrlib.tests import selftest
 
656
 
 
657
        print '%10s: %s' % ('bzrlib', bzrlib_path[0])
 
658
        if benchmark:
 
659
            print 'No benchmarks yet'
 
660
            return 3
 
661
 
 
662
            test_suite_factory = bench_suite
 
663
            if verbose is None:
 
664
                verbose = True
 
665
            # TODO: should possibly lock the history file...
 
666
            benchfile = open(".perf_history", "at", buffering=1)
 
667
        else:
 
668
            test_suite_factory = test_suite
 
669
            if verbose is None:
 
670
                verbose = False
 
671
            benchfile = None
 
672
 
 
673
        if testspecs_list is not None:
 
674
            pattern = '|'.join(testspecs_list)
 
675
        else:
 
676
            pattern = ".*"
 
677
 
 
678
        try:
 
679
            result = selftest(verbose=verbose,
 
680
                              pattern=pattern,
 
681
                              stop_on_failure=one,
 
682
                              test_suite_factory=test_suite_factory,
 
683
                              lsprof_timed=lsprof_timed,
 
684
                              bench_history=benchfile,
 
685
                              list_only=list_only,
 
686
                              random_seed=randomize,
 
687
                             )
 
688
        finally:
 
689
            if benchfile is not None:
 
690
                benchfile.close()
 
691
 
 
692
register_command(cmd_test_gtk)
 
693
 
 
694
 
 
695
 
630
696
import gettext
631
697
gettext.install('olive-gtk')
632
698