Björn Pedersen | c357ceb | 2015-05-27 10:17:36 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
David Pursehouse | 9a13f85 | 2014-03-26 14:45:02 -0700 | [diff] [blame] | 2 | # Copyright (C) 2014 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | from __future__ import print_function |
| 17 | from optparse import OptionParser |
| 18 | import os.path |
| 19 | import re |
| 20 | import sys |
| 21 | |
| 22 | parser = OptionParser() |
| 23 | opts, args = parser.parse_args() |
| 24 | |
| 25 | if not len(args): |
| 26 | parser.error('not enough arguments') |
| 27 | elif len(args) > 1: |
| 28 | parser.error('too many arguments') |
| 29 | |
David Pursehouse | 8612f89 | 2015-07-06 14:08:34 +0900 | [diff] [blame] | 30 | DEST_PATTERN = r'\g<1>%s\g<3>' % args[0] |
David Pursehouse | 9a13f85 | 2014-03-26 14:45:02 -0700 | [diff] [blame] | 31 | |
David Pursehouse | 8612f89 | 2015-07-06 14:08:34 +0900 | [diff] [blame] | 32 | |
| 33 | def replace_in_file(filename, src_pattern): |
| 34 | try: |
| 35 | f = open(filename, "r") |
| 36 | s = f.read() |
| 37 | f.close() |
| 38 | s = re.sub(src_pattern, DEST_PATTERN, s) |
| 39 | f = open(filename, "w") |
| 40 | f.write(s) |
| 41 | f.close() |
| 42 | except IOError as err: |
| 43 | print('error updating %s: %s' % (filename, err), file=sys.stderr) |
| 44 | |
| 45 | |
| 46 | src_pattern = re.compile(r'^(\s*<version>)([-.\w]+)(</version>\s*)$', |
| 47 | re.MULTILINE) |
David Ostrovsky | 947b5e5 | 2015-09-24 21:52:17 +0200 | [diff] [blame] | 48 | for project in ['gerrit-acceptance-framework', 'gerrit-extension-api', |
| 49 | 'gerrit-plugin-api', 'gerrit-plugin-archetype', |
| 50 | 'gerrit-plugin-gwt-archetype', 'gerrit-plugin-gwtui', |
| 51 | 'gerrit-plugin-js-archetype', 'gerrit-war']: |
David Pursehouse | 9a13f85 | 2014-03-26 14:45:02 -0700 | [diff] [blame] | 52 | pom = os.path.join(project, 'pom.xml') |
David Pursehouse | 8612f89 | 2015-07-06 14:08:34 +0900 | [diff] [blame] | 53 | replace_in_file(pom, src_pattern) |
David Pursehouse | a022f3e | 2015-01-22 16:42:36 +0900 | [diff] [blame] | 54 | |
David Pursehouse | 8612f89 | 2015-07-06 14:08:34 +0900 | [diff] [blame] | 55 | src_pattern = re.compile(r"^(GERRIT_VERSION = ')([-.\w]+)(')$", re.MULTILINE) |
| 56 | replace_in_file('VERSION', src_pattern) |
| 57 | |
| 58 | src_pattern = re.compile(r'^(\s*-DarchetypeVersion=)([-.\w]+)(\s*\\)$', |
| 59 | re.MULTILINE) |
| 60 | replace_in_file(os.path.join('Documentation', 'dev-plugins.txt'), src_pattern) |