~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2007-07-26 15:52:55 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070726155255-cawzo84zpzoulzbr
Allow importing directly from a URL

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import bzrlib
24
24
 
 
25
 
 
26
__version__ = '0.19.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
 
25
68
from bzrlib.lazy_import import lazy_import
26
69
lazy_import(globals(), """
27
 
from bzrlib import help, urlutils
 
70
from bzrlib import help
28
71
import shelf
29
72
""")
30
73
 
31
 
from version import version_info, __version__
32
 
from command import BzrToolsCommand
33
74
from errors import CommandError, NoPyBaz
34
75
from patchsource import BzrPatchSource
35
76
import sys
37
78
 
38
79
import bzrlib.builtins
39
80
import bzrlib.commands
40
 
from bzrlib.branch import Branch
41
 
from bzrlib.bzrdir import BzrDir
42
81
from bzrlib.commands import get_cmd_object
43
82
from bzrlib.errors import BzrCommandError
44
83
import bzrlib.ignores
45
 
from bzrlib.trace import note
46
84
from bzrlib.option import Option
47
85
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__),
48
86
                                                 "external")))
49
87
 
50
88
import show_paths
51
 
from command import BzrToolsCommand
52
89
 
53
90
bzrlib.ignores.add_runtime_ignores(['./.shelf'])
54
91
 
55
92
 
56
 
class cmd_clean_tree(BzrToolsCommand):
 
93
class cmd_clean_tree(bzrlib.commands.Command):
57
94
    """Remove unwanted files from working tree.
58
95
 
59
96
    By default, only unknown files, not ignored files, are deleted.  Versioned
83
120
                   dry_run=dry_run)
84
121
 
85
122
 
86
 
class cmd_graph_ancestry(BzrToolsCommand):
 
123
class cmd_graph_ancestry(bzrlib.commands.Command):
87
124
    """Produce ancestry graphs using dot.
88
125
    
89
126
    Output format is detected according to file extension.  Some of the more
148
185
                                  max_distance=max_distance)
149
186
 
150
187
 
151
 
class cmd_fetch_ghosts(BzrToolsCommand):
 
188
class cmd_fetch_ghosts(bzrlib.commands.Command):
152
189
    """Attempt to retrieve ghosts from another branch.
153
190
    If the other branch is not supplied, the last-pulled branch is used.
154
191
    """
163
200
each file name found in the patch file."""
164
201
 
165
202
 
166
 
class cmd_patch(BzrToolsCommand):
 
203
class cmd_patch(bzrlib.commands.Command):
167
204
    """Apply a named patch to the current tree.
168
205
    """
169
206
    takes_args = ['filename?']
178
215
        return patch(wt, filename, strip, silent)
179
216
 
180
217
 
181
 
class cmd_shelve(BzrToolsCommand):
 
218
class cmd_shelve(bzrlib.commands.Command):
182
219
    """Temporarily set aside some changes from the current tree.
183
220
 
184
221
    Shelve allows you to temporarily put changes you've made "on the shelf",
273
310
        self.shelf.upgrade()
274
311
 
275
312
 
276
 
class cmd_shelf(BzrToolsCommand):
 
313
class cmd_shelf(bzrlib.commands.Command):
277
314
    """Perform various operations on your shelved patches. See also shelve."""
278
315
    takes_args = ['subcommand', 'args*']
279
316
 
339
376
        return text
340
377
 
341
378
 
342
 
class cmd_unshelve(BzrToolsCommand):
 
379
class cmd_unshelve(bzrlib.commands.Command):
343
380
    """Restore shelved changes.
344
381
 
345
382
    By default the most recently shelved changes are restored. However if you
360
397
        return 0
361
398
 
362
399
 
363
 
class cmd_shell(BzrToolsCommand):
 
400
class cmd_shell(bzrlib.commands.Command):
364
401
    """Begin an interactive shell tailored for bzr.
365
402
    Bzr commands can be used without typing bzr first, and will be run natively
366
403
    when possible.  Tab completion is tailored for bzr.  The shell prompt shows
383
420
        return shell.run_shell()
384
421
 
385
422
 
386
 
class cmd_branch_history(BzrToolsCommand):
 
423
class cmd_branch_history(bzrlib.commands.Command):
387
424
    """\
388
425
    Display the development history of a branch.
389
426
 
397
434
        return branch_history(branch)
398
435
 
399
436
 
400
 
class cmd_zap(BzrToolsCommand):
 
437
class cmd_zap(bzrlib.commands.Command):
401
438
    """\
402
439
    Remove a lightweight checkout, if it can be done safely.
403
440
 
409
446
    the branch has no new commits (relative to its parent).
410
447
    """
411
448
    takes_options = [Option("branch", help="Remove associated branch from"
412
 
                                           " repository."),
413
 
                     Option('force', help='Delete tree even if contents are'
414
 
                     ' modified.')]
 
449
                                           " repository.")]
415
450
    takes_args = ["checkout"]
416
 
    def run(self, checkout, branch=False, force=False):
 
451
    def run(self, checkout, branch=False):
417
452
        from zap import zap
418
 
        return zap(checkout, remove_branch=branch, allow_modified=force)
419
 
 
420
 
 
421
 
class cmd_cbranch(BzrToolsCommand):
 
453
        return zap(checkout, remove_branch=branch)
 
454
 
 
455
 
 
456
class cmd_cbranch(bzrlib.commands.Command):
422
457
    """
423
458
    Create a new checkout, associated with a new repository branch.
424
459
 
446
481
                       revision=revision)
447
482
 
448
483
 
449
 
class cmd_branches(BzrToolsCommand):
 
484
class cmd_branches(bzrlib.commands.Command):
450
485
    """Scan a location for branches"""
451
486
    takes_args = ["location?"]
452
487
    def run(self, location=None):
454
489
        return branches(location)
455
490
 
456
491
 
457
 
class cmd_multi_pull(BzrToolsCommand):
 
492
class cmd_multi_pull(bzrlib.commands.Command):
458
493
    """Pull all the branches under a location, e.g. a repository.
459
494
 
460
495
    Both branches present in the directory and the branches of checkouts are
462
497
    """
463
498
    takes_args = ["location?"]
464
499
    def run(self, location=None):
 
500
        from bzrlib.branch import Branch
465
501
        from bzrlib.transport import get_transport
466
502
        from bzrtools import iter_branch_tree
467
503
        if location is None:
468
504
            location = '.'
469
505
        t = get_transport(location)
470
 
        possible_transports = []
471
506
        if not t.listable():
472
507
            print "Can't list this type of location."
473
508
            return 3
489
524
                relpath = base
490
525
            print "Pulling %s from %s" % (relpath, parent)
491
526
            try:
492
 
                branch_t = get_transport(parent, possible_transports)
493
 
                pullable.pull(Branch.open_from_transport(branch_t))
 
527
                pullable.pull(Branch.open(parent))
494
528
            except Exception, e:
495
529
                print e
496
530
 
497
531
 
498
 
class cmd_import(BzrToolsCommand):
 
532
class cmd_branch_mark(bzrlib.commands.Command):
 
533
    """
 
534
    Add, view or list branch markers <EXPERIMENTAL>
 
535
 
 
536
    To add a mark, do 'bzr branch-mark MARK'.
 
537
    To list marks, do 'bzr branch-mark' (this lists all marks for the branch's
 
538
    repository).
 
539
    To delete a mark, do 'bzr branch-mark --delete MARK'
 
540
 
 
541
    These marks can be used to track a branch's status.
 
542
    """
 
543
    takes_args = ['mark?', 'branch?']
 
544
    takes_options = [Option('delete', help='Delete this mark.')]
 
545
    def run(self, mark=None, branch=None, delete=False):
 
546
        from branch_mark import branch_mark
 
547
        branch_mark(mark, branch, delete)
 
548
 
 
549
 
 
550
class cmd_import(bzrlib.commands.Command):
499
551
    """Import sources from a directory, tarball or zip file
500
552
 
501
553
    This command will import a directory, tarball or zip file into a bzr
515
567
        do_import(source, tree)
516
568
 
517
569
 
518
 
class cmd_cdiff(BzrToolsCommand):
 
570
class cmd_cdiff(bzrlib.commands.Command):
519
571
    """A color version of bzr's diff"""
520
572
    takes_args = property(lambda x: get_cmd_object('diff').takes_args)
521
573
    takes_options = list(get_cmd_object('diff').takes_options) + [
528
580
        colordiff(check_style, *args, **kwargs)
529
581
 
530
582
 
531
 
class cmd_baz_import(BzrToolsCommand):
 
583
class cmd_baz_import(bzrlib.commands.Command):
532
584
    """Import an Arch or Baz archive into a bzr repository.
533
585
 
534
586
    This command should be used on local archives (or mirrors) only.  It is
570
622
            print "This command is disabled.  Please install PyBaz."
571
623
 
572
624
 
573
 
class cmd_baz_import_branch(BzrToolsCommand):
 
625
class cmd_baz_import_branch(bzrlib.commands.Command):
574
626
    """Import an Arch or Baz branch into a bzr branch.
575
627
 
576
628
    WARNING: Encoding should not be specified unless necessary, because if you
600
652
            print "This command is disabled.  Please install PyBaz."
601
653
 
602
654
 
603
 
class cmd_rspush(BzrToolsCommand):
 
655
class cmd_rspush(bzrlib.commands.Command):
604
656
    """Upload this branch to another location using rsync.
605
657
 
606
658
    If no location is specified, the last-used location will be used.  To
622
674
                      working_tree=not no_tree)
623
675
 
624
676
 
 
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
 
625
687
commands = [
626
688
            cmd_baz_import,
627
689
            cmd_baz_import_branch,
628
690
            cmd_branches,
629
691
            cmd_branch_history,
 
692
            cmd_branch_mark,
630
693
            cmd_cbranch,
631
694
            cmd_cdiff,
632
695
            cmd_clean_tree,
639
702
            cmd_shelf,
640
703
            cmd_shell,
641
704
            cmd_shelve,
 
705
            cmd_switch,
642
706
            cmd_unshelve,
643
707
            cmd_zap,
644
708
            ]
657
721
    import bzrtools
658
722
    import tests.clean_tree
659
723
    import tests.is_clean
660
 
    import tests.test_rspush
661
724
    import tests.upstream_import
662
725
    import zap
663
726
    import tests.blackbox
676
739
    result.addTest(tests.upstream_import.test_suite())
677
740
    result.addTest(zap.test_suite())
678
741
    result.addTest(TestLoader().loadTestsFromModule(tests.is_clean))
679
 
    result.addTest(TestLoader().loadTestsFromModule(tests.test_rspush))
680
742
    return result