/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-23 16:36:21 UTC
  • mto: (423.1.8 trunk)
  • mto: This revision was merged to the branch mainline in revision 429.
  • Revision ID: daniel.schierbeck@gmail.com-20080123163621-x8kublc38ojipnly
Made the revision popup menu correctly add tags.

Show diffs side-by-side

added added

removed removed

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