OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright 2016 Google Inc. All Rights Reserved. | 3 # Copyright 2016 Google Inc. All Rights Reserved. |
4 # | 4 # |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
8 # | 8 # |
9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
10 # | 10 # |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 """ | 30 """ |
31 | 31 |
32 import sys | 32 import sys |
33 import argparse | 33 import argparse |
34 import locale | 34 import locale |
35 import math | 35 import math |
36 import os | 36 import os |
37 import subprocess | 37 import subprocess |
38 | 38 |
| 39 _FILEBYFILE_JAR_PATH = os.path.abspath( |
| 40 os.path.join(os.path.dirname(__file__), 'lib', 'file-by-file-tools.jar')) |
| 41 |
39 bsdiff_path = None | 42 bsdiff_path = None |
40 gzip_path = None | 43 gzip_path = None |
41 head_path = None | 44 head_path = None |
42 tail_path = None | 45 tail_path = None |
43 bunzip2_path = None | 46 bunzip2_path = None |
44 java_path = None | 47 java_path = None |
45 | 48 |
46 | 49 |
47 def find_bins_or_die(): | 50 def find_bins_or_die(): |
48 """Checks that all the binaries needed are available. | 51 """Checks that all the binaries needed are available. |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 else: | 255 else: |
253 filebyfile_patch_path = temp_path + '.filebyfile' | 256 filebyfile_patch_path = temp_path + '.filebyfile' |
254 gzipped_filebyfile_patch_path = filebyfile_patch_path + '.gz' | 257 gzipped_filebyfile_patch_path = filebyfile_patch_path + '.gz' |
255 if os.path.exists(gzipped_filebyfile_patch_path): | 258 if os.path.exists(gzipped_filebyfile_patch_path): |
256 os.remove(gzipped_filebyfile_patch_path) | 259 os.remove(gzipped_filebyfile_patch_path) |
257 | 260 |
258 # file by file patch | 261 # file by file patch |
259 # We use a jar from https://github.com/andrewhayden/archive-patcher | 262 # We use a jar from https://github.com/andrewhayden/archive-patcher |
260 if os.path.exists(filebyfile_patch_path): os.remove(filebyfile_patch_path) | 263 if os.path.exists(filebyfile_patch_path): os.remove(filebyfile_patch_path) |
261 p = subprocess.Popen( | 264 p = subprocess.Popen( |
262 [java_path, '-jar', 'lib/file-by-file-tools.jar', '--generate', | 265 [java_path, '-jar', _FILEBYFILE_JAR_PATH, '--generate', '--old', old_file, |
263 '--old', old_file, '--new', new_file, '--patch', filebyfile_patch_path], | 266 '--new', new_file, '--patch', filebyfile_patch_path], |
264 shell=False) | 267 shell=False) |
265 ret_code = p.wait() | 268 ret_code = p.wait() |
266 if ret_code != 0: raise Exception( | 269 if ret_code != 0: raise Exception( |
267 'Problem creating file by file patch, returned code: %s' % ret_code) | 270 'Problem creating file by file patch, returned code: %s' % ret_code) |
268 | 271 |
269 # gzip file by file patch and get its size | 272 # gzip file by file patch and get its size |
270 subprocess.check_output([gzip_path, '-9', filebyfile_patch_path]) | 273 subprocess.check_output([gzip_path, '-9', filebyfile_patch_path]) |
271 gzipped_filebyfile_patch_size = os.stat(gzipped_filebyfile_patch_path).st_size | 274 gzipped_filebyfile_patch_size = os.stat(gzipped_filebyfile_patch_path).st_size |
272 # Clean temp files | 275 # Clean temp files |
273 if os.path.exists(temp_path): os.remove(temp_path) | 276 if os.path.exists(temp_path): os.remove(temp_path) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 344 |
342 print '\nEstimated download size for updates from the old APK,' | 345 print '\nEstimated download size for updates from the old APK,' |
343 print ' using File-by-File:' | 346 print ' using File-by-File:' |
344 print (' File-by-File patch (gzipped) size: %s bytes [%s]\n' | 347 print (' File-by-File patch (gzipped) size: %s bytes [%s]\n' |
345 % (locale.format('%d', gzipped_filebyfile_patch_size, grouping=True), | 348 % (locale.format('%d', gzipped_filebyfile_patch_size, grouping=True), |
346 human_file_size(gzipped_filebyfile_patch_size))) | 349 human_file_size(gzipped_filebyfile_patch_size))) |
347 | 350 |
348 | 351 |
349 if __name__ == '__main__': | 352 if __name__ == '__main__': |
350 main() | 353 main() |
OLD | NEW |