Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: build/check_play_services_version.py

Issue 1152203003: Add script to validate installed Android SDK packages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved.
Andrew Hayden (chromium.org) 2015/05/28 12:55:00 It's totally 2015, man.
dgn 2015/06/08 14:34:09 Done.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 '''Checks the status of an android SDK package.
7
8 Verifies the given package has been installed from the Android SDK Manager and
9 that it is at an appropriate version. Prints only when there is an error.
10 '''
11
12 import argparse
13 import os
14 import re
15 import json
16
17 UDPATE_SCRIPT_PATH = 'build/install-build-deps-android.sh'
18
19 SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__),
20 'android_sdk_extras.json')
21
22 REPO_NOT_FOUND_MSG = ('Could not find the Google Play services package in '
23 '{checked_location}. Please run {script} to download it. '
24 'You might have to run it as root.')
25 UPDATE_NEEDED_MSG = ('Google Play services package version {required_version} '
26 'is required. Version {actual_version} found. Please run '
27 '{script} to update it. You might have to run it as root.')
28 REQUIRED_VERSION_ERROR_MSG = ('Could not retrieve the required Google Play '
29 'services package version.')
30
31 BOLD_STYLE = '\033[1m'
32 END_STYLE = '\033[0m'
33
34 def print_and_exit(msg):
35 """Should always exit with a success code for gyp to pick up the message. """
36 print('---------------\n')
37 print(BOLD_STYLE + msg + END_STYLE)
38 print('\n---------------')
39 exit(0)
40
41
42 def parse_args():
43 parser = argparse.ArgumentParser(description=__doc__)
44 parser.add_argument('package_id',
45 help=('Id of the package to check for. The list of '
46 'possible ids can be obtained by running '
47 'third_party/android_tools/sdk/tools/android list '
48 'sdk --extended'))
49 parser.add_argument('package_location',
50 help=('Absolute path to the expected install location of '
51 'the package'))
52
53 return parser.parse_args()
54
55
56 def get_required_version(package_id):
57 with open(SDK_EXTRAS_JSON_FILE, 'r') as json_file:
58 packages = json.load(json_file)
59
60 for package in packages:
61 if package['package_id'] == package_id:
62 return int(package['version'].split('.')[0])
63
64 print_and_exit(REQUIRED_VERSION_ERROR_MSG)
65
66
67 def check_m2repo_version(location, required_version):
68 version_file_path = os.path.join(location, 'source.properties')
69 # Extracts the version of the package described by the property file. We only
70 # care about the major version number here.
71 version_pattern = re.compile(r'^Pkg\.Revision=(?P<version>\d+).*$',
72 re.MULTILINE)
73
74 if not os.path.isdir(location) or not os.path.isfile(version_file_path):
75 print_and_exit(REPO_NOT_FOUND_MSG.format(
76 checked_location=location,
77 script=UDPATE_SCRIPT_PATH))
78
79 with open(version_file_path, 'r') as f:
80 match = version_pattern.search(f.read())
81
82 if not match:
83 print_and_exit(REPO_NOT_FOUND_MSG.format(
84 checked_location=location,
85 script=UDPATE_SCRIPT_PATH))
86
87 pkg_version = int(match.group('version'))
88 if pkg_version < required_version:
89 print_and_exit(UPDATE_NEEDED_MSG.format(
90 required_version=required_version,
91 actual_version=pkg_version,
92 script=UDPATE_SCRIPT_PATH))
93
94 # Everything looks ok, print nothing.
95
96
97 if __name__ == '__main__':
98 args = parse_args()
99 required_version = get_required_version(args.package_id)
100 check_m2repo_version(args.package_location, required_version)
101 exit(0)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698