Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 lastchange.py -- Chromium revision fetching utility. | 7 lastchange.py -- Chromium revision fetching utility. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import re | 10 import re |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 if argv is None: | 189 if argv is None: |
| 190 argv = sys.argv | 190 argv = sys.argv |
| 191 | 191 |
| 192 parser = optparse.OptionParser(usage="lastchange.py [options]") | 192 parser = optparse.OptionParser(usage="lastchange.py [options]") |
| 193 parser.add_option("-d", "--default-lastchange", metavar="FILE", | 193 parser.add_option("-d", "--default-lastchange", metavar="FILE", |
| 194 help="default last change input FILE") | 194 help="default last change input FILE") |
| 195 parser.add_option("-o", "--output", metavar="FILE", | 195 parser.add_option("-o", "--output", metavar="FILE", |
| 196 help="write last change to FILE") | 196 help="write last change to FILE") |
| 197 parser.add_option("--revision-only", action='store_true', | 197 parser.add_option("--revision-only", action='store_true', |
| 198 help="just print the SVN revision number") | 198 help="just print the SVN revision number") |
| 199 parser.add_option("-s", "--source-dir", metavar="DIR", | |
| 200 help="use repository in the given directory") | |
| 199 opts, args = parser.parse_args(argv[1:]) | 201 opts, args = parser.parse_args(argv[1:]) |
| 200 | 202 |
| 201 out_file = opts.output | 203 out_file = opts.output |
| 202 | 204 |
| 203 while len(args) and out_file is None: | 205 while len(args) and out_file is None: |
| 204 if out_file is None: | 206 if out_file is None: |
| 205 out_file = args.pop(0) | 207 out_file = args.pop(0) |
| 206 if args: | 208 if args: |
| 207 sys.stderr.write('Unexpected arguments: %r\n\n' % args) | 209 sys.stderr.write('Unexpected arguments: %r\n\n' % args) |
| 208 parser.print_help() | 210 parser.print_help() |
| 209 sys.exit(2) | 211 sys.exit(2) |
| 210 | 212 |
| 211 version_info = FetchVersionInfo(opts.default_lastchange, | 213 if opts.source_dir: |
| 212 os.path.dirname(sys.argv[0])) | 214 src_dir = opts.source_dir |
| 215 else: | |
| 216 src_dir = os.path.dirname(sys.argv[0]) | |
|
M-A Ruel
2012/10/25 17:56:01
not always a good idea. In general it's better to
chrisha
2012/10/25 17:59:07
Done.
| |
| 217 | |
| 218 version_info = FetchVersionInfo(opts.default_lastchange, src_dir) | |
| 213 | 219 |
| 214 if version_info.revision == None: | 220 if version_info.revision == None: |
| 215 version_info.revision = '0' | 221 version_info.revision = '0' |
| 216 | 222 |
| 217 if opts.revision_only: | 223 if opts.revision_only: |
| 218 print version_info.revision | 224 print version_info.revision |
| 219 else: | 225 else: |
| 220 contents = "LASTCHANGE=%s\n" % version_info.revision | 226 contents = "LASTCHANGE=%s\n" % version_info.revision |
| 221 if out_file: | 227 if out_file: |
| 222 WriteIfChanged(out_file, contents) | 228 WriteIfChanged(out_file, contents) |
| 223 else: | 229 else: |
| 224 sys.stdout.write(contents) | 230 sys.stdout.write(contents) |
| 225 | 231 |
| 226 return 0 | 232 return 0 |
| 227 | 233 |
| 228 | 234 |
| 229 if __name__ == '__main__': | 235 if __name__ == '__main__': |
| 230 sys.exit(main()) | 236 sys.exit(main()) |
| OLD | NEW |