~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2007-12-22 02:01:03 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20071222020103-ggjszok7n974e1l2
Update branches, multi-pull to new APIs, create trees

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import bzrlib
24
24
 
25
 
 
26
 
__version__ = '0.18.0'
27
 
 
28
 
 
29
 
version_info = tuple(int(n) for n in __version__.split('.'))
30
 
 
31
 
 
32
 
def check_bzrlib_version(desired):
33
 
    """Check that bzrlib is compatible.
34
 
 
35
 
    If version is < bzrtools version, assume incompatible.
36
 
    If version == bzrtools version, assume completely compatible
37
 
    If version == bzrtools version + 1, assume compatible, with deprecations
38
 
    Otherwise, assume incompatible.
39
 
    """
40
 
    desired_plus = (desired[0], desired[1]+1)
41
 
    bzrlib_version = bzrlib.version_info[:2]
42
 
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
43
 
                                     bzrlib.version_info[3] == 'dev'):
44
 
        return
45
 
    try:
46
 
        from bzrlib.trace import warning
47
 
    except ImportError:
48
 
        # get the message out any way we can
49
 
        from warnings import warn as warning
50
 
    if bzrlib_version < desired:
51
 
        warning('Installed Bazaar version %s is too old to be used with'
52
 
                ' plugin \n'
53
 
                '"Bzrtools" %s.' % (bzrlib.__version__, __version__))
54
 
        # Not using BzrNewError, because it may not exist.
55
 
        raise Exception, ('Version mismatch', version_info)
56
 
    else:
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.'
61
 
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
62
 
        if bzrlib_version != desired_plus:
63
 
            raise Exception, 'Version mismatch'
64
 
 
65
 
 
66
 
check_bzrlib_version(version_info[:2])
67
 
 
68
25
from bzrlib.lazy_import import lazy_import
69
26
lazy_import(globals(), """
70
 
from bzrlib import help
 
27
from bzrlib import help, urlutils
71
28
import shelf
72
29
""")
73
30
 
 
31
from version import version_info, __version__
 
32
from command import BzrToolsCommand
74
33
from errors import CommandError, NoPyBaz
75
34
from patchsource import BzrPatchSource
76
35
import sys
78
37
 
79
38
import bzrlib.builtins
80
39
import bzrlib.commands
 
40
from bzrlib.branch import Branch
 
41
from bzrlib.bzrdir import BzrDir
81
42
from bzrlib.commands import get_cmd_object
82
43
from bzrlib.errors import BzrCommandError
83
44
import bzrlib.ignores
 
45
from bzrlib.trace import note
84
46
from bzrlib.option import Option
85
47
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__),
86
48
                                                 "external")))
87
49
 
88
50
import show_paths
 
51
from command import BzrToolsCommand
89
52
 
90
53
bzrlib.ignores.add_runtime_ignores(['./.shelf'])
91
54
 
92
55
 
93
 
class cmd_clean_tree(bzrlib.commands.Command):
 
56
class cmd_clean_tree(BzrToolsCommand):
94
57
    """Remove unwanted files from working tree.
95
58
 
96
59
    By default, only unknown files, not ignored files, are deleted.  Versioned
105
68
 
106
69
    To check what clean-tree will do, use --dry-run.
107
70
    """
108
 
    takes_options = [Option('ignored', help='delete all ignored files.'),
109
 
                     Option('detritus', help='delete conflict files, merge'
 
71
    takes_options = [Option('ignored', help='Delete all ignored files.'),
 
72
                     Option('detritus', help='Delete conflict files, merge'
110
73
                            ' backups, and failed selftest dirs.'),
111
74
                     Option('unknown',
112
 
                            help='delete files unknown to bzr.  (default)'),
113
 
                     Option('dry-run', help='show files to delete instead of'
 
75
                            help='Delete files unknown to bzr (default).'),
 
76
                     Option('dry-run', help='Show files to delete instead of'
114
77
                            ' deleting them.')]
115
78
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False):
116
79
        from clean_tree import clean_tree
120
83
                   dry_run=dry_run)
121
84
 
122
85
 
123
 
class cmd_graph_ancestry(bzrlib.commands.Command):
 
86
class cmd_graph_ancestry(BzrToolsCommand):
124
87
    """Produce ancestry graphs using dot.
125
88
    
126
89
    Output format is detected according to file extension.  Some of the more
156
119
    be disabled with --no-antialias.
157
120
    """
158
121
    takes_args = ['file', 'merge_branch?']
159
 
    takes_options = [Option('no-collapse', help="Do not skip simple nodes"),
 
122
    takes_options = [Option('no-collapse', help="Do not skip simple nodes."),
160
123
                     Option('no-antialias',
161
 
                     help="Do not use rsvg to produce antialiased output"),
 
124
                     help="Do not use rsvg to produce antialiased output."),
162
125
                     Option('merge-branch', type=str,
163
 
                     help="Use this branch to calcuate a merge base"),
 
126
                     help="Use this branch to calcuate a merge base."),
164
127
                     Option('cluster', help="Use clustered output."),
165
128
                     Option('max-distance',
166
 
                            help="Show no nodes farther than this", type=int),
 
129
                            help="Show no nodes farther than this.", type=int),
167
130
                     Option('directory',
168
131
                            help='Source branch to use (default is current'
169
 
                            ' directory)',
 
132
                            ' directory).',
170
133
                            short_name='d',
171
134
                            type=unicode),
172
135
                    ]
185
148
                                  max_distance=max_distance)
186
149
 
187
150
 
188
 
class cmd_fetch_ghosts(bzrlib.commands.Command):
 
151
class cmd_fetch_ghosts(BzrToolsCommand):
189
152
    """Attempt to retrieve ghosts from another branch.
190
153
    If the other branch is not supplied, the last-pulled branch is used.
191
154
    """
192
155
    aliases = ['fetch-missing']
193
156
    takes_args = ['branch?']
194
 
    takes_options = [Option('no-fix')]
 
157
    takes_options = [Option('no-fix', help="Skip additional synchonization.")]
195
158
    def run(self, branch=None, no_fix=False):
196
159
        from fetch_ghosts import fetch_ghosts
197
160
        fetch_ghosts(branch, no_fix)
200
163
each file name found in the patch file."""
201
164
 
202
165
 
203
 
class cmd_patch(bzrlib.commands.Command):
 
166
class cmd_patch(BzrToolsCommand):
204
167
    """Apply a named patch to the current tree.
205
168
    """
206
169
    takes_args = ['filename?']
207
170
    takes_options = [Option('strip', type=int, help=strip_help),
208
 
                     Option('silent', help='Suppress chatter')]
 
171
                     Option('silent', help='Suppress chatter.')]
209
172
    def run(self, filename=None, strip=None, silent=False):
210
173
        from patch import patch
211
174
        from bzrlib.workingtree import WorkingTree
215
178
        return patch(wt, filename, strip, silent)
216
179
 
217
180
 
218
 
class cmd_shelve(bzrlib.commands.Command):
 
181
class cmd_shelve(BzrToolsCommand):
219
182
    """Temporarily set aside some changes from the current tree.
220
183
 
221
184
    Shelve allows you to temporarily put changes you've made "on the shelf",
246
209
    """
247
210
 
248
211
    takes_args = ['file*']
249
 
    takes_options = ['message', 'revision',
250
 
            Option('all', help='Shelve all changes without prompting'),
251
 
            Option('no-color', help='Never display changes in color')]
 
212
    takes_options = [Option('message',
 
213
            help='A message to associate with the shelved changes.',
 
214
            short_name='m', type=unicode),
 
215
            'revision',
 
216
            Option('all', help='Shelve all changes without prompting.'),
 
217
            Option('no-color', help='Never display changes in color.')]
252
218
 
253
219
    def run(self, all=False, file_list=None, message=None, revision=None,
254
220
            no_color=False):
307
273
        self.shelf.upgrade()
308
274
 
309
275
 
310
 
class cmd_shelf(bzrlib.commands.Command):
 
276
class cmd_shelf(BzrToolsCommand):
311
277
    """Perform various operations on your shelved patches. See also shelve."""
312
278
    takes_args = ['subcommand', 'args*']
313
279
 
373
339
        return text
374
340
 
375
341
 
376
 
class cmd_unshelve(bzrlib.commands.Command):
 
342
class cmd_unshelve(BzrToolsCommand):
377
343
    """Restore shelved changes.
378
344
 
379
345
    By default the most recently shelved changes are restored. However if you
382
348
    See 'shelve' for more information.
383
349
    """
384
350
    takes_options = [
385
 
            Option('all', help='Unshelve all changes without prompting'),
386
 
            Option('force', help='Force unshelving even if errors occur'),
387
 
            Option('no-color', help='Never display changes in color')
 
351
            Option('all', help='Unshelve all changes without prompting.'),
 
352
            Option('force', help='Force unshelving even if errors occur.'),
 
353
            Option('no-color', help='Never display changes in color.')
388
354
        ]
389
355
    takes_args = ['patch?']
390
356
    def run(self, patch=None, all=False, force=False, no_color=False):
394
360
        return 0
395
361
 
396
362
 
397
 
class cmd_shell(bzrlib.commands.Command):
 
363
class cmd_shell(BzrToolsCommand):
398
364
    """Begin an interactive shell tailored for bzr.
399
365
    Bzr commands can be used without typing bzr first, and will be run natively
400
366
    when possible.  Tab completion is tailored for bzr.  The shell prompt shows
417
383
        return shell.run_shell()
418
384
 
419
385
 
420
 
class cmd_branch_history(bzrlib.commands.Command):
 
386
class cmd_branch_history(BzrToolsCommand):
421
387
    """\
422
388
    Display the development history of a branch.
423
389
 
431
397
        return branch_history(branch)
432
398
 
433
399
 
434
 
class cmd_zap(bzrlib.commands.Command):
 
400
class cmd_zap(BzrToolsCommand):
435
401
    """\
436
402
    Remove a lightweight checkout, if it can be done safely.
437
403
 
442
408
    If --branch is specified, the branch will be deleted too, but only if the
443
409
    the branch has no new commits (relative to its parent).
444
410
    """
445
 
    takes_options = [Option("branch", help="Remove associtated branch from"
446
 
                                           " repository")]
 
411
    takes_options = [Option("branch", help="Remove associated branch from"
 
412
                                           " repository."),
 
413
                     Option('force', help='Delete tree even if contents are'
 
414
                     ' modified.')]
447
415
    takes_args = ["checkout"]
448
 
    def run(self, checkout, branch=False):
 
416
    def run(self, checkout, branch=False, force=False):
449
417
        from zap import zap
450
 
        return zap(checkout, remove_branch=branch)
451
 
 
452
 
 
453
 
class cmd_cbranch(bzrlib.commands.Command):
 
418
        return zap(checkout, remove_branch=branch, allow_modified=force)
 
419
 
 
420
 
 
421
class cmd_cbranch(BzrToolsCommand):
454
422
    """
455
423
    Create a new checkout, associated with a new repository branch.
456
424
 
470
438
    deprecated.
471
439
    """
472
440
    takes_options = [Option("lightweight",
473
 
                            help="Create a lightweight checkout"), 'revision']
 
441
                            help="Create a lightweight checkout."), 'revision',
 
442
                     Option('files-from', type=unicode,
 
443
                            help='Accelerate checkout using files from this'
 
444
                                 ' tree.')]
474
445
    takes_args = ["source", "target?"]
475
 
    def run(self, source, target=None, lightweight=False, revision=None):
 
446
    def run(self, source, target=None, lightweight=False, revision=None,
 
447
            files_from=None):
476
448
        from cbranch import cbranch
477
449
        return cbranch(source, target, lightweight=lightweight,
478
 
                       revision=revision)
479
 
 
480
 
 
481
 
class cmd_branches(bzrlib.commands.Command):
 
450
                       revision=revision, files_from=files_from)
 
451
 
 
452
 
 
453
class cmd_branches(BzrToolsCommand):
482
454
    """Scan a location for branches"""
483
455
    takes_args = ["location?"]
484
456
    def run(self, location=None):
485
457
        from branches import branches
486
458
        return branches(location)
487
459
 
 
460
class cmd_trees(BzrToolsCommand):
 
461
    """Scan a location for trees"""
 
462
    takes_args = ['location?']
 
463
    def run(self, location='.'):
 
464
        from bzrlib.workingtree import WorkingTree
 
465
        from bzrlib.transport import get_transport
 
466
        t = get_transport(location)
 
467
        for tree in WorkingTree.find_trees(location):
 
468
            self.outf.write('%s\n' % t.relpath(
 
469
                tree.bzrdir.root_transport.base))
488
470
 
489
 
class cmd_multi_pull(bzrlib.commands.Command):
 
471
class cmd_multi_pull(BzrToolsCommand):
490
472
    """Pull all the branches under a location, e.g. a repository.
491
473
 
492
474
    Both branches present in the directory and the branches of checkouts are
494
476
    """
495
477
    takes_args = ["location?"]
496
478
    def run(self, location=None):
497
 
        from bzrlib.branch import Branch
498
479
        from bzrlib.transport import get_transport
499
480
        from bzrtools import iter_branch_tree
500
481
        if location is None:
501
482
            location = '.'
502
483
        t = get_transport(location)
 
484
        possible_transports = []
503
485
        if not t.listable():
504
486
            print "Can't list this type of location."
505
487
            return 3
521
503
                relpath = base
522
504
            print "Pulling %s from %s" % (relpath, parent)
523
505
            try:
524
 
                pullable.pull(Branch.open(parent))
 
506
                branch_t = get_transport(parent, possible_transports)
 
507
                pullable.pull(Branch.open_from_transport(branch_t))
525
508
            except Exception, e:
526
509
                print e
527
510
 
528
511
 
529
 
class cmd_branch_mark(bzrlib.commands.Command):
530
 
    """
531
 
    Add, view or list branch markers <EXPERIMENTAL>
532
 
 
533
 
    To add a mark, do 'bzr branch-mark MARK'.
534
 
    To list marks, do 'bzr branch-mark' (this lists all marks for the branch's
535
 
    repository).
536
 
    To delete a mark, do 'bzr branch-mark --delete MARK'
537
 
 
538
 
    These marks can be used to track a branch's status.
539
 
    """
540
 
    takes_args = ['mark?', 'branch?']
541
 
    takes_options = [Option('delete', help='Delete this mark')]
542
 
    def run(self, mark=None, branch=None, delete=False):
543
 
        from branch_mark import branch_mark
544
 
        branch_mark(mark, branch, delete)
545
 
 
546
 
 
547
 
class cmd_import(bzrlib.commands.Command):
 
512
 
 
513
class cmd_import(BzrToolsCommand):
548
514
    """Import sources from a directory, tarball or zip file
549
515
 
550
516
    This command will import a directory, tarball or zip file into a bzr
564
530
        do_import(source, tree)
565
531
 
566
532
 
567
 
class cmd_cdiff(bzrlib.commands.Command):
 
533
class cmd_cdiff(BzrToolsCommand):
568
534
    """A color version of bzr's diff"""
569
535
    takes_args = property(lambda x: get_cmd_object('diff').takes_args)
570
 
 
571
 
    def _takes_options(self):
572
 
        options = list(get_cmd_object('diff').takes_options)
573
 
        options.append(Option('check-style',
 
536
    takes_options = list(get_cmd_object('diff').takes_options) + [
 
537
        Option('check-style',
574
538
            help='Warn if trailing whitespace or spurious changes have been'
575
 
                 ' added.'))
576
 
        return options
577
 
 
578
 
    takes_options = property(_takes_options)
 
539
                 ' added.')]
579
540
 
580
541
    def run(self, check_style=False, *args, **kwargs):
581
542
        from colordiff import colordiff
582
543
        colordiff(check_style, *args, **kwargs)
583
544
 
584
545
 
585
 
class cmd_baz_import(bzrlib.commands.Command):
 
546
class cmd_baz_import(BzrToolsCommand):
586
547
    """Import an Arch or Baz archive into a bzr repository.
587
548
 
588
549
    This command should be used on local archives (or mirrors) only.  It is
609
570
    """
610
571
    takes_args = ['to_root_dir', 'from_archive', 'reuse_history*']
611
572
    takes_options = ['verbose', Option('prefixes', type=str,
612
 
                     help="Prefixes of branches to import, colon-separated"),
 
573
                     help="Prefixes of branches to import, colon-separated."),
613
574
                     Option('encoding', type=str,
614
575
                     help='Force encoding to specified value.  See WARNING.')]
615
576
 
624
585
            print "This command is disabled.  Please install PyBaz."
625
586
 
626
587
 
627
 
class cmd_baz_import_branch(bzrlib.commands.Command):
 
588
class cmd_baz_import_branch(BzrToolsCommand):
628
589
    """Import an Arch or Baz branch into a bzr branch.
629
590
 
630
591
    WARNING: Encoding should not be specified unless necessary, because if you
635
596
    are incompatible.
636
597
    """
637
598
    takes_args = ['to_location', 'from_branch?', 'reuse_history*']
638
 
    takes_options = ['verbose', Option('max-count', type=int),
 
599
    takes_options = ['verbose', 
 
600
                     Option('max-count', type=int, 
 
601
                     help='Maximim revisions to import at once.'),
639
602
                     Option('encoding', type=str,
640
603
                     help='Force encoding to specified value.  See WARNING.')]
641
604
 
652
615
            print "This command is disabled.  Please install PyBaz."
653
616
 
654
617
 
655
 
class cmd_rspush(bzrlib.commands.Command):
 
618
class cmd_rspush(BzrToolsCommand):
656
619
    """Upload this branch to another location using rsync.
657
620
 
658
621
    If no location is specified, the last-used location will be used.  To
662
625
    """
663
626
    takes_args = ['location?']
664
627
    takes_options = [Option('overwrite', help='Ignore differences between'
665
 
                            ' branches and overwrite unconditionally'),
 
628
                            ' branches and overwrite unconditionally.'),
666
629
                     Option('no-tree', help='Do not push the working tree,'
667
630
                            ' just the .bzr.')]
668
631
 
674
637
                      working_tree=not no_tree)
675
638
 
676
639
 
677
 
class cmd_switch(bzrlib.commands.Command):
678
 
    """Set the branch of a lightweight checkout and update."""
679
 
 
680
 
    takes_args = ['to_location']
681
 
 
682
 
    def run(self, to_location):
683
 
        from switch import cmd_switch
684
 
        cmd_switch().run(to_location)
685
 
 
686
 
 
687
640
commands = [
688
641
            cmd_baz_import,
689
642
            cmd_baz_import_branch,
690
643
            cmd_branches,
 
644
            cmd_trees,
691
645
            cmd_branch_history,
692
 
            cmd_branch_mark,
693
646
            cmd_cbranch,
694
647
            cmd_cdiff,
695
648
            cmd_clean_tree,
702
655
            cmd_shelf,
703
656
            cmd_shell,
704
657
            cmd_shelve,
705
 
            cmd_switch,
706
658
            cmd_unshelve,
707
659
            cmd_zap,
708
660
            ]
721
673
    import bzrtools
722
674
    import tests.clean_tree
723
675
    import tests.is_clean
 
676
    import tests.test_rspush
724
677
    import tests.upstream_import
725
678
    import zap
726
679
    import tests.blackbox
739
692
    result.addTest(tests.upstream_import.test_suite())
740
693
    result.addTest(zap.test_suite())
741
694
    result.addTest(TestLoader().loadTestsFromModule(tests.is_clean))
 
695
    result.addTest(TestLoader().loadTestsFromModule(tests.test_rspush))
742
696
    return result