~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to obsolete/baz2bzr

  • Committer: Michael Ellerman
  • Date: 2005-11-29 07:12:26 UTC
  • mto: (0.3.1 shelf-dev) (325.1.2 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20051129071226-a04b3f827880025d
Unshelve --pick was broken, because we deleted the whole patch, even when only
part of it was unshelved. So now if we unshelve part of a patch, the patch is
replaced with a new patch that has just the unshelved parts. That's a long way
of saying it does what you'd expect.

Implementing this required changing HunkSelector to return both the selected,
and unselected hunks (ie. patches to shelve, and patches to keep).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
# Copyright (C) 2005 Aaron Bentley
4
 
# <aaron.bentley@utoronto.ca>
5
 
#
6
 
#    This program is free software; you can redistribute it and/or modify
7
 
#    it under the terms of the GNU General Public License as published by
8
 
#    the Free Software Foundation; either version 2 of the License, or
9
 
#    (at your option) any later version.
10
 
#
11
 
#    This program is distributed in the hope that it will be useful,
12
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
#    GNU General Public License for more details.
15
 
#
16
 
#    You should have received a copy of the GNU General Public License
17
 
#    along with this program; if not, write to the Free Software
18
 
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
 
20
 
import sys
21
 
from errors import NoPyBaz
22
 
try:
23
 
    from baz_import import import_version, UserError
24
 
except NoPyBaz:
25
 
    print >> sys.stderr, "This command requires PyBaz.  Please ensure that it is installed."
26
 
    sys.exit(1)
27
 
 
28
 
import pybaz
29
 
import os.path
30
 
 
31
 
def main(args):
32
 
    """Just the main() function for this script.
33
 
 
34
 
    By separating it into a function, this can be called as a child from some other
35
 
    script.
36
 
 
37
 
    :param args: The arguments to this script. Essentially sys.argv[1:]
38
 
    """
39
 
    import optparse
40
 
    parser = optparse.OptionParser(usage='%prog [options] [VERSION] OUTDIR'
41
 
        '\n  VERSION is the arch version to import.'
42
 
        '\n  OUTDIR can be an existing directory to be updated'
43
 
        '\n         or a new directory which will be created from scratch.')
44
 
    parser.add_option('--verbose', action='store_true'
45
 
        , help='Get chatty')
46
 
 
47
 
    parser.add_option('--skip-symlinks', action="store_true", 
48
 
                      dest="skip_symlinks", 
49
 
                      help="Ignore any symlinks present in the Arch tree.")
50
 
 
51
 
    g = optparse.OptionGroup(parser, 'Test options', 'Options useful while testing process.')
52
 
    g.add_option('--test', action='store_true'
53
 
        , help='Run the self-tests and exit.')
54
 
    g.add_option('--dry-run', action='store_true'
55
 
        , help='Do the update, but don\'t copy the result to OUTDIR')
56
 
    g.add_option('--max-count', type='int', metavar='COUNT', default=None
57
 
        , help='At most, add COUNT patches.')
58
 
    g.add_option('--safe', action='store_false', dest='fast')
59
 
    g.add_option('--fast', action='store_true', default=False
60
 
        , help='By default the .bzr control directory will be copied, so that an error'
61
 
        ' does not modify the original. --fast allows the directory to be renamed instead.')
62
 
    parser.add_option_group(g)
63
 
 
64
 
    (opts, args) = parser.parse_args(args)
65
 
 
66
 
    if opts.test:
67
 
        print "Running tests"
68
 
        import doctest, baz_import
69
 
        nfail, ntests = doctest.testmod(baz_import, verbose=opts.verbose)
70
 
        if nfail > 0:
71
 
            return 1
72
 
        else:
73
 
            return 0
74
 
    if len(args) == 2:
75
 
        version,output_dir = args
76
 
            
77
 
    elif len(args) == 1:
78
 
        output_dir = args[0]
79
 
        version = None
80
 
    else:
81
 
        print 'Invalid number of arguments, try --help for more info'
82
 
        return 1
83
 
 
84
 
    output_dir = os.path.realpath(output_dir)
85
 
    if version is not None:
86
 
        try:
87
 
            version = pybaz.Version(version)
88
 
        except pybaz.errors.NamespaceError:
89
 
            print "%s is not a valid Arch branch." % version
90
 
            return 1
91
 
        
92
 
    try:
93
 
        import_version(output_dir, version,
94
 
            verbose=opts.verbose, fast=opts.fast,
95
 
            dry_run=opts.dry_run, max_count=opts.max_count,
96
 
            skip_symlinks=opts.skip_symlinks)
97
 
        return 0
98
 
    except UserError, e:
99
 
        print e
100
 
        return 1
101
 
    except KeyboardInterrupt:
102
 
        print "Aborted."
103
 
        return 1
104
 
 
105
 
        
106
 
 
107
 
if __name__ == '__main__':
108
 
    sys.exit(main(sys.argv[1:]))
109