~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2007-06-10 17:55:08 UTC
  • mfrom: (531.2.2 bzrtools)
  • Revision ID: aaron.bentley@utoronto.ca-20070610175508-gex1oxvmfv0qoagi
Merge whitespace cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Aaron Bentley <aaron.bentley@utoronto.ca>
 
1
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron.bentley@utoronto.ca>
2
2
# Copyright (C) 2005, 2006 Canonical Limited.
3
3
# Copyright (C) 2006 Michael Ellerman.
4
4
#
23
23
import bzrlib
24
24
 
25
25
 
26
 
__version__ = '0.14.0'
 
26
__version__ = '0.17.0'
27
27
 
28
28
 
29
29
version_info = tuple(int(n) for n in __version__.split('.'))
39
39
    """
40
40
    desired_plus = (desired[0], desired[1]+1)
41
41
    bzrlib_version = bzrlib.version_info[:2]
42
 
    if bzrlib_version == desired:
 
42
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
 
43
                                     bzrlib.version_info[3] == 'dev'):
43
44
        return
44
45
    try:
45
46
        from bzrlib.trace import warning
47
48
        # get the message out any way we can
48
49
        from warnings import warn as warning
49
50
    if bzrlib_version < desired:
50
 
        warning('Installed bzr version %s is too old to be used with bzrtools'
51
 
                ' %s.' % (bzrlib.__version__, __version__))
 
51
        warning('Installed Bazaar version %s is too old to be used with'
 
52
                ' plugin \n'
 
53
                '"Bzrtools" %s.' % (bzrlib.__version__, __version__))
52
54
        # Not using BzrNewError, because it may not exist.
53
55
        raise Exception, ('Version mismatch', version_info)
54
56
    else:
55
 
        warning('Bzrtools is not up to date with installed bzr version %s.'
56
 
                ' \nThere should be a newer version available, e.g. %i.%i.' 
 
57
        warning('Plugin "Bzrtools" is not up to date with installed Bazaar'
 
58
                ' version %s.\n'
 
59
                ' There should be a newer version of Bzrtools available, e.g.'
 
60
                ' %i.%i.'
57
61
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
58
62
        if bzrlib_version != desired_plus:
59
63
            raise Exception, 'Version mismatch'
61
65
 
62
66
check_bzrlib_version(version_info[:2])
63
67
 
 
68
from bzrlib.lazy_import import lazy_import
 
69
lazy_import(globals(), """
 
70
from bzrlib import help
 
71
import shelf
 
72
""")
64
73
 
65
74
from errors import CommandError, NoPyBaz
66
75
from patchsource import BzrPatchSource
67
 
from shelf import Shelf
68
76
import sys
69
77
import os.path
70
78
 
72
80
import bzrlib.commands
73
81
from bzrlib.commands import get_cmd_object
74
82
from bzrlib.errors import BzrCommandError
75
 
from bzrlib.help import command_usage
76
83
import bzrlib.ignores
77
84
from bzrlib.option import Option
78
 
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), 
 
85
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__),
79
86
                                                 "external")))
80
87
 
81
88
import show_paths
98
105
 
99
106
    To check what clean-tree will do, use --dry-run.
100
107
    """
101
 
    takes_options = [Option('ignored', help='delete all ignored files.'), 
 
108
    takes_options = [Option('ignored', help='delete all ignored files.'),
102
109
                     Option('detritus', help='delete conflict files, merge'
103
 
                            ' backups, and failed selftest dirs.'), 
104
 
                     Option('unknown', 
 
110
                            ' backups, and failed selftest dirs.'),
 
111
                     Option('unknown',
105
112
                            help='delete files unknown to bzr.  (default)'),
106
113
                     Option('dry-run', help='show files to delete instead of'
107
114
                            ' deleting them.')]
125
132
    with the last 5 characters of their revision identifier are used instead.
126
133
 
127
134
    The value starting with d is "(maximum) distance from the null revision".
128
 
    
 
135
 
129
136
    If --merge-branch is specified, the two branches are compared and a merge
130
137
    base is selected.
131
 
    
 
138
 
132
139
    Legend:
133
140
    white    normal revision
134
141
    yellow   THIS  history
149
156
    be disabled with --no-antialias.
150
157
    """
151
158
    takes_args = ['branch', 'file']
152
 
    takes_options = [Option('no-collapse', help="Do not skip simple nodes"), 
 
159
    takes_options = [Option('no-collapse', help="Do not skip simple nodes"),
153
160
                     Option('no-antialias',
154
 
                     help="Do not use rsvg to produce antialiased output"), 
155
 
                     Option('merge-branch', type=str, 
156
 
                     help="Use this branch to calcuate a merge base"), 
 
161
                     help="Do not use rsvg to produce antialiased output"),
 
162
                     Option('merge-branch', type=str,
 
163
                     help="Use this branch to calcuate a merge base"),
157
164
                     Option('cluster', help="Use clustered output."),
158
165
                     Option('max-distance', help="Show no nodes farther than this",
159
166
                            type=int)]
164
171
            ranking = "cluster"
165
172
        else:
166
173
            ranking = "forced"
167
 
        graph.write_ancestry_file(branch, file, not no_collapse, 
168
 
                                  not no_antialias, merge_branch, ranking, 
 
174
        graph.write_ancestry_file(branch, file, not no_collapse,
 
175
                                  not no_antialias, merge_branch, ranking,
169
176
                                  max_distance=max_distance)
170
177
 
171
178
 
188
195
    """Apply a named patch to the current tree.
189
196
    """
190
197
    takes_args = ['filename?']
191
 
    takes_options = [Option('strip', type=int, help=strip_help)]
192
 
    def run(self, filename=None, strip=None):
 
198
    takes_options = [Option('strip', type=int, help=strip_help),
 
199
                     Option('silent', help='Suppress chatter')]
 
200
    def run(self, filename=None, strip=None, silent=False):
193
201
        from patch import patch
194
202
        from bzrlib.workingtree import WorkingTree
195
203
        wt = WorkingTree.open_containing('.')[0]
196
204
        if strip is None:
197
205
            strip = 0
198
 
        return patch(wt, filename, strip)
 
206
        return patch(wt, filename, strip, silent)
199
207
 
200
208
 
201
209
class cmd_shelve(bzrlib.commands.Command):
230
238
 
231
239
    takes_args = ['file*']
232
240
    takes_options = ['message', 'revision',
233
 
            Option('all', help='Shelve all changes without prompting'), 
 
241
            Option('all', help='Shelve all changes without prompting'),
234
242
            Option('no-color', help='Never display changes in color')]
235
243
 
236
244
    def run(self, all=False, file_list=None, message=None, revision=None,
243
251
                                  "parameter.")
244
252
 
245
253
        source = BzrPatchSource(revision, file_list)
246
 
        s = Shelf(source.base)
 
254
        s = shelf.Shelf(source.base)
247
255
        s.shelve(source, all, message, no_color)
248
256
        return 0
249
257
 
271
279
    aliases = ['switch']
272
280
    takes_args = ['othershelf']
273
281
    def run(self, othershelf):
274
 
        s = Shelf(self.shelf.base, othershelf)
 
282
        s = shelf.Shelf(self.shelf.base, othershelf)
275
283
        s.make_default()
276
284
 
277
285
 
304
312
            args_list = []
305
313
        cmd = self._get_cmd_object(subcommand)
306
314
        source = BzrPatchSource()
307
 
        s = Shelf(source.base)
 
315
        s = shelf.Shelf(source.base)
308
316
        cmd.shelf = s
 
317
 
 
318
        if args_list is None:
 
319
            args_list = []
309
320
        return cmd.run_argv_aliases(args_list)
310
321
 
311
322
    def _get_cmd_object(self, cmd_name):
328
339
        cmd_obj = cmd_class()
329
340
        indent = 2 * ' '
330
341
 
331
 
        usage = command_usage(cmd_obj)
 
342
        usage = cmd_obj._usage()
332
343
        usage = usage.replace('bzr shelf-', '')
333
344
        text.append('%s%s\n' % (indent, usage))
334
345
 
369
380
    takes_args = ['patch?']
370
381
    def run(self, patch=None, all=False, force=False, no_color=False):
371
382
        source = BzrPatchSource()
372
 
        s = Shelf(source.base)
 
383
        s = shelf.Shelf(source.base)
373
384
        s.unshelve(source, patch, all, force, no_color)
374
385
        return 0
375
386
 
407
418
    """
408
419
    takes_args = ["branch?"]
409
420
    def run(self, branch=None):
410
 
        from branchhistory import branch_history 
 
421
        from branchhistory import branch_history
411
422
        return branch_history(branch)
412
423
 
413
424
 
433
444
class cmd_cbranch(bzrlib.commands.Command):
434
445
    """
435
446
    Create a new checkout, associated with a new repository branch.
436
 
    
 
447
 
437
448
    When you cbranch, bzr looks up a target location in locations.conf, and
438
449
    creates the branch there.
439
450
 
443
454
    cbranch_target:policy = appendpath
444
455
 
445
456
    This will mean that if you run "bzr cbranch foo/bar foo/baz" in the
446
 
    working directory root, the branch will be created in 
 
457
    working directory root, the branch will be created in
447
458
    "/branch_root/foo/baz"
448
459
 
449
460
    NOTE: cbranch also supports "cbranch_root", but that behaviour is
450
461
    deprecated.
451
462
    """
452
 
    takes_options = [Option("lightweight", 
 
463
    takes_options = [Option("lightweight",
453
464
                            help="Create a lightweight checkout"), 'revision']
454
465
    takes_args = ["source", "target?"]
455
466
    def run(self, source, target=None, lightweight=False, revision=None):
456
467
        from cbranch import cbranch
457
 
        return cbranch(source, target, lightweight=lightweight, 
 
468
        return cbranch(source, target, lightweight=lightweight,
458
469
                       revision=revision)
459
470
 
460
471
 
468
479
 
469
480
class cmd_multi_pull(bzrlib.commands.Command):
470
481
    """Pull all the branches under a location, e.g. a repository.
471
 
    
 
482
 
472
483
    Both branches present in the directory and the branches of checkouts are
473
484
    pulled.
474
485
    """
526
537
 
527
538
class cmd_import(bzrlib.commands.Command):
528
539
    """Import sources from a directory, tarball or zip file
529
 
    
 
540
 
530
541
    This command will import a directory, tarball or zip file into a bzr
531
542
    tree, replacing any versioned files already present.  If a directory is
532
543
    specified, it is used as the target.  If the directory does not exist, or
537
548
    If the tarball or zip has a single root directory, that directory is
538
549
    stripped when extracting the tarball.  This is not done for directories.
539
550
    """
540
 
    
 
551
 
541
552
    takes_args = ['source', 'tree?']
542
553
    def run(self, source, tree=None):
543
554
        from upstream_import import do_import
547
558
class cmd_cdiff(bzrlib.commands.Command):
548
559
    """A color version of bzr's diff"""
549
560
    takes_args = property(lambda x: get_cmd_object('diff').takes_args)
550
 
    takes_options = property(lambda x: get_cmd_object('diff').takes_options)
551
 
    def run(*args, **kwargs):
 
561
 
 
562
    def _takes_options(self):
 
563
        options = list(get_cmd_object('diff').takes_options)
 
564
        options.append(Option('check-style',
 
565
            help='Warn if trailing whitespace or spurious changes have been'
 
566
                 ' added.'))
 
567
        return options
 
568
 
 
569
    takes_options = property(_takes_options)
 
570
 
 
571
    def run(self, check_style=False, *args, **kwargs):
552
572
        from colordiff import colordiff
553
 
        colordiff(*args, **kwargs)
 
573
        colordiff(check_style, *args, **kwargs)
554
574
 
555
575
 
556
576
class cmd_baz_import(bzrlib.commands.Command):
558
578
 
559
579
    This command should be used on local archives (or mirrors) only.  It is
560
580
    quite slow on remote archives.
561
 
    
562
 
    reuse_history allows you to specify any previous imports you 
 
581
 
 
582
    reuse_history allows you to specify any previous imports you
563
583
    have done of different archives, which this archive has branches
564
 
    tagged from. This will dramatically reduce the time to convert 
 
584
    tagged from. This will dramatically reduce the time to convert
565
585
    the archive as it will not have to convert the history already
566
586
    converted in that other branch.
567
587
 
581
601
    takes_args = ['to_root_dir', 'from_archive', 'reuse_history*']
582
602
    takes_options = ['verbose', Option('prefixes', type=str,
583
603
                     help="Prefixes of branches to import, colon-separated"),
584
 
                     Option('encoding', type=str, 
 
604
                     Option('encoding', type=str,
585
605
                     help='Force encoding to specified value.  See WARNING.')]
586
606
 
587
607
    def run(self, to_root_dir, from_archive, encoding=None, verbose=False,
607
627
    """
608
628
    takes_args = ['to_location', 'from_branch?', 'reuse_history*']
609
629
    takes_options = ['verbose', Option('max-count', type=int),
610
 
                     Option('encoding', type=str, 
 
630
                     Option('encoding', type=str,
611
631
                     help='Force encoding to specified value.  See WARNING.')]
612
632
 
613
633
    def run(self, to_location, from_branch=None, fast=False, max_count=None,
616
636
        from errors import NoPyBaz
617
637
        try:
618
638
            import baz_import
619
 
            baz_import.baz_import_branch(to_location, from_branch, fast, 
 
639
            baz_import.baz_import_branch(to_location, from_branch, fast,
620
640
                                         max_count, verbose, encoding, dry_run,
621
641
                                         reuse_history_list)
622
642
        except NoPyBaz:
626
646
class cmd_rspush(bzrlib.commands.Command):
627
647
    """Upload this branch to another location using rsync.
628
648
 
629
 
    If no location is specified, the last-used location will be used.  To 
630
 
    prevent dirty trees from being uploaded, rspush will error out if there are 
631
 
    unknown files or local changes.  It will also error out if the upstream 
632
 
    directory is non-empty and not an earlier version of the branch. 
 
649
    If no location is specified, the last-used location will be used.  To
 
650
    prevent dirty trees from being uploaded, rspush will error out if there are
 
651
    unknown files or local changes.  It will also error out if the upstream
 
652
    directory is non-empty and not an earlier version of the branch.
633
653
    """
634
654
    takes_args = ['location?']
635
655
    takes_options = [Option('overwrite', help='Ignore differences between'
641
661
        from bzrlib import workingtree
642
662
        import bzrtools
643
663
        cur_branch = workingtree.WorkingTree.open_containing(".")[0]
644
 
        bzrtools.rspush(cur_branch, location, overwrite=overwrite, 
 
664
        bzrtools.rspush(cur_branch, location, overwrite=overwrite,
645
665
                      working_tree=not no_tree)
646
666
 
647
667
 
661
681
            cmd_branches,
662
682
            cmd_branch_history,
663
683
            cmd_branch_mark,
664
 
            cmd_cbranch,  
 
684
            cmd_cbranch,
665
685
            cmd_cdiff,
666
686
            cmd_clean_tree,
667
687
            cmd_fetch_ghosts,
670
690
            cmd_multi_pull,
671
691
            cmd_patch,
672
692
            cmd_rspush,
673
 
            cmd_shelf, 
 
693
            cmd_shelf,
674
694
            cmd_shell,
675
 
            cmd_shelve, 
 
695
            cmd_shelve,
676
696
            cmd_switch,
677
 
            cmd_unshelve, 
678
 
            cmd_zap,            
 
697
            cmd_unshelve,
 
698
            cmd_zap,
679
699
            ]
680
700
 
681
701
 
691
711
    from unittest import TestSuite
692
712
    import bzrtools
693
713
    import tests.clean_tree
 
714
    import tests.is_clean
694
715
    import tests.upstream_import
695
716
    import zap
696
717
    import tests.blackbox
708
729
    result.addTest(tests.blackbox.test_suite())
709
730
    result.addTest(tests.upstream_import.test_suite())
710
731
    result.addTest(zap.test_suite())
 
732
    result.addTest(TestLoader().loadTestsFromModule(tests.is_clean))
711
733
    return result