OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | |
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} ' | |
cjhopman
2015/05/22 20:25:22
Places in this file explicitly refer to google pla
dgn
2015/06/08 14:34:10
Done.
| |
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' | |
cjhopman
2015/05/22 20:25:22
I don't think I'd hardcode in these escape codes.
dgn
2015/06/08 14:34:09
Done.
| |
32 END_STYLE = '\033[0m' | |
33 | |
34 def print_and_exit(msg): | |
cjhopman
2015/05/22 20:25:22
python functions use CapWords() style
dgn
2015/06/08 14:34:09
Done.
| |
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) | |
OLD | NEW |