2
by abentley
Added baz2bzr file(doh!) |
1 |
#!/usr/bin/env python
|
14
by abentley
GPLed the project, ignored files |
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 |
||
83
by Aaron Bentley
Moved most baz2bzr code to baz_import, added Python plugin |
20 |
from baz_import import import_version, UserError |
21 |
from progress import rewriting_supported |
|
22 |
import pybaz |
|
23 |
import sys |
|
2
by abentley
Added baz2bzr file(doh!) |
24 |
import os.path |
6
by abentley
added commit, timport, commit_test_revisions |
25 |
|
59
by Aaron Bentley
Applied John Meinel's options patch |
26 |
def main(args): |
27 |
"""Just the main() function for this script.
|
|
28 |
||
29 |
By separating it into a function, this can be called as a child from some other
|
|
30 |
script.
|
|
31 |
||
32 |
:param args: The arguments to this script. Essentially sys.argv[1:]
|
|
33 |
"""
|
|
34 |
import optparse |
|
62
by Aaron Bentley
Refactored, made version optional |
35 |
parser = optparse.OptionParser(usage='%prog [options] [VERSION] OUTDIR' |
59
by Aaron Bentley
Applied John Meinel's options patch |
36 |
'\n VERSION is the arch version to import.' |
37 |
'\n OUTDIR can be an existing directory to be updated' |
|
38 |
'\n or a new directory which will be created from scratch.') |
|
39 |
parser.add_option('--verbose', action='store_true' |
|
40 |
, help='Get chatty') |
|
41 |
||
60
by Aaron Bentley
Made symlink-skipping an option |
42 |
parser.add_option('--skip-symlinks', action="store_true", |
43 |
dest="skip_symlinks", |
|
44 |
help="Ignore any symlinks present in the Arch tree.") |
|
45 |
||
59
by Aaron Bentley
Applied John Meinel's options patch |
46 |
g = optparse.OptionGroup(parser, 'Test options', 'Options useful while testing process.') |
47 |
g.add_option('--test', action='store_true' |
|
48 |
, help='Run the self-tests and exit.') |
|
49 |
g.add_option('--dry-run', action='store_true' |
|
50 |
, help='Do the update, but don\'t copy the result to OUTDIR') |
|
51 |
g.add_option('--max-count', type='int', metavar='COUNT', default=None |
|
52 |
, help='At most, add COUNT patches.') |
|
53 |
g.add_option('--safe', action='store_false', dest='fast') |
|
54 |
g.add_option('--fast', action='store_true', default=False |
|
55 |
, help='By default the .bzr control directory will be copied, so that an error' |
|
56 |
' does not modify the original. --fast allows the directory to be renamed instead.') |
|
57 |
parser.add_option_group(g) |
|
58 |
||
59 |
(opts, args) = parser.parse_args(args) |
|
60 |
||
61 |
if opts.test: |
|
62 |
print "Running tests" |
|
83
by Aaron Bentley
Moved most baz2bzr code to baz_import, added Python plugin |
63 |
import doctest, baz_import |
64 |
nfail, ntests = doctest.testmod(baz_import, verbose=opts.verbose) |
|
59
by Aaron Bentley
Applied John Meinel's options patch |
65 |
if nfail > 0: |
66 |
return 1 |
|
67 |
else: |
|
68 |
return 0 |
|
62
by Aaron Bentley
Refactored, made version optional |
69 |
if len(args) == 2: |
83
by Aaron Bentley
Moved most baz2bzr code to baz_import, added Python plugin |
70 |
version,output_dir = args[1] |
71
by Aaron Bentley
Improved errors for invalid or missing versions |
71 |
|
62
by Aaron Bentley
Refactored, made version optional |
72 |
elif len(args) == 1: |
83
by Aaron Bentley
Moved most baz2bzr code to baz_import, added Python plugin |
73 |
output_dir = args[0] |
62
by Aaron Bentley
Refactored, made version optional |
74 |
version = None |
75 |
else: |
|
59
by Aaron Bentley
Applied John Meinel's options patch |
76 |
print 'Invalid number of arguments, try --help for more info' |
77 |
return 1 |
|
83
by Aaron Bentley
Moved most baz2bzr code to baz_import, added Python plugin |
78 |
|
79 |
output_dir = os.path.realpath(output_dir) |
|
80 |
if version is not None: |
|
81 |
try: |
|
82 |
version = pybaz.Version(version) |
|
83 |
except pybaz.errors.NamespaceError: |
|
84 |
print "%s is not a valid Arch branch." % version |
|
85 |
return 1 |
|
62
by Aaron Bentley
Refactored, made version optional |
86 |
|
87 |
try: |
|
80
by Aaron Bentley
Disabled fancy output when stdout is not a tty |
88 |
fancy = rewriting_supported() |
62
by Aaron Bentley
Refactored, made version optional |
89 |
import_version(output_dir, version, |
90 |
verbose=opts.verbose, fast=opts.fast, |
|
66
by Aaron Bentley
Continued symlink fix, cleaned up merge, error message |
91 |
dry_run=opts.dry_run, max_count=opts.max_count, |
80
by Aaron Bentley
Disabled fancy output when stdout is not a tty |
92 |
skip_symlinks=opts.skip_symlinks, fancy=fancy) |
62
by Aaron Bentley
Refactored, made version optional |
93 |
return 0 |
94 |
except UserError, e: |
|
95 |
print e |
|
96 |
return 1 |
|
97 |
except KeyboardInterrupt: |
|
98 |
print "Aborted." |
|
99 |
return 1 |
|
59
by Aaron Bentley
Applied John Meinel's options patch |
100 |
|
70
by Aaron Bentley
Friendlier error, when dir is not a bzr branch |
101 |
|
59
by Aaron Bentley
Applied John Meinel's options patch |
102 |
|
103 |
if __name__ == '__main__': |
|
104 |
sys.exit(main(sys.argv[1:])) |
|
105 |