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

Side by Side Diff: build/android/play_services/utils.py

Issue 1469913002: Cleanup gms update/preprocess scripts, roll android_tools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add CustomHelpAction to pylib.utils Created 5 years 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
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 ''' 5 '''
6 Utility functions for all things related to manipulating google play services 6 Utility functions for all things related to manipulating google play services
7 related files. 7 related files.
8 ''' 8 '''
9 9
10 import argparse 10 import argparse
(...skipping 25 matching lines...) Expand all
36 class ConfigParser(object): 36 class ConfigParser(object):
37 '''Reads and writes the configuration files for play services related scripts 37 '''Reads and writes the configuration files for play services related scripts
38 38
39 The configuration files are JSON files. Here is the data they are expected 39 The configuration files are JSON files. Here is the data they are expected
40 to contain: 40 to contain:
41 41
42 - version_number 42 - version_number
43 Number. Mirrors @integer/google_play_services_version from the library. 43 Number. Mirrors @integer/google_play_services_version from the library.
44 Example: 815000 44 Example: 815000
45 45
46 - sdk_version
47 Version of the Play Services SDK to retrieve, when preprocessing the
48 library from a maven/gradle repository.
49 Example: "8.1.0"
50
51 - clients
52 List of strings. Name of the clients (or play services modules) to
53 include when preprocessing the library.
54 Example: ["play-services-base", "play-services-cast"]
55
56 - version_xml_path
57 String. Path to the version.xml string describing the current version.
58 Should be relative to the library base directory
59 Example: "res/values/version.xml"
60
61 - locale_whitelist
62 List of strings. List of locales to keep from the resources. Can be
63 obtained by generating an android build and looking at the content of
64 `out/Debug/gen/chrome/java/res`; or looking at the android section in
65 `//chrome/app/generated_resources.grd`
66 Example: ["am", "ar", "bg", "ca", "cs"]
67
46 ''' 68 '''
47 _VERSION_NUMBER_KEY = 'version_number' 69 _VERSION_NUMBER_KEY = 'version_number'
48 70
49 def __init__(self, path): 71 def __init__(self, path):
50 self.path = path 72 self.path = path
51 self.data = {} 73 self._data = {}
52 74
53 with open(path, 'r') as stream: 75 with open(path, 'r') as stream:
54 self.data = json.load(stream) 76 self._data = json.load(stream)
55 77
56 @property 78 @property
57 def version_number(self): 79 def version_number(self):
58 return self.data[self._VERSION_NUMBER_KEY] 80 return self._data[self._VERSION_NUMBER_KEY]
81
82 @property
83 def sdk_version(self):
84 return self._data['sdk_version']
85
86 @property
87 def clients(self):
88 return self._data['clients']
89
90 @property
91 def version_xml_path(self):
92 return self._data['version_xml_path']
93
94 @property
95 def locale_whitelist(self):
96 return self._data['locale_whitelist']
jbudorick 2015/12/10 14:16:31 clients, version_xml_path, and locale_whitelist do
dgn 2015/12/10 14:35:19 But that happens only when trying to read it. If r
jbudorick 2015/12/10 14:37:27 Hm. I'm debating between raising a KeyError and re
dgn 2015/12/10 21:12:57 Done.
59 97
60 def UpdateVersionNumber(self, new_version_number): 98 def UpdateVersionNumber(self, new_version_number):
61 '''Updates the version number and saves it in the configuration file. ''' 99 '''Updates the version number and saves it in the configuration file. '''
62 100
63 with open(self.path, 'w') as stream: 101 with open(self.path, 'w') as stream:
64 self.data[self._VERSION_NUMBER_KEY] = new_version_number 102 self._data[self._VERSION_NUMBER_KEY] = new_version_number
65 json.dump(self.data, stream, sort_keys=True, indent=2) 103 stream.write(DumpTrimmedJson(self._data))
66 stream.write(os.linesep) 104
105 def DumpTrimmedJson(json_data):
106 '''
107 Default formatting when dumping json to string has trailing spaces and lacks
108 a new line at the end. This function fixes that.
109 '''
110
111 out = json.dumps(json_data, sort_keys=True, indent=2)
112 out = out.replace(' ' + os.linesep, os.linesep)
113 return out + os.linesep
67 114
68 115
69 def FileEquals(expected_file, actual_file): 116 def FileEquals(expected_file, actual_file):
70 ''' 117 '''
71 Returns whether the two files are equal. Returns False if any of the files 118 Returns whether the two files are equal. Returns False if any of the files
72 doesn't exist. 119 doesn't exist.
73 ''' 120 '''
74 121
75 if not os.path.isfile(actual_file) or not os.path.isfile(expected_file): 122 if not os.path.isfile(actual_file) or not os.path.isfile(expected_file):
76 return False 123 return False
(...skipping 27 matching lines...) Expand all
104 def MakeLocalCommit(repo_root, files_to_commit, message): 151 def MakeLocalCommit(repo_root, files_to_commit, message):
105 '''Makes a local git commit.''' 152 '''Makes a local git commit.'''
106 153
107 logging.debug('Staging files (%s) for commit.', files_to_commit) 154 logging.debug('Staging files (%s) for commit.', files_to_commit)
108 if cmd_helper.Call(['git', 'add'] + files_to_commit, cwd=repo_root) != 0: 155 if cmd_helper.Call(['git', 'add'] + files_to_commit, cwd=repo_root) != 0:
109 raise Exception('The local commit failed.') 156 raise Exception('The local commit failed.')
110 157
111 logging.debug('Committing.') 158 logging.debug('Committing.')
112 if cmd_helper.Call(['git', 'commit', '-m', message], cwd=repo_root) != 0: 159 if cmd_helper.Call(['git', 'commit', '-m', message], cwd=repo_root) != 0:
113 raise Exception('The local commit failed.') 160 raise Exception('The local commit failed.')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698