/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:12:49 UTC
  • mto: (423.1.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 429.
  • Revision ID: daniel.schierbeck@gmail.com-20080113141249-gd0i2lknr3yik55r
Moved branch view to its own package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
gannotate         GTK+ annotate. 
20
20
gbranch           GTK+ branching. 
21
21
gcheckout         GTK+ checkout. 
22
 
gcommit           GTK+ commit dialog 
23
 
gconflicts        GTK+ push. 
 
22
gcommit           GTK+ commit dialog.
 
23
gconflicts        GTK+ conflicts. 
24
24
gdiff             Show differences in working tree in a GTK+ Window. 
25
25
ginit             Initialise a new branch.
26
26
gmissing          GTK+ missing revisions dialog. 
27
27
gpreferences      GTK+ preferences dialog. 
28
 
gpush             GTK+ push. 
29
 
gstatus           GTK+ status dialog 
 
28
gpush             GTK+ push.
 
29
gsend             GTK+ send merge directive.
 
30
gstatus           GTK+ status dialog.
30
31
gtags             Manage branch tags.
31
32
visualise         Graphically visualise this branch. 
32
33
"""
33
34
 
 
35
import sys
 
36
 
34
37
import bzrlib
35
38
 
36
 
__version__ = '0.19.0'
37
 
version_info = tuple(int(n) for n in __version__.split('.'))
38
 
 
 
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)
39
48
 
40
49
def check_bzrlib_version(desired):
41
50
    """Check that bzrlib is compatible.
42
51
 
43
52
    If version is < bzr-gtk version, assume incompatible.
44
 
    If version == bzr-gtk version, assume completely compatible
45
 
    If version == bzr-gtk version + 1, assume compatible, with deprecations
46
 
    Otherwise, assume incompatible.
47
53
    """
48
 
    desired_plus = (desired[0], desired[1]+1)
49
54
    bzrlib_version = bzrlib.version_info[:2]
50
 
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
51
 
                                     bzrlib.version_info[3] == 'dev'):
52
 
        return
53
55
    try:
54
56
        from bzrlib.trace import warning
55
57
    except ImportError:
57
59
        from warnings import warn as warning
58
60
    if bzrlib_version < desired:
59
61
        from bzrlib.errors import BzrError
60
 
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
 
62
        warning('Installed Bazaar version %s is too old to be used with bzr-gtk'
61
63
                ' %s.' % (bzrlib.__version__, __version__))
62
 
        raise BzrError('Version mismatch: %r' % version_info)
63
 
    else:
64
 
        warning('bzr-gtk is not up to date with installed bzr version %s.'
65
 
                ' \nThere should be a newer version available, e.g. %i.%i.' 
66
 
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
67
 
 
68
 
 
69
 
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)
70
69
 
71
70
from bzrlib.trace import warning
72
71
if __name__ != 'bzrlib.plugins.gtk':
76
75
lazy_import(globals(), """
77
76
from bzrlib import (
78
77
    branch,
 
78
    builtins,
79
79
    errors,
80
80
    workingtree,
81
81
    )
103
103
    bzrlib.ui.ui_factory = GtkUIFactory()
104
104
 
105
105
 
 
106
def data_path():
 
107
    return os.path.dirname(__file__)
 
108
 
 
109
 
106
110
class GTKCommand(Command):
107
111
    """Abstract class providing GTK specific run commands."""
108
112
 
215
219
    :return: The viz window object.
216
220
    """
217
221
    from viz.branchwin import BranchWindow
218
 
    branch.lock_read()
219
 
    pp = BranchWindow()
220
 
    pp.set_branch(branch, revision, limit)
221
 
    # cleanup locks when the window is closed
222
 
    pp.connect("destroy", lambda w: branch.unlock())
223
 
    return pp
 
222
    return BranchWindow(branch, revision, limit)
224
223
 
225
224
 
226
225
class cmd_visualise(Command):
242
241
    def run(self, location=".", revision=None, limit=None):
243
242
        set_ui_factory()
244
243
        (br, path) = branch.Branch.open_containing(location)
245
 
        br.lock_read()
246
 
        try:
247
 
            if revision is None:
248
 
                revid = br.last_revision()
249
 
                if revid is None:
250
 
                    return
251
 
            else:
252
 
                (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)
253
250
 
254
 
            import gtk
255
 
            pp = start_viz_window(br, revid, limit)
256
 
            pp.connect("destroy", lambda w: gtk.main_quit())
257
 
            pp.show()
258
 
            gtk.main()
259
 
        finally:
260
 
            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()
261
256
 
262
257
 
263
258
class cmd_gannotate(GTKCommand):
330
325
    """GTK+ commit dialog
331
326
 
332
327
    Graphical user interface for committing revisions"""
333
 
    
 
328
 
334
329
    aliases = [ "gci" ]
335
330
    takes_args = []
336
331
    takes_options = []
349
344
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
350
345
            br = wt.branch
351
346
        except NoWorkingTree, e:
352
 
            path = e.base
353
 
            (br, path) = branch.Branch.open_containing(path)
354
 
 
355
 
        commit = CommitDialog(wt, path, not br)
356
 
        commit.run()
357
 
 
 
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()
358
362
 
359
363
 
360
364
class cmd_gstatus(GTKCommand):
377
381
        status.run()
378
382
 
379
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
 
380
403
 
381
404
class cmd_gconflicts(GTKCommand):
382
 
    """ GTK+ push.
 
405
    """GTK+ conflicts.
383
406
    
 
407
    Select files from the list of conflicts and run an external utility to
 
408
    resolve them.
384
409
    """
385
410
    def run(self):
386
411
        (wt, path) = workingtree.WorkingTree.open_containing('.')
390
415
        dialog.run()
391
416
 
392
417
 
393
 
 
394
418
class cmd_gpreferences(GTKCommand):
395
419
    """ GTK+ preferences dialog.
396
420
 
402
426
        dialog.run()
403
427
 
404
428
 
405
 
 
406
429
class cmd_gmissing(Command):
407
430
    """ GTK+ missing revisions dialog.
408
431
 
459
482
 
460
483
 
461
484
commands = [
 
485
    cmd_gannotate, 
 
486
    cmd_gbranch,
 
487
    cmd_gcheckout, 
 
488
    cmd_gcommit, 
 
489
    cmd_gconflicts, 
 
490
    cmd_gdiff,
 
491
    cmd_ginit,
462
492
    cmd_gmissing, 
463
493
    cmd_gpreferences, 
464
 
    cmd_gconflicts, 
 
494
    cmd_gpush, 
 
495
    cmd_gsend,
465
496
    cmd_gstatus,
466
 
    cmd_gcommit, 
467
 
    cmd_gannotate, 
468
 
    cmd_visualise, 
469
 
    cmd_gdiff,
470
 
    cmd_gpush, 
471
 
    cmd_gcheckout, 
472
 
    cmd_gbranch,
473
 
    cmd_ginit,
474
 
    cmd_gtags
 
497
    cmd_gtags,
 
498
    cmd_visualise
475
499
    ]
476
500
 
477
501
for cmd in commands:
489
513
        from notify import NotifyPopupMenu
490
514
        gtk = self.open_display()
491
515
        menu = NotifyPopupMenu()
492
 
        icon = gtk.status_icon_new_from_file("bzr-icon-64.png")
 
516
        icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
493
517
        icon.connect('popup-menu', menu.display)
494
518
 
495
519
        import cgi
552
576
register_command(cmd_commit_notify)
553
577
 
554
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
 
555
675
import gettext
556
676
gettext.install('olive-gtk')
557
677
 
570
690
    default_encoding = sys.getdefaultencoding()
571
691
    try:
572
692
        result = TestSuite()
 
693
        try:
 
694
            import_pygtk()
 
695
        except errors.BzrCommandError:
 
696
            return result
573
697
        result.addTest(tests.test_suite())
574
698
    finally:
575
699
        if sys.getdefaultencoding() != default_encoding: