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

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

Issue 2209233002: ▶ Update the Play services to 9.8 and load from AARs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mention the configuration file in the upload command line help Created 4 years, 1 month 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''Unittests for update.py. 6 '''Unittests for update.py.
7 7
8 They set up a temporary directory that is used to mock a bucket, the directory 8 They set up a temporary directory that is used to mock a bucket, the directory
9 containing the configuration files and the android sdk directory. 9 containing the configuration files and the android sdk directory.
10 10
11 Tests run the script with various inputs and check the status of the filesystem 11 Tests run the script with various inputs and check the status of the filesystem
12 ''' 12 '''
13 13
14 import contextlib
15 import logging
16 import os
14 import shutil 17 import shutil
18 import sys
15 import tempfile 19 import tempfile
16 import unittest 20 import unittest
17 import os
18 import sys
19 import zipfile 21 import zipfile
20 import contextlib
21 22
22 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) 23 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
23 from play_services import update 24 from play_services import update
25 import devil_chromium # pylint: disable=import-error,unused-import
26 from devil.utils import cmd_helper
24 27
25 28
26 class TestFunctions(unittest.TestCase): 29 class TestFunctions(unittest.TestCase):
27 DEFAULT_CONFIG_VERSION = 42 30 DEFAULT_CONFIG_VERSION = '1.2.3'
28 DEFAULT_LICENSE = 'Default License' 31 DEFAULT_LICENSE = 'Default License'
29 DEFAULT_ZIP_SHA1 = 'zip0and0filling0to0forty0chars0000000000' 32 DEFAULT_ZIP_SHA1 = 'zip0and0filling0to0forty0chars0000000000'
30 33
31 def __init__(self, *args, **kwargs): 34 def __init__(self, *args, **kwargs):
32 super(TestFunctions, self).__init__(*args, **kwargs) 35 super(TestFunctions, self).__init__(*args, **kwargs)
33 self.paths = None # Initialized in SetUpWorkdir 36 self.paths = None # Initialized in SetUpWorkdir
34 self.workdir = None # Initialized in setUp 37 self.workdir = None # Initialized in setUp
35 38
39 # Uncomment for debug logs.
40 # logging.basicConfig(level=logging.DEBUG)
41
36 #override 42 #override
37 def setUp(self): 43 def setUp(self):
38 self.workdir = tempfile.mkdtemp() 44 self.workdir = tempfile.mkdtemp()
39 45
40 #override 46 #override
41 def tearDown(self): 47 def tearDown(self):
42 shutil.rmtree(self.workdir) 48 shutil.rmtree(self.workdir)
43 self.workdir = None 49 self.workdir = None
44 50
45 def testUpload(self): 51 def testUpload(self):
46 version = 1337 52 version = '2.3.4'
47 self.SetUpWorkdir( 53 self.SetUpWorkdir(
48 xml_version=version,
49 gms_lib=True, 54 gms_lib=True,
55 config_version=version,
50 source_prop=True) 56 source_prop=True)
51 57
52 status = update.main([ 58 status = update.main([
53 'upload', 59 'upload',
54 '--dry-run', 60 '--dry-run',
55 '--skip-git', 61 '--skip-git',
56 '--bucket', self.paths.bucket, 62 '--bucket', self.paths.bucket,
57 '--config', self.paths.config_file, 63 '--config', self.paths.config_file,
58 '--sdk-root', self.paths.sdk_root 64 '--sdk-root', self.paths.gms.sdk_root
59 ]) 65 ])
60 self.assertEqual(status, 0, 'the command should have succeeded.') 66 self.assertEqual(status, 0, 'the command should have succeeded.')
61 67
62 # bucket should contain license, name = license.sha1 68 # bucket should contain license, name = content from LICENSE.sha1
63 self.assertTrue(os.path.isfile(self.paths.config_license_sha1)) 69 self.assertTrue(os.path.isfile(self.paths.config_license_sha1))
64 license_sha1 = _GetFileContent(self.paths.config_license_sha1) 70 license_sha1 = _GetFileContent(self.paths.config_license_sha1)
65 bucket_license = os.path.join(self.paths.bucket, str(version), 71 bucket_license = os.path.join(self.paths.bucket, version, license_sha1)
66 license_sha1)
67 self.assertTrue(os.path.isfile(bucket_license)) 72 self.assertTrue(os.path.isfile(bucket_license))
68 self.assertEqual(_GetFileContent(bucket_license), self.DEFAULT_LICENSE) 73 self.assertEqual(_GetFileContent(bucket_license), self.DEFAULT_LICENSE)
69 74
70 # bucket should contain zip, name = zip.sha1 75 # bucket should contain zip, name = content from zip.sha1
71 self.assertTrue(os.path.isfile(self.paths.config_zip_sha1)) 76 self.assertTrue(os.path.isfile(self.paths.config_zip_sha1))
72 bucket_zip = os.path.join(self.paths.bucket, str(version), 77 bucket_zip = os.path.join(self.paths.bucket, str(version),
73 _GetFileContent(self.paths.config_zip_sha1)) 78 _GetFileContent(self.paths.config_zip_sha1))
74 self.assertTrue(os.path.isfile(bucket_zip)) 79 self.assertTrue(os.path.isfile(bucket_zip))
75 80
76 # unzip, should contain expected files 81 # unzip, should contain expected files
77 with zipfile.ZipFile(bucket_zip, "r") as bucket_zip_file: 82 with zipfile.ZipFile(bucket_zip, "r") as bucket_zip_file:
78 self.assertEqual(bucket_zip_file.namelist(), 83 self.assertEqual(bucket_zip_file.namelist(),
79 ['dummy_file', 'res/values/version.xml']) 84 ['com/google/android/gms/client/2.3.4/client-2.3.4.aar'])
80
81 def testUploadAlreadyLatestVersion(self):
82 self.SetUpWorkdir(
83 xml_version=self.DEFAULT_CONFIG_VERSION,
84 gms_lib=True,
85 source_prop=True)
86
87 status = update.main([
88 'upload',
89 '--dry-run',
90 '--skip-git',
91 '--bucket', self.paths.bucket,
92 '--config', self.paths.config_file,
93 '--sdk-root', self.paths.sdk_root,
94 ])
95 self.assertEqual(status, 0, 'the command should have succeeded.')
96
97 # bucket should be empty
98 self.assertFalse(os.listdir(self.paths.bucket))
99 self.assertFalse(os.path.isfile(self.paths.config_license_sha1))
100 self.assertFalse(os.path.isfile(self.paths.config_zip_sha1))
101 85
102 def testDownload(self): 86 def testDownload(self):
103 self.SetUpWorkdir(populate_bucket=True) 87 self.SetUpWorkdir(populate_bucket=True)
104 88
105 with _MockedInput('y'): 89 with _MockedInput('y'):
106 status = update.main([ 90 status = update.main([
107 'download', 91 'download',
108 '--dry-run', 92 '--dry-run',
109 '--bucket', self.paths.bucket, 93 '--bucket', self.paths.bucket,
110 '--config', self.paths.config_file, 94 '--config', self.paths.config_file,
111 '--sdk-root', self.paths.sdk_root, 95 '--sdk-root', self.paths.gms.sdk_root,
112 ]) 96 ])
113 97
114 self.assertEqual(status, 0, 'the command should have succeeded.') 98 self.assertEqual(status, 0, 'the command should have succeeded.')
115 99
116 # sdk_root should contain zip contents, zip sha1, license 100 # sdk_root should contain zip contents, zip sha1, license
117 self.assertTrue(os.path.isfile(os.path.join(self.paths.gms_lib, 101 self.assertTrue(os.path.isfile(self.paths.gms.client_paths[0]))
118 'dummy_file'))) 102 self.assertTrue(os.path.isfile(self.paths.gms.lib_zip_sha1))
119 self.assertTrue(os.path.isfile(self.paths.gms_root_sha1)) 103 self.assertTrue(os.path.isfile(self.paths.gms.license))
120 self.assertTrue(os.path.isfile(self.paths.gms_root_license)) 104 self.assertEquals(_GetFileContent(self.paths.gms.license),
121 self.assertEquals(_GetFileContent(self.paths.gms_root_license),
122 self.DEFAULT_LICENSE) 105 self.DEFAULT_LICENSE)
123 106
124 def testDownloadBot(self): 107 def testDownloadBot(self):
125 self.SetUpWorkdir(populate_bucket=True, bot_env=True) 108 self.SetUpWorkdir(populate_bucket=True, bot_env=True)
126 109
127 # No need to type 'y' on bots 110 # No need to type 'y' on bots
128 status = update.main([ 111 status = update.main([
129 'download', 112 'download',
130 '--dry-run', 113 '--dry-run',
131 '--bucket', self.paths.bucket, 114 '--bucket', self.paths.bucket,
132 '--config', self.paths.config_file, 115 '--config', self.paths.config_file,
133 '--sdk-root', self.paths.sdk_root, 116 '--sdk-root', self.paths.gms.sdk_root,
134 ]) 117 ])
135 118
136 self.assertEqual(status, 0, 'the command should have succeeded.') 119 self.assertEqual(status, 0, 'the command should have succeeded.')
137 120
138 # sdk_root should contain zip contents, zip sha1, license 121 # sdk_root should contain zip contents, zip sha1, license
139 self.assertTrue(os.path.isfile(os.path.join(self.paths.gms_lib, 122 self.assertTrue(os.path.isfile(self.paths.gms.client_paths[0]))
140 'dummy_file'))) 123 self.assertTrue(os.path.isfile(self.paths.gms.lib_zip_sha1))
141 self.assertTrue(os.path.isfile(self.paths.gms_root_sha1)) 124 self.assertTrue(os.path.isfile(self.paths.gms.license))
142 self.assertTrue(os.path.isfile(self.paths.gms_root_license)) 125 self.assertEquals(_GetFileContent(self.paths.gms.license),
143 self.assertEquals(_GetFileContent(self.paths.gms_root_license),
144 self.DEFAULT_LICENSE) 126 self.DEFAULT_LICENSE)
145 127
146 def testDownloadAlreadyUpToDate(self): 128 def testDownloadAlreadyUpToDate(self):
147 self.SetUpWorkdir( 129 self.SetUpWorkdir(
148 populate_bucket=True, 130 populate_bucket=True,
149 existing_zip_sha1=self.DEFAULT_ZIP_SHA1) 131 existing_zip_sha1=self.DEFAULT_ZIP_SHA1)
150 132
151 status = update.main([ 133 status = update.main([
152 'download', 134 'download',
153 '--dry-run', 135 '--dry-run',
154 '--bucket', self.paths.bucket, 136 '--bucket', self.paths.bucket,
155 '--config', self.paths.config_file, 137 '--config', self.paths.config_file,
156 '--sdk-root', self.paths.sdk_root, 138 '--sdk-root', self.paths.gms.sdk_root,
157 ]) 139 ])
158 140
159 self.assertEqual(status, 0, 'the command should have succeeded.') 141 self.assertEqual(status, 0, 'the command should have succeeded.')
160 142
161 # there should not be new files downloaded to sdk_root 143 # there should not be new files downloaded to sdk_root
162 self.assertFalse(os.path.isfile(os.path.join(self.paths.gms_lib, 144 self.assertFalse(os.path.isfile(os.path.join(self.paths.gms.client_paths[0],
163 'dummy_file'))) 145 'dummy_file')))
164 self.assertFalse(os.path.isfile(self.paths.gms_root_license)) 146 self.assertFalse(os.path.isfile(self.paths.gms.license))
165 147
166 def testDownloadAcceptedLicense(self): 148 def testDownloadAcceptedLicense(self):
167 self.SetUpWorkdir( 149 self.SetUpWorkdir(
168 populate_bucket=True, 150 populate_bucket=True,
169 existing_license=self.DEFAULT_LICENSE) 151 existing_license=self.DEFAULT_LICENSE)
170 152
171 # License already accepted, no need to type 153 # License already accepted, no need to type
172 status = update.main([ 154 status = update.main([
173 'download', 155 'download',
174 '--dry-run', 156 '--dry-run',
175 '--bucket', self.paths.bucket, 157 '--bucket', self.paths.bucket,
176 '--config', self.paths.config_file, 158 '--config', self.paths.config_file,
177 '--sdk-root', self.paths.sdk_root, 159 '--sdk-root', self.paths.gms.sdk_root,
178 ]) 160 ])
179 161
180 self.assertEqual(status, 0, 'the command should have succeeded.') 162 self.assertEqual(status, 0, 'the command should have succeeded.')
181 163
182 # sdk_root should contain zip contents, zip sha1, license 164 # sdk_root should contain zip contents, zip sha1, license
183 self.assertTrue(os.path.isfile(os.path.join(self.paths.gms_lib, 165 self.assertTrue(os.path.isfile(self.paths.gms.client_paths[0]))
184 'dummy_file'))) 166 self.assertTrue(os.path.isfile(self.paths.gms.lib_zip_sha1))
185 self.assertTrue(os.path.isfile(self.paths.gms_root_sha1)) 167 self.assertTrue(os.path.isfile(self.paths.gms.license))
186 self.assertTrue(os.path.isfile(self.paths.gms_root_license)) 168 self.assertEquals(_GetFileContent(self.paths.gms.license),
187 self.assertEquals(_GetFileContent(self.paths.gms_root_license),
188 self.DEFAULT_LICENSE) 169 self.DEFAULT_LICENSE)
189 170
190 def testDownloadNewLicense(self): 171 def testDownloadNewLicense(self):
191 self.SetUpWorkdir( 172 self.SetUpWorkdir(
192 populate_bucket=True, 173 populate_bucket=True,
193 existing_license='Old license') 174 existing_license='Old license')
194 175
195 with _MockedInput('y'): 176 with _MockedInput('y'):
196 status = update.main([ 177 status = update.main([
197 'download', 178 'download',
198 '--dry-run', 179 '--dry-run',
199 '--bucket', self.paths.bucket, 180 '--bucket', self.paths.bucket,
200 '--config', self.paths.config_file, 181 '--config', self.paths.config_file,
201 '--sdk-root', self.paths.sdk_root, 182 '--sdk-root', self.paths.gms.sdk_root,
202 ]) 183 ])
203 184
204 self.assertEqual(status, 0, 'the command should have succeeded.') 185 self.assertEqual(status, 0, 'the command should have succeeded.')
205 186
206 # sdk_root should contain zip contents, zip sha1, NEW license 187 # sdk_root should contain zip contents, zip sha1, NEW license
207 self.assertTrue(os.path.isfile(os.path.join(self.paths.gms_lib, 188 self.assertTrue(os.path.isfile(self.paths.gms.client_paths[0]))
208 'dummy_file'))) 189 self.assertTrue(os.path.isfile(self.paths.gms.lib_zip_sha1))
209 self.assertTrue(os.path.isfile(self.paths.gms_root_sha1)) 190 self.assertTrue(os.path.isfile(self.paths.gms.license))
210 self.assertTrue(os.path.isfile(self.paths.gms_root_license)) 191 self.assertEquals(_GetFileContent(self.paths.gms.license),
211 self.assertEquals(_GetFileContent(self.paths.gms_root_license),
212 self.DEFAULT_LICENSE) 192 self.DEFAULT_LICENSE)
213 193
214 def testDownloadRefusedLicense(self): 194 def testDownloadRefusedLicense(self):
215 self.SetUpWorkdir( 195 self.SetUpWorkdir(
216 populate_bucket=True, 196 populate_bucket=True,
217 existing_license='Old license') 197 existing_license='Old license')
218 198
219 with _MockedInput('n'): 199 with _MockedInput('n'):
220 status = update.main([ 200 status = update.main([
221 'download', 201 'download',
222 '--dry-run', 202 '--dry-run',
223 '--bucket', self.paths.bucket, 203 '--bucket', self.paths.bucket,
224 '--config', self.paths.config_file, 204 '--config', self.paths.config_file,
225 '--sdk-root', self.paths.sdk_root, 205 '--sdk-root', self.paths.gms.sdk_root,
226 ]) 206 ])
227 207
228 self.assertEqual(status, 0, 'the command should have succeeded.') 208 self.assertEqual(status, 0, 'the command should have succeeded.')
229 209
230 # there should not be new files downloaded to sdk_root 210 # there should not be new files downloaded to sdk_root
231 self.assertFalse(os.path.isfile(os.path.join(self.paths.gms_lib, 211 self.assertFalse(os.path.isfile(os.path.join(self.paths.gms.client_paths[0],
232 'dummy_file'))) 212 'dummy_file')))
233 self.assertEquals(_GetFileContent(self.paths.gms_root_license), 213 self.assertEquals(_GetFileContent(self.paths.gms.license),
234 'Old license') 214 'Old license')
235 215
236 def testDownloadNoAndroidSDK(self): 216 def testDownloadNoAndroidSDK(self):
237 self.SetUpWorkdir( 217 self.SetUpWorkdir(
238 populate_bucket=True, 218 populate_bucket=True,
239 existing_license='Old license') 219 existing_license='Old license')
240 220
241 non_existing_sdk_root = os.path.join(self.workdir, 'non_existing_sdk_root') 221 non_existing_sdk_root = os.path.join(self.workdir, 'non_existing_sdk_root')
242 # Should not run, no typing needed 222 # Should not run, no typing needed
243 status = update.main([ 223 status = update.main([
244 'download', 224 'download',
245 '--dry-run', 225 '--dry-run',
246 '--bucket', self.paths.bucket, 226 '--bucket', self.paths.bucket,
247 '--config', self.paths.config_file, 227 '--config', self.paths.config_file,
248 '--sdk-root', non_existing_sdk_root, 228 '--sdk-root', non_existing_sdk_root,
249 ]) 229 ])
250 230
251 self.assertEqual(status, 0, 'the command should have succeeded.') 231 self.assertEqual(status, 0, 'the command should have succeeded.')
252 self.assertFalse(os.path.isdir(non_existing_sdk_root)) 232 self.assertFalse(os.path.isdir(non_existing_sdk_root))
253 233
254 def SetUpWorkdir(self, 234 def SetUpWorkdir(self,
255 bot_env=False, 235 bot_env=False,
256 config_version=DEFAULT_CONFIG_VERSION, 236 config_version=DEFAULT_CONFIG_VERSION,
257 existing_license=None, 237 existing_license=None,
258 existing_zip_sha1=None, 238 existing_zip_sha1=None,
259 gms_lib=False, 239 gms_lib=False,
260 populate_bucket=False, 240 populate_bucket=False,
261 source_prop=None, 241 source_prop=None):
262 xml_version=None):
263 '''Prepares workdir by putting it in the specified state 242 '''Prepares workdir by putting it in the specified state
264 243
265 Args: 244 Args:
266 - general 245 - general
267 bot_env: sets or unsets CHROME_HEADLESS 246 bot_env: sets or unsets CHROME_HEADLESS
268 247
269 - bucket 248 - bucket
270 populate_bucket: boolean. Populate the bucket with a zip and license 249 populate_bucket: boolean. Populate the bucket with a zip and license
271 file. The sha1s will be copied to the config directory 250 file. The sha1s will be copied to the config directory
272 251
273 - config 252 - config
274 config_version: number. Version of the current SDK. Defaults to 253 config_version: number. Version of the current SDK. Defaults to
275 `self.DEFAULT_CONFIG_VERSION` 254 `self.DEFAULT_CONFIG_VERSION`
276 255
277 - sdk_root 256 - sdk_root
278 existing_license: string. Create a LICENSE file setting the specified 257 existing_license: string. Create a LICENSE file setting the specified
279 text as content of the currently accepted license. 258 text as content of the currently accepted license.
280 existing_zip_sha1: string. Create a sha1 file setting the specified 259 existing_zip_sha1: string. Create a sha1 file setting the specified
281 hash as hash of the SDK supposed to be installed 260 hash as hash of the SDK supposed to be installed
282 gms_lib: boolean. Create a dummy file in the location of the play 261 gms_lib: boolean. Create a dummy file in the location of the play
283 services SDK. 262 services SDK.
284 source_prop: boolean. Create a source.properties file that contains 263 source_prop: boolean. Create a source.properties file that contains
285 the license to upload. 264 the license to upload.
286 xml_version: number. Create a version.xml file with the specified
287 version that is used when uploading
288 ''' 265 '''
289 self.paths = Paths(self.workdir) 266 client_name = 'client'
267 self.paths = Paths(self.workdir, config_version, [client_name])
290 268
291 # Create the main directories 269 # Create the main directories
292 _MakeDirs(self.paths.sdk_root) 270 _MakeDirs(self.paths.gms.sdk_root)
293 _MakeDirs(self.paths.config_dir) 271 _MakeDirs(self.paths.config_dir)
294 _MakeDirs(self.paths.bucket) 272 _MakeDirs(self.paths.bucket)
295 273
296 # is not configured via argument. 274 # is not configured via argument.
297 update.SHA1_DIRECTORY = self.paths.config_dir 275 update.SHA1_DIRECTORY = self.paths.config_dir
298 276
299 os.environ['CHROME_HEADLESS'] = '1' if bot_env else '' 277 os.environ['CHROME_HEADLESS'] = '1' if bot_env else ''
300 278
301 if config_version: 279 if config_version:
302 _MakeDirs(os.path.dirname(self.paths.config_file)) 280 _MakeDirs(os.path.dirname(self.paths.config_file))
303 with open(self.paths.config_file, 'w') as stream: 281 with open(self.paths.config_file, 'w') as stream:
304 stream.write(('{"version_number":%d,' 282 stream.write(('{"clients": ["%s"],'
305 '"version_xml_path": "res/values/version.xml"}' 283 '"version_number": "%s"}'
306 '\n') % config_version) 284 '\n') % (client_name, config_version))
307 285
308 if existing_license: 286 if existing_license:
309 _MakeDirs(self.paths.gms_root) 287 _MakeDirs(self.paths.gms.package)
310 with open(self.paths.gms_root_license, 'w') as stream: 288 with open(self.paths.gms.license, 'w') as stream:
311 stream.write(existing_license) 289 stream.write(existing_license)
312 290
313 if existing_zip_sha1: 291 if existing_zip_sha1:
314 _MakeDirs(self.paths.gms_root) 292 _MakeDirs(self.paths.gms.package)
315 with open(self.paths.gms_root_sha1, 'w') as stream: 293 with open(self.paths.gms.lib_zip_sha1, 'w') as stream:
316 stream.write(existing_zip_sha1) 294 stream.write(existing_zip_sha1)
317 295
318 if gms_lib: 296 if gms_lib:
319 _MakeDirs(self.paths.gms_lib) 297 _MakeDirs(os.path.dirname(self.paths.gms.client_paths[0]))
320 with open(os.path.join(self.paths.gms_lib, 'dummy_file'), 'w') as stream: 298 with open(self.paths.gms.client_paths[0], 'w') as stream:
321 stream.write('foo\n') 299 stream.write('foo\n')
322 300
323 if source_prop: 301 if source_prop:
324 _MakeDirs(os.path.dirname(self.paths.source_prop)) 302 _MakeDirs(os.path.dirname(self.paths.gms.source_prop))
325 with open(self.paths.source_prop, 'w') as stream: 303 with open(self.paths.gms.source_prop, 'w') as stream:
326 stream.write('Foo=Bar\n' 304 stream.write('Foo=Bar\n'
327 'Pkg.License=%s\n' 305 'Pkg.License=%s\n'
328 'Baz=Fizz\n' % self.DEFAULT_LICENSE) 306 'Baz=Fizz\n' % self.DEFAULT_LICENSE)
329 307
330 if populate_bucket: 308 if populate_bucket:
331 _MakeDirs(self.paths.config_dir) 309 _MakeDirs(self.paths.config_dir)
332 bucket_dir = os.path.join(self.paths.bucket, str(config_version)) 310 bucket_dir = os.path.join(self.paths.bucket, str(config_version))
333 _MakeDirs(bucket_dir) 311 _MakeDirs(bucket_dir)
334 312
335 # TODO(dgn) should we use real sha1s? comparison with the real sha1 is 313 # TODO(dgn) should we use real sha1s? comparison with the real sha1 is
336 # done but does not do anything other than displaying a message. 314 # done but does not do anything other than displaying a message.
337 config_license_sha1 = 'license0and0filling0to0forty0chars000000' 315 config_license_sha1 = 'license0and0filling0to0forty0chars000000'
338 with open(self.paths.config_license_sha1, 'w') as stream: 316 with open(self.paths.config_license_sha1, 'w') as stream:
339 stream.write(config_license_sha1) 317 stream.write(config_license_sha1)
340 318
341 with open(os.path.join(bucket_dir, config_license_sha1), 'w') as stream: 319 with open(os.path.join(bucket_dir, config_license_sha1), 'w') as stream:
342 stream.write(self.DEFAULT_LICENSE) 320 stream.write(self.DEFAULT_LICENSE)
343 321
344 config_zip_sha1 = self.DEFAULT_ZIP_SHA1 322 config_zip_sha1 = self.DEFAULT_ZIP_SHA1
345 with open(self.paths.config_zip_sha1, 'w') as stream: 323 with open(self.paths.config_zip_sha1, 'w') as stream:
346 stream.write(config_zip_sha1) 324 stream.write(config_zip_sha1)
347 325
348 pre_zip_lib = os.path.join(self.workdir, 'pre_zip_lib') 326 pre_zip_client = os.path.join(
327 self.workdir,
328 'pre_zip_lib',
329 os.path.relpath(self.paths.gms.client_paths[0],
330 self.paths.gms.package))
331 pre_zip_lib = os.path.dirname(pre_zip_client)
349 post_zip_lib = os.path.join(bucket_dir, config_zip_sha1) 332 post_zip_lib = os.path.join(bucket_dir, config_zip_sha1)
333 print(pre_zip_lib, post_zip_lib)
350 _MakeDirs(pre_zip_lib) 334 _MakeDirs(pre_zip_lib)
351 with open(os.path.join(pre_zip_lib, 'dummy_file'), 'w') as stream: 335 with open(pre_zip_client, 'w') as stream:
352 stream.write('foo\n') 336 stream.write('foo\n')
353 shutil.make_archive(post_zip_lib, 'zip', pre_zip_lib)
354 # make_archive appends .zip
355 shutil.move(post_zip_lib + '.zip', post_zip_lib)
356 337
357 if xml_version: 338 # pylint: disable=protected-access
358 _MakeDirs(os.path.dirname(self.paths.xml_version)) 339 update._ZipLibrary(post_zip_lib, [pre_zip_client], os.path.join(
359 with open(self.paths.xml_version, 'w') as stream: 340 self.workdir, 'pre_zip_lib'))
360 stream.write( 341
361 '<?xml version="1.0" encoding="utf-8"?>\n' 342 if logging.getLogger().isEnabledFor(logging.DEBUG):
362 '<resources>\n' 343 cmd_helper.Call(['tree', self.workdir])
363 ' <integer name="google_play_services_version">%d</integer>\n'
364 '</resources>\n' % xml_version)
365 344
366 345
367 class Paths(object): 346 class Paths(object):
368 '''Declaration of the paths commonly manipulated in the tests.''' 347 '''Declaration of the paths commonly manipulated in the tests.'''
369 348
370 def __init__(self, workdir): 349 def __init__(self, workdir, version, clients):
371 self.bucket = os.path.join(workdir, 'bucket') 350 self.bucket = os.path.join(workdir, 'bucket')
372 351
373 self.config_dir = os.path.join(workdir, 'config') 352 self.config_dir = os.path.join(workdir, 'config')
374 self.config_file = os.path.join(self.config_dir, 'config.json') 353 self.config_file = os.path.join(self.config_dir, 'config.json')
375 self.config_license_sha1 = os.path.join(self.config_dir, 'LICENSE.sha1') 354 self.config_license_sha1 = os.path.join(self.config_dir, 'LICENSE.sha1')
376 self.config_zip_sha1 = os.path.join( 355 self.config_zip_sha1 = os.path.join(
377 self.config_dir, 356 self.config_dir,
378 'google_play_services_library.zip.sha1') 357 'google_play_services_library.zip.sha1')
379 358 self.gms = update.PlayServicesPaths(os.path.join(workdir, 'sdk_root'),
380 self.sdk_root = os.path.join(workdir, 'sdk_root') 359 version, clients)
381 self.gms_root = os.path.join(self.sdk_root, 'extras', 'google',
382 'google_play_services')
383 self.gms_root_sha1 = os.path.join(self.gms_root,
384 'google_play_services_library.zip.sha1')
385 self.gms_root_license = os.path.join(self.gms_root, 'LICENSE')
386 self.source_prop = os.path.join(self.gms_root, 'source.properties')
387 self.gms_lib = os.path.join(self.gms_root, 'libproject',
388 'google-play-services_lib')
389 self.xml_version = os.path.join(self.gms_lib, 'res', 'values',
390 'version.xml')
391 360
392 361
393 def _GetFileContent(file_path): 362 def _GetFileContent(file_path):
394 with open(file_path, 'r') as stream: 363 with open(file_path, 'r') as stream:
395 return stream.read() 364 return stream.read()
396 365
397 366
398 def _MakeDirs(path): 367 def _MakeDirs(path):
399 '''Avoids having to do the error handling everywhere.''' 368 '''Avoids having to do the error handling everywhere.'''
400 if not os.path.exists(path): 369 if not os.path.exists(path):
401 os.makedirs(path) 370 os.makedirs(path)
402 371
403 372
404 @contextlib.contextmanager 373 @contextlib.contextmanager
405 def _MockedInput(typed_string): 374 def _MockedInput(typed_string):
406 '''Makes raw_input return |typed_string| while inside the context.''' 375 '''Makes raw_input return |typed_string| while inside the context.'''
407 try: 376 try:
408 original_raw_input = __builtins__.raw_input 377 if isinstance(__builtins__, dict):
409 __builtins__.raw_input = lambda _: typed_string 378 original_raw_input = __builtins__['raw_input']
379 __builtins__['raw_input'] = lambda _: typed_string
380 else:
381 original_raw_input = __builtins__.raw_input
382 __builtins__.raw_input = lambda _: typed_string
410 yield 383 yield
411 finally: 384 finally:
412 __builtins__.raw_input = original_raw_input 385 if isinstance(__builtins__, dict):
386 __builtins__['raw_input'] = original_raw_input
387 else:
388 __builtins__.raw_input = original_raw_input
413 389
414 390
415 if __name__ == '__main__': 391 if __name__ == '__main__':
416 unittest.main() 392 unittest.main()
OLDNEW
« no previous file with comments | « build/android/play_services/update.py ('k') | build/secondary/third_party/android_tools/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698