~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2006-07-17 19:05:46 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060717190546-11b67e418c7c3241
Allow completion on executables, fix broken prompt code

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Aaron Bentley <aaron.bentley@utoronto.ca>
2
 
# Copyright (C) 2005, 2006 Canonical Limited.
3
 
# Copyright (C) 2006 Michael Ellerman.
4
 
#
5
 
#    This program is free software; you can redistribute it and/or modify
6
 
#    it under the terms of the GNU General Public License as published by
7
 
#    the Free Software Foundation; either version 2 of the License, or
8
 
#    (at your option) any later version.
9
 
#
10
 
#    This program is distributed in the hope that it will be useful,
11
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
#    GNU General Public License for more details.
14
 
#
15
 
#    You should have received a copy of the GNU General Public License
16
 
#    along with this program; if not, write to the Free Software
17
 
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
 
 
1
#!/usr/bin/python
19
2
"""\
20
3
Various useful plugins for working with bzr.
21
4
"""
22
 
 
23
 
import bzrlib
24
 
 
25
 
 
26
 
__version__ = '0.13.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:
43
 
        return
44
 
    try:
45
 
        from bzrlib.trace import warning
46
 
    except ImportError:
47
 
        # get the message out any way we can
48
 
        from warnings import warn as warning
49
 
    if bzrlib_version < desired:
50
 
        warning('Installed bzr version %s is too old to be used with bzrtools'
51
 
                ' %s.' % (bzrlib.__version__, __version__))
52
 
        # Not using BzrNewError, because it may not exist.
53
 
        raise Exception, ('Version mismatch', version_info)
54
 
    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
 
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
58
 
        if bzrlib_version != desired_plus:
59
 
            raise Exception, 'Version mismatch'
60
 
 
61
 
 
62
 
check_bzrlib_version(version_info[:2])
63
 
 
64
 
 
65
 
from errors import CommandError, NoPyBaz
 
5
import rspush
 
6
from errors import CommandError
66
7
from patchsource import BzrPatchSource
67
8
from shelf import Shelf
 
9
from switch import cmd_switch
68
10
import sys
69
11
import os.path
70
12
 
 
13
from bzrlib import DEFAULT_IGNORE
71
14
import bzrlib.builtins
 
15
import bzrlib.branch
72
16
import bzrlib.commands
73
17
from bzrlib.commands import get_cmd_object
74
18
from bzrlib.errors import BzrCommandError
75
19
from bzrlib.help import command_usage
76
 
import bzrlib.ignores
77
20
from bzrlib.option import Option
78
21
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), 
79
22
                                                 "external")))
80
23
 
81
 
bzrlib.ignores.add_runtime_ignores(['./.shelf'])
 
24
 
 
25
DEFAULT_IGNORE.append('./.shelf')
 
26
DEFAULT_IGNORE.append('./.bzr-shelf*')
82
27
 
83
28
 
84
29
class cmd_clean_tree(bzrlib.commands.Command):
110
55
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus, 
111
56
                   dry_run=dry_run)
112
57
 
113
 
 
114
58
class cmd_graph_ancestry(bzrlib.commands.Command):
115
59
    """Produce ancestry graphs using dot.
116
60
    
163
107
        graph.write_ancestry_file(branch, file, not no_collapse, 
164
108
                                  not no_antialias, merge_branch, ranking)
165
109
 
166
 
 
167
110
class cmd_fetch_ghosts(bzrlib.commands.Command):
168
111
    """Attempt to retrieve ghosts from another branch.
169
112
    If the other branch is not supplied, the last-pulled branch is used.
179
122
each file name found in the patch file."""
180
123
Option.OPTIONS['bzrdiff'] = Option('bzrdiff',type=None,
181
124
                                help="""Handle extra bzr tags""")
182
 
 
183
 
 
184
125
class cmd_patch(bzrlib.commands.Command):
185
126
    """Apply a named patch to the current tree.
186
127
    """
196
137
 
197
138
        return patch(wt, filename, strip, legacy= not bzrdiff)
198
139
 
199
 
 
200
140
class cmd_shelve(bzrlib.commands.Command):
201
141
    """Temporarily set aside some changes from the current tree.
202
142
 
222
162
    you can also unshelve changes in a different order by explicitly
223
163
    specifiying which changes to unshelve. This works best when the changes
224
164
    don't depend on each other.
225
 
 
226
 
    While you have patches on the shelf you can view and manipulate them with
227
 
    the 'shelf' command. Run 'bzr shelf -h' for more info.
228
165
    """
229
166
 
230
167
    takes_args = ['file*']
231
168
    takes_options = ['message', 'revision',
232
 
            Option('all', help='Shelve all changes without prompting'), 
233
 
            Option('no-color', help='Never display changes in color')]
 
169
            Option('all', help='Shelve all changes without prompting')]
234
170
 
235
 
    def run(self, all=False, file_list=None, message=None, revision=None,
236
 
            no_color=False):
 
171
    def run(self, all=False, file_list=None, message=None, revision=None):
237
172
        if revision is not None and revision:
238
173
            if len(revision) == 1:
239
174
                revision = revision[0]
243
178
 
244
179
        source = BzrPatchSource(revision, file_list)
245
180
        s = Shelf(source.base)
246
 
        s.shelve(source, all, message, no_color)
 
181
        s.shelve(source, all, message)
247
182
        return 0
248
183
 
249
184
 
299
234
    def run(self, subcommand, args_list):
300
235
        import sys
301
236
 
302
 
        if args_list is None:
303
 
            args_list = []
304
237
        cmd = self._get_cmd_object(subcommand)
305
238
        source = BzrPatchSource()
306
239
        s = Shelf(source.base)
352
285
        return text
353
286
 
354
287
 
 
288
 
355
289
class cmd_unshelve(bzrlib.commands.Command):
356
290
    """Restore shelved changes.
357
291
 
363
297
    takes_options = [
364
298
            Option('all', help='Unshelve all changes without prompting'),
365
299
            Option('force', help='Force unshelving even if errors occur'),
366
 
            Option('no-color', help='Never display changes in color')
367
 
        ]
 
300
    ]
368
301
    takes_args = ['patch?']
369
 
    def run(self, patch=None, all=False, force=False, no_color=False):
 
302
    def run(self, patch=None, all=False, force=False):
370
303
        source = BzrPatchSource()
371
304
        s = Shelf(source.base)
372
 
        s.unshelve(source, patch, all, force, no_color)
 
305
        s.unshelve(source, patch, all, force)
373
306
        return 0
374
307
 
375
308
 
395
328
        import shell
396
329
        return shell.run_shell()
397
330
 
398
 
 
399
331
class cmd_branch_history(bzrlib.commands.Command):
400
332
    """\
401
333
    Display the development history of a branch.
434
366
    Create a new checkout, associated with a new repository branch.
435
367
    
436
368
    When you cbranch, bzr looks up the repository associated with your current
437
 
    directory in locations.conf.  It creates a new branch in that repository
 
369
    directory in branches.conf.  It creates a new branch in that repository
438
370
    with the same name and relative path as the checkout you request.
439
371
 
440
 
    The locations.conf parameter is "cbranch_root".  So if you want 
 
372
    The branches.conf parameter is "cbranch_root".  So if you want 
441
373
    cbranch operations in /home/jrandom/bigproject to produce branches in 
442
374
    /home/jrandom/bigproject/repository, you'd add this:
443
375
 
522
454
        from branch_mark import branch_mark
523
455
        branch_mark(mark, branch, delete)
524
456
 
525
 
 
526
457
class cmd_import(bzrlib.commands.Command):
527
458
    """Import sources from a tarball
528
459
    
542
473
        from upstream_import import do_import
543
474
        do_import(source, tree)
544
475
 
 
476
class cmd_shove(bzrlib.commands.Command):
 
477
    """Apply uncommitted changes to another tree
 
478
    
 
479
    This is useful when you start to make changes in one tree, then realize
 
480
    they should really be done in a different tree.
 
481
 
 
482
    Shove is implemented using merge, so:
 
483
     - All changes, including renames and adds, will be applied.
 
484
     - No changes that have already been applied will be applied.
 
485
     - If the target is significantly different from the source, conflicts may
 
486
       be produced.
 
487
    """
 
488
 
 
489
    takes_args = ['target', 'source?']
 
490
    def run(self, target, source='.'):
 
491
        from shove import do_shove
 
492
        do_shove(source, target)
545
493
 
546
494
class cmd_cdiff(bzrlib.commands.Command):
547
495
    """A color version of bzr's diff"""
551
499
        from colordiff import colordiff
552
500
        colordiff(*args, **kwargs)
553
501
 
554
 
 
555
 
class cmd_baz_import(bzrlib.commands.Command):
556
 
    """Import an Arch or Baz archive into a bzr repository.
557
 
 
558
 
    This command should be used on local archives (or mirrors) only.  It is
559
 
    quite slow on remote archives.
560
 
    
561
 
    reuse_history allows you to specify any previous imports you 
562
 
    have done of different archives, which this archive has branches
563
 
    tagged from. This will dramatically reduce the time to convert 
564
 
    the archive as it will not have to convert the history already
565
 
    converted in that other branch.
566
 
 
567
 
    If you specify prefixes, only branches whose names start with that prefix
568
 
    will be imported.  Skipped branches will be listed, so you can import any
569
 
    branches you missed by accident.  Here's an example of doing a partial
570
 
    import from thelove@canonical.com:
571
 
    bzr baz-import thelove thelove@canonical.com --prefixes dists:talloc-except
572
 
    """
573
 
    takes_args = ['to_root_dir', 'from_archive', 'reuse_history*']
574
 
    takes_options = ['verbose', Option('prefixes', type=str,
575
 
                     help="Prefixes of branches to import, colon-separated")]
576
 
 
577
 
    def run(self, to_root_dir, from_archive, encoding=None, verbose=False,
578
 
            reuse_history_list=[], prefixes=None):
579
 
        from errors import NoPyBaz
580
 
        try:
581
 
            import baz_import
582
 
            baz_import.baz_import(to_root_dir, from_archive, encoding,
583
 
                                  verbose, reuse_history_list, prefixes)
584
 
        except NoPyBaz:
585
 
            print "This command is disabled.  Please install PyBaz."
586
 
 
587
 
 
588
 
class cmd_baz_import_branch(bzrlib.commands.Command):
589
 
    """Import an Arch or Baz branch into a bzr branch."""
590
 
    takes_args = ['to_location', 'from_branch?', 'reuse_history*']
591
 
    takes_options = ['verbose', Option('max-count', type=int)]
592
 
 
593
 
    def run(self, to_location, from_branch=None, fast=False, max_count=None,
594
 
            encoding=None, verbose=False, dry_run=False,
595
 
            reuse_history_list=[]):
596
 
        from errors import NoPyBaz
597
 
        try:
598
 
            import baz_import
599
 
            baz_import.baz_import_branch(to_location, from_branch, fast, 
600
 
                                         max_count, verbose, encoding, dry_run,
601
 
                                         reuse_history_list)
602
 
        except NoPyBaz:
603
 
            print "This command is disabled.  Please install PyBaz."
604
 
 
605
 
 
606
 
class cmd_rspush(bzrlib.commands.Command):
607
 
    """Upload this branch to another location using rsync.
608
 
 
609
 
    If no location is specified, the last-used location will be used.  To 
610
 
    prevent dirty trees from being uploaded, rspush will error out if there are 
611
 
    unknown files or local changes.  It will also error out if the upstream 
612
 
    directory is non-empty and not an earlier version of the branch. 
613
 
    """
614
 
    takes_args = ['location?']
615
 
    takes_options = [Option('overwrite', help='Ignore differences between'
616
 
                            ' branches and overwrite unconditionally'),
617
 
                     Option('no-tree', help='Do not push the working tree,'
618
 
                            ' just the .bzr.')]
619
 
 
620
 
    def run(self, location=None, overwrite=False, no_tree=False):
621
 
        from bzrlib import workingtree
622
 
        import bzrtools
623
 
        cur_branch = workingtree.WorkingTree.open_containing(".")[0]
624
 
        bzrtools.rspush(cur_branch, location, overwrite=overwrite, 
625
 
                      working_tree=not no_tree)
626
 
 
627
 
 
628
 
class cmd_switch(bzrlib.commands.Command):
629
 
    """Set the branch of a lightweight checkout and update."""
630
 
 
631
 
    takes_args = ['to_location']
632
 
 
633
 
    def run(self, to_location):
634
 
        from switch import cmd_switch
635
 
        cmd_switch().run(to_location)
636
 
 
637
 
 
638
 
commands = [
639
 
            cmd_baz_import,
640
 
            cmd_baz_import_branch,
641
 
            cmd_branches,
642
 
            cmd_branch_history,
643
 
            cmd_branch_mark,
644
 
            cmd_cbranch,  
645
 
            cmd_cdiff,
646
 
            cmd_clean_tree,
647
 
            cmd_fetch_ghosts,
648
 
            cmd_graph_ancestry,
649
 
            cmd_import,
650
 
            cmd_multi_pull,
651
 
            cmd_patch,
652
 
            cmd_rspush,
653
 
            cmd_shelf, 
654
 
            cmd_shell,
655
 
            cmd_shelve, 
656
 
            cmd_switch,
657
 
            cmd_unshelve, 
658
 
            cmd_zap,            
659
 
            ]
 
502
commands = [cmd_shelve, cmd_unshelve, cmd_shelf, cmd_clean_tree,
 
503
            cmd_graph_ancestry, cmd_fetch_ghosts, cmd_patch, cmd_shell,
 
504
            cmd_branch_history, cmd_zap, cmd_cbranch, cmd_branches, 
 
505
            cmd_multi_pull, cmd_switch, cmd_branch_mark, cmd_import, cmd_shove,
 
506
            cmd_cdiff]
 
507
 
 
508
 
 
509
commands.append(rspush.cmd_rspush)
 
510
 
 
511
from errors import NoPyBaz
 
512
try:
 
513
    import baz_import
 
514
    commands.append(baz_import.cmd_baz_import_branch)
 
515
    commands.append(baz_import.cmd_baz_import)
 
516
 
 
517
except NoPyBaz:
 
518
    class cmd_baz_import_branch(bzrlib.commands.Command):
 
519
        """Disabled. (Requires PyBaz)"""
 
520
        takes_args = ['to_location?', 'from_branch?', 'reuse_history*']
 
521
        takes_options = ['verbose', Option('max-count', type=int)]
 
522
        def run(self, to_location=None, from_branch=None, fast=False, 
 
523
                max_count=None, verbose=False, dry_run=False,
 
524
                reuse_history_list=[]):
 
525
            print "This command is disabled.  Please install PyBaz."
 
526
 
 
527
 
 
528
    class cmd_baz_import(bzrlib.commands.Command):
 
529
        """Disabled. (Requires PyBaz)"""
 
530
        takes_args = ['to_root_dir?', 'from_archive?', 'reuse_history*']
 
531
        takes_options = ['verbose', Option('prefixes', type=str,
 
532
                         help="Prefixes of branches to import")]
 
533
        def run(self, to_root_dir=None, from_archive=None, verbose=False,
 
534
                reuse_history_list=[], prefixes=None):
 
535
                print "This command is disabled.  Please install PyBaz."
 
536
    commands.extend((cmd_baz_import_branch, cmd_baz_import))
660
537
 
661
538
 
662
539
if hasattr(bzrlib.commands, 'register_command'):
669
546
    import tests
670
547
    from doctest import DocTestSuite, ELLIPSIS
671
548
    from unittest import TestSuite
672
 
    import bzrtools
673
549
    import tests.clean_tree
674
550
    import upstream_import
675
551
    import zap