summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgn <dgn@chromium.org>2015-11-03 14:39:21 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-03 22:41:08 +0000
commit24f457db32c79f72e5a445bcdf5d6bc0647f4edb (patch)
treedc2da8f5a22150ce1f1e693e7cc3f9830190187e
parent1fdfeb2825c578c6694e5d5b7323bd015000a7f3 (diff)
downloadchromium_src-24f457db32c79f72e5a445bcdf5d6bc0647f4edb.zip
chromium_src-24f457db32c79f72e5a445bcdf5d6bc0647f4edb.tar.gz
chromium_src-24f457db32c79f72e5a445bcdf5d6bc0647f4edb.tar.bz2
Use JSON instead of YAML for the play services scripts config
Bots don't have the yaml python module installed. JSON is supported. Added a parser object that will also hold the description of the different possible fields since JSON doesn't support comments BUG=541727 Review URL: https://codereview.chromium.org/1411183004 Cr-Commit-Position: refs/heads/master@{#357656}
-rw-r--r--build/android/play_services/config.json3
-rw-r--r--build/android/play_services/config.yaml7
-rwxr-xr-xbuild/android/play_services/update.py17
-rw-r--r--build/android/play_services/utils.py70
4 files changed, 46 insertions, 51 deletions
diff --git a/build/android/play_services/config.json b/build/android/play_services/config.json
new file mode 100644
index 0000000..df669e9
--- /dev/null
+++ b/build/android/play_services/config.json
@@ -0,0 +1,3 @@
+{
+ "version_number": 8115000
+}
diff --git a/build/android/play_services/config.yaml b/build/android/play_services/config.yaml
deleted file mode 100644
index de83be0..0000000
--- a/build/android/play_services/config.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
----
-##
-# Configuration file for the Google Play services related scripts.
-#
-
-# Mirrors @integer/google_play_services_version from the library.
-version_number: 8115000
diff --git a/build/android/play_services/update.py b/build/android/play_services/update.py
index 5966db2..b2d57ad 100755
--- a/build/android/play_services/update.py
+++ b/build/android/play_services/update.py
@@ -42,7 +42,7 @@ GMS_CLOUD_STORAGE = 'chrome-sdk-extras'
# Path to the default configuration file. It exposes the currently installed
# version of the library in a human readable way.
CONFIG_DEFAULT_PATH = os.path.join(constants.DIR_SOURCE_ROOT, 'build',
- 'android', 'play_services', 'config.yaml')
+ 'android', 'play_services', 'config.json')
LICENSE_FILE_NAME = 'LICENSE'
LIBRARY_FILE_NAME = 'google_play_services_library.zip'
@@ -123,7 +123,7 @@ def AddCommonArguments(parser):
help='name of the bucket where the files are stored',
default=GMS_CLOUD_STORAGE)
parser.add_argument('--config',
- help='YAML Configuration file',
+ help='JSON Configuration file',
default=CONFIG_DEFAULT_PATH)
parser.add_argument('--dry-run',
action='store_true',
@@ -157,8 +157,9 @@ def Download(args):
logging.debug('The Google Play services library is up to date.')
return 0
+ config = utils.ConfigParser(args.config)
bucket_path = _VerifyBucketPathFormat(args.bucket,
- utils.GetVersionNumber(args.config),
+ config.version_number,
args.dry_run)
tmp_root = tempfile.mkdtemp()
@@ -245,13 +246,13 @@ def Upload(args):
logging.error('The repo is dirty. Please commit or stash your changes.')
return -1
- old_version_number = utils.GetVersionNumber(args.config)
+ config = utils.ConfigParser(args.config)
version_xml = os.path.join(paths.lib, 'res', 'values', 'version.xml')
new_version_number = utils.GetVersionNumberFromLibraryResources(version_xml)
logging.debug('comparing versions: new=%d, old=%s',
- new_version_number, old_version_number)
- if new_version_number <= old_version_number and not args.force:
+ new_version_number, config.version_number)
+ if new_version_number <= config.version_number and not args.force:
logging.info('The checked in version of the library is already the latest '
'one. No update needed. Please rerun with --force to skip '
'this check.')
@@ -281,13 +282,13 @@ def Upload(args):
finally:
shutil.rmtree(tmp_root)
- utils.UpdateVersionNumber(args.config, new_version_number)
+ config.UpdateVersionNumber(new_version_number)
if not args.skip_git:
commit_message = ('Update the Google Play services dependency to %s\n'
'\n') % new_version_number
utils.MakeLocalCommit(constants.DIR_SOURCE_ROOT,
- [new_lib_zip_sha1, new_license_sha1, args.config],
+ [new_lib_zip_sha1, new_license_sha1, config.path],
commit_message)
return 0
diff --git a/build/android/play_services/utils.py b/build/android/play_services/utils.py
index 94e684b..90339d2 100644
--- a/build/android/play_services/utils.py
+++ b/build/android/play_services/utils.py
@@ -9,20 +9,17 @@ related files.
import argparse
import filecmp
+import json
import logging
import os
import re
import sys
-import yaml
import zipfile
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
from devil.utils import cmd_helper
-_CONFIG_VERSION_NUMBER_KEY = 'version_number'
-_YAML_VERSION_NUMBER_PATTERN = re.compile(
- r'(^\s*%s\s*:\s*)(\d+)(.*$)' % _CONFIG_VERSION_NUMBER_KEY, re.MULTILINE)
_XML_VERSION_NUMBER_PATTERN = re.compile(
r'<integer name="google_play_services_version">(\d+)<\/integer>')
@@ -37,6 +34,39 @@ class DefaultsRawHelpFormatter(argparse.ArgumentDefaultsHelpFormatter,
pass
+class ConfigParser(object):
+ '''Reads and writes the configuration files for play services related scripts
+
+ The configuration files are JSON files. Here is the data they are expected
+ to contain:
+
+ - version_number
+ Number. Mirrors @integer/google_play_services_version from the library.
+ Example: 815000
+
+ '''
+ _VERSION_NUMBER_KEY = 'version_number'
+
+ def __init__(self, path):
+ self.path = path
+ self.data = {}
+
+ with open(path, 'r') as stream:
+ self.data = json.load(stream)
+
+ @property
+ def version_number(self):
+ return self.data[self._VERSION_NUMBER_KEY]
+
+ def UpdateVersionNumber(self, new_version_number):
+ '''Updates the version number and saves it in the configuration file. '''
+
+ with open(self.path, 'w') as stream:
+ self.data[self._VERSION_NUMBER_KEY] = new_version_number
+ json.dump(self.data, stream, sort_keys=True, indent=2)
+ stream.write(os.linesep)
+
+
def FileEquals(expected_file, actual_file):
'''
Returns whether the two files are equal. Returns False if any of the files
@@ -72,38 +102,6 @@ def GetVersionNumberFromLibraryResources(version_xml):
return int(match.group(1))
-def UpdateVersionNumber(config_file_path, new_version_number):
- '''Updates the version number in the update/preprocess configuration file.'''
-
- with open(config_file_path, 'r+') as stream:
- config_content = stream.read()
- # Implemented as string replacement instead of yaml parsing to preserve
- # whitespace and comments.
- updated = _YAML_VERSION_NUMBER_PATTERN.sub(
- r'\g<1>%s\g<3>' % new_version_number, config_content)
- stream.seek(0)
- stream.write(updated)
-
-
-def GetVersionNumber(config_file_path):
- '''
- Returns the version number from an update/preprocess configuration file.
- '''
-
- return int(GetConfig(config_file_path)[_CONFIG_VERSION_NUMBER_KEY])
-
-
-def GetConfig(path):
- '''
- Returns the configuration from an an update/preprocess configuration file as
- as dictionary.
- '''
-
- with open(path, 'r') as stream:
- config = yaml.load(stream)
- return config
-
-
def MakeLocalCommit(repo_root, files_to_commit, message):
'''Makes a local git commit.'''