/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 
 
22
gcommit           GTK+ commit dialog.
23
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.91.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:
59
61
        from bzrlib.errors import BzrError
60
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':
220
219
    :return: The viz window object.
221
220
    """
222
221
    from viz.branchwin import BranchWindow
223
 
    branch.lock_read()
224
 
    pp = BranchWindow()
225
 
    pp.set_branch(branch, revision, limit)
226
 
    # cleanup locks when the window is closed
227
 
    pp.connect("destroy", lambda w: branch.unlock())
228
 
    return pp
 
222
    return BranchWindow(branch, revision, limit)
229
223
 
230
224
 
231
225
class cmd_visualise(Command):
247
241
    def run(self, location=".", revision=None, limit=None):
248
242
        set_ui_factory()
249
243
        (br, path) = branch.Branch.open_containing(location)
250
 
        br.lock_read()
251
 
        try:
252
 
            if revision is None:
253
 
                revid = br.last_revision()
254
 
                if revid is None:
255
 
                    return
256
 
            else:
257
 
                (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)
258
250
 
259
 
            import gtk
260
 
            pp = start_viz_window(br, revid, limit)
261
 
            pp.connect("destroy", lambda w: gtk.main_quit())
262
 
            pp.show()
263
 
            gtk.main()
264
 
        finally:
265
 
            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()
266
256
 
267
257
 
268
258
class cmd_gannotate(GTKCommand):
335
325
    """GTK+ commit dialog
336
326
 
337
327
    Graphical user interface for committing revisions"""
338
 
    
 
328
 
339
329
    aliases = [ "gci" ]
340
330
    takes_args = []
341
331
    takes_options = []
354
344
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
355
345
            br = wt.branch
356
346
        except NoWorkingTree, e:
357
 
            path = e.base
358
 
            (br, path) = branch.Branch.open_containing(path)
359
 
 
360
 
        commit = CommitDialog(wt, path, not br)
361
 
        commit.run()
362
 
 
 
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()
363
362
 
364
363
 
365
364
class cmd_gstatus(GTKCommand):
382
381
        status.run()
383
382
 
384
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
 
385
403
 
386
404
class cmd_gconflicts(GTKCommand):
387
 
    """ GTK+ conflicts.
 
405
    """GTK+ conflicts.
388
406
    
389
407
    Select files from the list of conflicts and run an external utility to
390
408
    resolve them.
397
415
        dialog.run()
398
416
 
399
417
 
400
 
 
401
418
class cmd_gpreferences(GTKCommand):
402
419
    """ GTK+ preferences dialog.
403
420
 
409
426
        dialog.run()
410
427
 
411
428
 
412
 
 
413
429
class cmd_gmissing(Command):
414
430
    """ GTK+ missing revisions dialog.
415
431
 
466
482
 
467
483
 
468
484
commands = [
 
485
    cmd_gannotate, 
 
486
    cmd_gbranch,
 
487
    cmd_gcheckout, 
 
488
    cmd_gcommit, 
 
489
    cmd_gconflicts, 
 
490
    cmd_gdiff,
 
491
    cmd_ginit,
469
492
    cmd_gmissing, 
470
493
    cmd_gpreferences, 
471
 
    cmd_gconflicts, 
 
494
    cmd_gpush, 
 
495
    cmd_gsend,
472
496
    cmd_gstatus,
473
 
    cmd_gcommit, 
474
 
    cmd_gannotate, 
475
 
    cmd_visualise, 
476
 
    cmd_gdiff,
477
 
    cmd_gpush, 
478
 
    cmd_gcheckout, 
479
 
    cmd_gbranch,
480
 
    cmd_ginit,
481
 
    cmd_gtags
 
497
    cmd_gtags,
 
498
    cmd_visualise
482
499
    ]
483
500
 
484
501
for cmd in commands:
593
610
register_command(cmd_gselftest)
594
611
 
595
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
 
596
675
import gettext
597
676
gettext.install('olive-gtk')
598
677
 
611
690
    default_encoding = sys.getdefaultencoding()
612
691
    try:
613
692
        result = TestSuite()
 
693
        try:
 
694
            import_pygtk()
 
695
        except errors.BzrCommandError:
 
696
            return result
614
697
        result.addTest(tests.test_suite())
615
698
    finally:
616
699
        if sys.getdefaultencoding() != default_encoding: