/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-04-07 20:34:51 UTC
  • mfrom: (450.6.13 bugs)
  • mto: (463.2.1 bug.78765)
  • mto: This revision was merged to the branch mainline in revision 462.
  • Revision ID: daniel.schierbeck@gmail.com-20080407203451-2i6el7jf9t0k9y64
Merged bug page improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
gcommit           GTK+ commit dialog.
23
23
gconflicts        GTK+ conflicts. 
24
24
gdiff             Show differences in working tree in a GTK+ Window. 
 
25
ghandle-patch     Display and optionally merge a merge directive or patch.
25
26
ginit             Initialise a new branch.
26
27
gmissing          GTK+ missing revisions dialog. 
27
28
gpreferences      GTK+ preferences dialog. 
32
33
visualise         Graphically visualise this branch. 
33
34
"""
34
35
 
 
36
import sys
 
37
 
35
38
import bzrlib
36
39
 
37
 
version_info = (0, 92, 0, 'dev', 0)
 
40
version_info = (0, 94, 0, 'dev', 0)
38
41
 
39
42
if version_info[3] == 'final':
40
43
    version_string = '%d.%d.%d' % version_info[:3]
42
45
    version_string = '%d.%d.%d%s%d' % version_info
43
46
__version__ = version_string
44
47
 
 
48
required_bzrlib = (1, 3)
 
49
 
45
50
def check_bzrlib_version(desired):
46
51
    """Check that bzrlib is compatible.
47
52
 
48
53
    If version is < bzr-gtk version, assume incompatible.
49
 
    If version == bzr-gtk version, assume completely compatible
50
 
    If version == bzr-gtk version + 1, assume compatible, with deprecations
51
 
    Otherwise, assume incompatible.
52
54
    """
53
 
    desired_plus = (desired[0], desired[1]+1)
54
55
    bzrlib_version = bzrlib.version_info[:2]
55
 
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
56
 
                                     bzrlib.version_info[3] == 'dev'):
57
 
        return
58
56
    try:
59
57
        from bzrlib.trace import warning
60
58
    except ImportError:
65
63
        warning('Installed Bazaar version %s is too old to be used with bzr-gtk'
66
64
                ' %s.' % (bzrlib.__version__, __version__))
67
65
        raise BzrError('Version mismatch: %r, %r' % (version_info, bzrlib.version_info) )
68
 
    else:
69
 
        warning('bzr-gtk is not up to date with installed bzr version %s.'
70
 
                ' \nThere should be a newer version available, e.g. %i.%i.' 
71
 
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
72
66
 
73
67
 
74
68
if version_info[2] == "final":
75
 
    check_bzrlib_version(version_info[:2])
 
69
    check_bzrlib_version(required_bzrlib)
76
70
 
77
71
from bzrlib.trace import warning
78
72
if __name__ != 'bzrlib.plugins.gtk':
84
78
    branch,
85
79
    builtins,
86
80
    errors,
 
81
    merge_directive,
87
82
    workingtree,
88
83
    )
89
84
""")
114
109
    return os.path.dirname(__file__)
115
110
 
116
111
 
 
112
def icon_path(*args):
 
113
    basedirs = [os.path.join(data_path()),
 
114
             "/usr/share/bzr-gtk", 
 
115
             "/usr/local/share/bzr-gtk"]
 
116
    for basedir in basedirs:
 
117
        path = os.path.join(basedir, 'icons', *args)
 
118
        if os.path.exists(path):
 
119
            return path
 
120
    return None
 
121
 
 
122
 
117
123
class GTKCommand(Command):
118
124
    """Abstract class providing GTK specific run commands."""
119
125
 
220
226
            wt.unlock()
221
227
 
222
228
 
223
 
def start_viz_window(branch, revision, limit=None):
 
229
def start_viz_window(branch, revisions, limit=None):
224
230
    """Start viz on branch with revision revision.
225
231
    
226
232
    :return: The viz window object.
227
233
    """
228
 
    from viz.branchwin import BranchWindow
229
 
    return BranchWindow(branch, revision, limit)
 
234
    from viz import BranchWindow
 
235
    return BranchWindow(branch, revisions, limit)
230
236
 
231
237
 
232
238
class cmd_visualise(Command):
242
248
        "revision",
243
249
        Option('limit', "Maximum number of revisions to display.",
244
250
               int, 'count')]
245
 
    takes_args = [ "location?" ]
 
251
    takes_args = [ "locations*" ]
246
252
    aliases = [ "visualize", "vis", "viz" ]
247
253
 
248
 
    def run(self, location=".", revision=None, limit=None):
 
254
    def run(self, locations_list, revision=None, limit=None):
249
255
        set_ui_factory()
250
 
        (br, path) = branch.Branch.open_containing(location)
251
 
        br.lock_read()
252
 
        try:
 
256
        if locations_list is None:
 
257
            locations_list = ["."]
 
258
        revids = []
 
259
        for location in locations_list:
 
260
            (br, path) = branch.Branch.open_containing(location)
253
261
            if revision is None:
254
 
                revid = br.last_revision()
255
 
                if revid is None:
256
 
                    return
 
262
                revids.append(br.last_revision())
257
263
            else:
258
264
                (revno, revid) = revision[0].in_history(br)
259
 
 
260
 
            import gtk
261
 
            pp = start_viz_window(br, revid, limit)
262
 
            pp.connect("destroy", lambda w: gtk.main_quit())
263
 
            pp.show()
264
 
            gtk.main()
265
 
        finally:
266
 
            br.unlock()
 
265
                revids.append(revid)
 
266
        import gtk
 
267
        pp = start_viz_window(br, revids, limit)
 
268
        pp.connect("destroy", lambda w: gtk.main_quit())
 
269
        pp.show()
 
270
        gtk.main()
267
271
 
268
272
 
269
273
class cmd_gannotate(GTKCommand):
315
319
 
316
320
        window = GAnnotateWindow(all, plain)
317
321
        window.connect("destroy", lambda w: gtk.main_quit())
318
 
        window.set_title(path + " - gannotate")
319
322
        config = GAnnotateConfig(window)
320
323
        window.show()
321
324
        br.lock_read()
336
339
    """GTK+ commit dialog
337
340
 
338
341
    Graphical user interface for committing revisions"""
339
 
    
 
342
 
340
343
    aliases = [ "gci" ]
341
344
    takes_args = []
342
345
    takes_options = []
355
358
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
356
359
            br = wt.branch
357
360
        except NoWorkingTree, e:
358
 
            path = e.base
359
 
            (br, path) = branch.Branch.open_containing(path)
360
 
 
361
 
        commit = CommitDialog(wt, path, not br)
362
 
        commit.run()
363
 
 
 
361
            from dialog import error_dialog
 
362
            error_dialog(_('Directory does not have a working tree'),
 
363
                         _('Operation aborted.'))
 
364
            return 1 # should this be retval=3?
 
365
 
 
366
        # It is a good habit to keep things locked for the duration, but it
 
367
        # could cause difficulties if someone wants to do things in another
 
368
        # window... We could lock_read() until we actually go to commit
 
369
        # changes... Just a thought.
 
370
        wt.lock_write()
 
371
        try:
 
372
            dlg = CommitDialog(wt)
 
373
            return dlg.run()
 
374
        finally:
 
375
            wt.unlock()
364
376
 
365
377
 
366
378
class cmd_gstatus(GTKCommand):
515
527
        from notify import NotifyPopupMenu
516
528
        gtk = self.open_display()
517
529
        menu = NotifyPopupMenu()
518
 
        icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
 
530
        icon = gtk.status_icon_new_from_file(icon_path("bzr-icon-64.png"))
519
531
        icon.connect('popup-menu', menu.display)
520
532
 
521
533
        import cgi
528
540
        from bzrlib.transport import get_transport
529
541
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
530
542
            import dbus.glib
531
 
        from bzrlib.plugins.dbus import activity
 
543
        BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast"
532
544
        bus = dbus.SessionBus()
533
 
        # get the object so we can subscribe to callbacks from it.
534
 
        broadcast_service = bus.get_object(
535
 
            activity.Broadcast.DBUS_NAME,
536
 
            activity.Broadcast.DBUS_PATH)
537
545
 
538
546
        def catch_branch(revision_id, urls):
539
547
            # TODO: show all the urls, or perhaps choose the 'best'.
570
578
            except Exception, e:
571
579
                print e
572
580
                raise
573
 
        broadcast_service.connect_to_signal("Revision", catch_branch,
574
 
            dbus_interface=activity.Broadcast.DBUS_INTERFACE)
 
581
        bus.add_signal_receiver(catch_branch,
 
582
                                dbus_interface=BROADCAST_INTERFACE,
 
583
                                signal_name="Revision")
575
584
        pynotify.init("bzr commit-notify")
576
585
        gtk.main()
577
586
 
612
621
register_command(cmd_gselftest)
613
622
 
614
623
 
 
624
class cmd_test_gtk(GTKCommand):
 
625
    """Version of selftest that just runs the gtk test suite."""
 
626
 
 
627
    takes_options = ['verbose',
 
628
                     Option('one', short_name='1',
 
629
                            help='Stop when one test fails.'),
 
630
                     Option('benchmark', help='Run the benchmarks.'),
 
631
                     Option('lsprof-timed',
 
632
                     help='Generate lsprof output for benchmarked'
 
633
                          ' sections of code.'),
 
634
                     Option('list-only',
 
635
                     help='List the tests instead of running them.'),
 
636
                     Option('randomize', type=str, argname="SEED",
 
637
                     help='Randomize the order of tests using the given'
 
638
                          ' seed or "now" for the current time.'),
 
639
                    ]
 
640
    takes_args = ['testspecs*']
 
641
 
 
642
    def run(self, verbose=None, one=False, benchmark=None,
 
643
            lsprof_timed=None, list_only=False, randomize=None,
 
644
            testspecs_list=None):
 
645
        from bzrlib import __path__ as bzrlib_path
 
646
        from bzrlib.tests import selftest
 
647
 
 
648
        print '%10s: %s' % ('bzrlib', bzrlib_path[0])
 
649
        if benchmark:
 
650
            print 'No benchmarks yet'
 
651
            return 3
 
652
 
 
653
            test_suite_factory = bench_suite
 
654
            if verbose is None:
 
655
                verbose = True
 
656
            # TODO: should possibly lock the history file...
 
657
            benchfile = open(".perf_history", "at", buffering=1)
 
658
        else:
 
659
            test_suite_factory = test_suite
 
660
            if verbose is None:
 
661
                verbose = False
 
662
            benchfile = None
 
663
 
 
664
        if testspecs_list is not None:
 
665
            pattern = '|'.join(testspecs_list)
 
666
        else:
 
667
            pattern = ".*"
 
668
 
 
669
        try:
 
670
            result = selftest(verbose=verbose,
 
671
                              pattern=pattern,
 
672
                              stop_on_failure=one,
 
673
                              test_suite_factory=test_suite_factory,
 
674
                              lsprof_timed=lsprof_timed,
 
675
                              bench_history=benchfile,
 
676
                              list_only=list_only,
 
677
                              random_seed=randomize,
 
678
                             )
 
679
        finally:
 
680
            if benchfile is not None:
 
681
                benchfile.close()
 
682
 
 
683
register_command(cmd_test_gtk)
 
684
 
 
685
 
 
686
class cmd_ghandle_patch(GTKCommand):
 
687
    """Display a patch or merge directive, possibly merging.
 
688
 
 
689
    This is a helper, meant to be launched from other programs like browsers
 
690
    or email clients.  Since these programs often do not allow parameters to
 
691
    be provided, a "handle-patch" script is included.
 
692
    """
 
693
 
 
694
    takes_args = ['path']
 
695
 
 
696
    def run(self, path):
 
697
        try:
 
698
            from bzrlib.plugins.gtk.diff import (DiffWindow,
 
699
                                                 MergeDirectiveWindow)
 
700
            lines = open(path, 'rb').readlines()
 
701
            lines = [l.replace('\r\n', '\n') for l in lines]
 
702
            try:
 
703
                directive = merge_directive.MergeDirective.from_lines(lines)
 
704
            except errors.NotAMergeDirective:
 
705
                window = DiffWindow()
 
706
                window.set_diff_text(path, lines)
 
707
            else:
 
708
                window = MergeDirectiveWindow(directive, path)
 
709
                window.set_diff_text(path, directive.patch.splitlines(True))
 
710
            window.show()
 
711
            gtk = self.open_display()
 
712
            window.connect("destroy", gtk.main_quit)
 
713
        except Exception, e:
 
714
            from dialog import error_dialog
 
715
            error_dialog('Error', str(e))
 
716
            raise
 
717
        gtk.main()
 
718
 
 
719
 
 
720
register_command(cmd_ghandle_patch)
 
721
 
 
722
 
615
723
import gettext
616
724
gettext.install('olive-gtk')
617
725
 
630
738
    default_encoding = sys.getdefaultencoding()
631
739
    try:
632
740
        result = TestSuite()
 
741
        try:
 
742
            import_pygtk()
 
743
        except errors.BzrCommandError:
 
744
            return result
633
745
        result.addTest(tests.test_suite())
634
746
    finally:
635
747
        if sys.getdefaultencoding() != default_encoding: