OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 optparse | 10 import optparse |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 if contents == old_contents: | 64 if contents == old_contents: |
65 return | 65 return |
66 os.unlink(file_name) | 66 os.unlink(file_name) |
67 open(file_name, 'w').write(contents) | 67 open(file_name, 'w').write(contents) |
68 | 68 |
69 | 69 |
70 def main(argv=None): | 70 def main(argv=None): |
71 if argv is None: | 71 if argv is None: |
72 argv = sys.argv | 72 argv = sys.argv |
73 | 73 |
74 parser = optparse.OptionParser(usage="lastchange.py [-h] [[-o] FILE]") | 74 parser = optparse.OptionParser(usage="lastchange.py [options]") |
75 parser.add_option("-d", "--default-lastchange", metavar="FILE", | 75 parser.add_option("-d", "--default-lastchange", metavar="FILE", |
76 help="default last change input FILE") | 76 help="default last change input FILE") |
77 parser.add_option("-o", "--output", metavar="FILE", | 77 parser.add_option("-o", "--output", metavar="FILE", |
78 help="write last change to FILE") | 78 help="write last change to FILE") |
| 79 parser.add_option("--revision-only", action='store_true', |
| 80 help="just print the SVN revision number") |
79 opts, args = parser.parse_args(argv[1:]) | 81 opts, args = parser.parse_args(argv[1:]) |
80 | 82 |
81 out_file = opts.output | 83 out_file = opts.output |
82 | 84 |
83 while len(args) and out_file is None: | 85 while len(args) and out_file is None: |
84 if out_file is None: | 86 if out_file is None: |
85 out_file = args.pop(0) | 87 out_file = args.pop(0) |
86 if args: | 88 if args: |
87 sys.stderr.write('Unexpected arguments: %r\n\n' % args) | 89 sys.stderr.write('Unexpected arguments: %r\n\n' % args) |
88 parser.print_help() | 90 parser.print_help() |
89 sys.exit(2) | 91 sys.exit(2) |
90 | 92 |
91 change = FetchChange(opts.default_lastchange) | 93 change = FetchChange(opts.default_lastchange) |
92 | 94 |
93 contents = "LASTCHANGE=%s\n" % change | 95 if opts.revision_only: |
94 | 96 print change |
95 if out_file: | |
96 WriteIfChanged(out_file, contents) | |
97 else: | 97 else: |
98 sys.stdout.write(contents) | 98 contents = "LASTCHANGE=%s\n" % change |
| 99 if out_file: |
| 100 WriteIfChanged(out_file, contents) |
| 101 else: |
| 102 sys.stdout.write(contents) |
99 | 103 |
100 return 0 | 104 return 0 |
101 | 105 |
102 | 106 |
103 if __name__ == '__main__': | 107 if __name__ == '__main__': |
104 sys.exit(main()) | 108 sys.exit(main()) |
OLD | NEW |