/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 15:13:34 UTC
  • Revision ID: jelmer@samba.org-20070715151334-2t0g8fmpgj6vnqa7
Add icon for Bazaar preferences.

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
19
21
gannotate         GTK+ annotate. 
20
22
gbranch           GTK+ branching. 
21
23
gcheckout         GTK+ checkout. 
22
 
gcommit           GTK+ commit dialog.
23
 
gconflicts        GTK+ conflicts. 
 
24
gcommit           GTK+ commit dialog 
 
25
gconflicts        GTK+ push. 
24
26
gdiff             Show differences in working tree in a GTK+ Window. 
25
27
ginit             Initialise a new branch.
26
28
gmissing          GTK+ missing revisions dialog. 
27
29
gpreferences      GTK+ preferences dialog. 
28
 
gpush             GTK+ push.
29
 
gsend             GTK+ send merge directive.
30
 
gstatus           GTK+ status dialog.
 
30
gpush             GTK+ push. 
 
31
gstatus           GTK+ status dialog 
31
32
gtags             Manage branch tags.
32
33
visualise         Graphically visualise this branch. 
33
34
"""
34
35
 
35
 
import sys
36
 
 
37
36
import bzrlib
38
37
 
39
 
version_info = (0, 93, 0, 'dev', 0)
 
38
__version__ = '0.18.0'
 
39
version_info = tuple(int(n) for n in __version__.split('.'))
40
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
41
 
47
42
def check_bzrlib_version(desired):
48
43
    """Check that bzrlib is compatible.
64
59
        from warnings import warn as warning
65
60
    if bzrlib_version < desired:
66
61
        from bzrlib.errors import BzrError
67
 
        warning('Installed Bazaar version %s is too old to be used with bzr-gtk'
 
62
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
68
63
                ' %s.' % (bzrlib.__version__, __version__))
69
 
        raise BzrError('Version mismatch: %r, %r' % (version_info, bzrlib.version_info) )
 
64
        raise BzrError('Version mismatch: %r' % version_info)
70
65
    else:
71
66
        warning('bzr-gtk is not up to date with installed bzr version %s.'
72
67
                ' \nThere should be a newer version available, e.g. %i.%i.' 
73
68
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
74
69
 
75
70
 
76
 
if version_info[2] == "final":
77
 
    check_bzrlib_version(version_info[:2])
 
71
check_bzrlib_version(version_info[:2])
78
72
 
79
73
from bzrlib.trace import warning
80
74
if __name__ != 'bzrlib.plugins.gtk':
84
78
lazy_import(globals(), """
85
79
from bzrlib import (
86
80
    branch,
87
 
    builtins,
88
81
    errors,
89
82
    workingtree,
90
83
    )
112
105
    bzrlib.ui.ui_factory = GtkUIFactory()
113
106
 
114
107
 
115
 
def data_path():
116
 
    return os.path.dirname(__file__)
117
 
 
118
 
 
119
108
class GTKCommand(Command):
120
109
    """Abstract class providing GTK specific run commands."""
121
110
 
166
155
        (br, path) = branch.Branch.open_containing(location)
167
156
        self.open_display()
168
157
        from push import PushDialog
169
 
        dialog = PushDialog(br.repository, br.last_revision(), br)
 
158
        dialog = PushDialog(br)
170
159
        dialog.run()
171
160
 
172
161
 
228
217
    :return: The viz window object.
229
218
    """
230
219
    from viz.branchwin import BranchWindow
231
 
    return BranchWindow(branch, revision, limit)
 
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
232
226
 
233
227
 
234
228
class cmd_visualise(Command):
250
244
    def run(self, location=".", revision=None, limit=None):
251
245
        set_ui_factory()
252
246
        (br, path) = branch.Branch.open_containing(location)
253
 
        if revision is None:
254
 
            revid = br.last_revision()
255
 
            if revid is None:
256
 
                return
257
 
        else:
258
 
            (revno, revid) = revision[0].in_history(br)
 
247
        br.lock_read()
 
248
        try:
 
249
            if revision is None:
 
250
                revid = br.last_revision()
 
251
                if revid is None:
 
252
                    return
 
253
            else:
 
254
                (revno, revid) = revision[0].in_history(br)
259
255
 
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()
 
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()
 
261
        finally:
 
262
            br.unlock()
265
263
 
266
264
 
267
265
class cmd_gannotate(GTKCommand):
334
332
    """GTK+ commit dialog
335
333
 
336
334
    Graphical user interface for committing revisions"""
337
 
 
 
335
    
338
336
    aliases = [ "gci" ]
339
337
    takes_args = []
340
338
    takes_options = []
353
351
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
354
352
            br = wt.branch
355
353
        except NoWorkingTree, e:
356
 
            from dialog import error_dialog
357
 
            error_dialog(_('Directory does not have a working tree'),
358
 
                         _('Operation aborted.'))
359
 
            return 1 # should this be retval=3?
360
 
 
361
 
        # It is a good habit to keep things locked for the duration, but it
362
 
        # could cause difficulties if someone wants to do things in another
363
 
        # window... We could lock_read() until we actually go to commit
364
 
        # changes... Just a thought.
365
 
        wt.lock_write()
366
 
        try:
367
 
            dlg = CommitDialog(wt)
368
 
            return dlg.run()
369
 
        finally:
370
 
            wt.unlock()
 
354
            path = e.base
 
355
            (br, path) = branch.Branch.open_containing(path)
 
356
 
 
357
        commit = CommitDialog(wt, path, not br)
 
358
        commit.run()
 
359
 
371
360
 
372
361
 
373
362
class cmd_gstatus(GTKCommand):
390
379
        status.run()
391
380
 
392
381
 
393
 
class cmd_gsend(GTKCommand):
394
 
    """GTK+ send merge directive.
395
 
 
396
 
    """
397
 
    def run(self):
398
 
        (br, path) = branch.Branch.open_containing(".")
399
 
        gtk = self.open_display()
400
 
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
401
 
        from StringIO import StringIO
402
 
        dialog = SendMergeDirectiveDialog(br)
403
 
        if dialog.run() == gtk.RESPONSE_OK:
404
 
            outf = StringIO()
405
 
            outf.writelines(dialog.get_merge_directive().to_lines())
406
 
            mail_client = br.get_config().get_mail_client()
407
 
            mail_client.compose_merge_request(dialog.get_mail_to(), "[MERGE]", 
408
 
                outf.getvalue())
409
 
 
410
 
            
411
 
 
412
382
 
413
383
class cmd_gconflicts(GTKCommand):
414
 
    """GTK+ conflicts.
 
384
    """ GTK+ push.
415
385
    
416
 
    Select files from the list of conflicts and run an external utility to
417
 
    resolve them.
418
386
    """
419
387
    def run(self):
420
388
        (wt, path) = workingtree.WorkingTree.open_containing('.')
424
392
        dialog.run()
425
393
 
426
394
 
 
395
 
427
396
class cmd_gpreferences(GTKCommand):
428
397
    """ GTK+ preferences dialog.
429
398
 
435
404
        dialog.run()
436
405
 
437
406
 
 
407
 
438
408
class cmd_gmissing(Command):
439
409
    """ GTK+ missing revisions dialog.
440
410
 
491
461
 
492
462
 
493
463
commands = [
 
464
    cmd_gmissing, 
 
465
    cmd_gpreferences, 
 
466
    cmd_gconflicts, 
 
467
    cmd_gstatus,
 
468
    cmd_gcommit, 
494
469
    cmd_gannotate, 
 
470
    cmd_visualise, 
 
471
    cmd_gdiff,
 
472
    cmd_gpush, 
 
473
    cmd_gcheckout, 
495
474
    cmd_gbranch,
496
 
    cmd_gcheckout, 
497
 
    cmd_gcommit, 
498
 
    cmd_gconflicts, 
499
 
    cmd_gdiff,
500
475
    cmd_ginit,
501
 
    cmd_gmissing, 
502
 
    cmd_gpreferences, 
503
 
    cmd_gpush, 
504
 
    cmd_gsend,
505
 
    cmd_gstatus,
506
 
    cmd_gtags,
507
 
    cmd_visualise
 
476
    cmd_gtags
508
477
    ]
509
478
 
510
479
for cmd in commands:
522
491
        from notify import NotifyPopupMenu
523
492
        gtk = self.open_display()
524
493
        menu = NotifyPopupMenu()
525
 
        icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
 
494
        icon = gtk.status_icon_new_from_file("bzr-icon-64.png")
526
495
        icon.connect('popup-menu', menu.display)
527
496
 
528
497
        import cgi
585
554
register_command(cmd_commit_notify)
586
555
 
587
556
 
588
 
class cmd_gselftest(GTKCommand):
589
 
    """Version of selftest that displays a notification at the end"""
590
 
 
591
 
    takes_args = builtins.cmd_selftest.takes_args
592
 
    takes_options = builtins.cmd_selftest.takes_options
593
 
    _see_also = ['selftest']
594
 
 
595
 
    def run(self, *args, **kwargs):
596
 
        import cgi
597
 
        import sys
598
 
        default_encoding = sys.getdefaultencoding()
599
 
        # prevent gtk from blowing up later
600
 
        gtk = import_pygtk()
601
 
        # prevent gtk from messing with default encoding
602
 
        import pynotify
603
 
        if sys.getdefaultencoding() != default_encoding:
604
 
            reload(sys)
605
 
            sys.setdefaultencoding(default_encoding)
606
 
        result = builtins.cmd_selftest().run(*args, **kwargs)
607
 
        if result == 0:
608
 
            summary = 'Success'
609
 
            body = 'Selftest succeeded in "%s"' % os.getcwd()
610
 
        if result == 1:
611
 
            summary = 'Failure'
612
 
            body = 'Selftest failed in "%s"' % os.getcwd()
613
 
        pynotify.init("bzr gselftest")
614
 
        note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
615
 
        note.set_timeout(pynotify.EXPIRES_NEVER)
616
 
        note.show()
617
 
 
618
 
 
619
 
register_command(cmd_gselftest)
620
 
 
621
 
 
622
 
class cmd_test_gtk(GTKCommand):
623
 
    """Version of selftest that just runs the gtk test suite."""
624
 
 
625
 
    takes_options = ['verbose',
626
 
                     Option('one', short_name='1',
627
 
                            help='Stop when one test fails.'),
628
 
                     Option('benchmark', help='Run the benchmarks.'),
629
 
                     Option('lsprof-timed',
630
 
                     help='Generate lsprof output for benchmarked'
631
 
                          ' sections of code.'),
632
 
                     Option('list-only',
633
 
                     help='List the tests instead of running them.'),
634
 
                     Option('randomize', type=str, argname="SEED",
635
 
                     help='Randomize the order of tests using the given'
636
 
                          ' seed or "now" for the current time.'),
637
 
                    ]
638
 
    takes_args = ['testspecs*']
639
 
 
640
 
    def run(self, verbose=None, one=False, benchmark=None,
641
 
            lsprof_timed=None, list_only=False, randomize=None,
642
 
            testspecs_list=None):
643
 
        from bzrlib import __path__ as bzrlib_path
644
 
        from bzrlib.tests import selftest
645
 
 
646
 
        print '%10s: %s' % ('bzrlib', bzrlib_path[0])
647
 
        if benchmark:
648
 
            print 'No benchmarks yet'
649
 
            return 3
650
 
 
651
 
            test_suite_factory = bench_suite
652
 
            if verbose is None:
653
 
                verbose = True
654
 
            # TODO: should possibly lock the history file...
655
 
            benchfile = open(".perf_history", "at", buffering=1)
656
 
        else:
657
 
            test_suite_factory = test_suite
658
 
            if verbose is None:
659
 
                verbose = False
660
 
            benchfile = None
661
 
 
662
 
        if testspecs_list is not None:
663
 
            pattern = '|'.join(testspecs_list)
664
 
        else:
665
 
            pattern = ".*"
666
 
 
667
 
        try:
668
 
            result = selftest(verbose=verbose,
669
 
                              pattern=pattern,
670
 
                              stop_on_failure=one,
671
 
                              test_suite_factory=test_suite_factory,
672
 
                              lsprof_timed=lsprof_timed,
673
 
                              bench_history=benchfile,
674
 
                              list_only=list_only,
675
 
                              random_seed=randomize,
676
 
                             )
677
 
        finally:
678
 
            if benchfile is not None:
679
 
                benchfile.close()
680
 
 
681
 
register_command(cmd_test_gtk)
682
 
 
683
 
 
684
557
import gettext
685
558
gettext.install('olive-gtk')
686
559
 
699
572
    default_encoding = sys.getdefaultencoding()
700
573
    try:
701
574
        result = TestSuite()
702
 
        try:
703
 
            import_pygtk()
704
 
        except errors.BzrCommandError:
705
 
            return result
706
575
        result.addTest(tests.test_suite())
707
576
    finally:
708
577
        if sys.getdefaultencoding() != default_encoding: