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 | |
42 bsdiff_path = None | 39 bsdiff_path = None |
43 gzip_path = None | 40 gzip_path = None |
44 head_path = None | 41 head_path = None |
45 tail_path = None | 42 tail_path = None |
46 bunzip2_path = None | 43 bunzip2_path = None |
47 java_path = None | 44 java_path = None |
48 | 45 |
49 | 46 |
50 def find_bins_or_die(): | 47 def find_bins_or_die(): |
51 """Checks that all the binaries needed are available. | 48 """Checks that all the binaries needed are available. |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 else: | 252 else: |
256 filebyfile_patch_path = temp_path + '.filebyfile' | 253 filebyfile_patch_path = temp_path + '.filebyfile' |
257 gzipped_filebyfile_patch_path = filebyfile_patch_path + '.gz' | 254 gzipped_filebyfile_patch_path = filebyfile_patch_path + '.gz' |
258 if os.path.exists(gzipped_filebyfile_patch_path): | 255 if os.path.exists(gzipped_filebyfile_patch_path): |
259 os.remove(gzipped_filebyfile_patch_path) | 256 os.remove(gzipped_filebyfile_patch_path) |
260 | 257 |
261 # file by file patch | 258 # file by file patch |
262 # We use a jar from https://github.com/andrewhayden/archive-patcher | 259 # We use a jar from https://github.com/andrewhayden/archive-patcher |
263 if os.path.exists(filebyfile_patch_path): os.remove(filebyfile_patch_path) | 260 if os.path.exists(filebyfile_patch_path): os.remove(filebyfile_patch_path) |
264 p = subprocess.Popen( | 261 p = subprocess.Popen( |
265 [java_path, '-jar', _FILEBYFILE_JAR_PATH, '--generate', '--old', old_file, | 262 [java_path, '-jar', 'lib/file-by-file-tools.jar', '--generate', |
266 '--new', new_file, '--patch', filebyfile_patch_path], | 263 '--old', old_file, '--new', new_file, '--patch', filebyfile_patch_path], |
267 shell=False) | 264 shell=False) |
268 ret_code = p.wait() | 265 ret_code = p.wait() |
269 if ret_code != 0: raise Exception( | 266 if ret_code != 0: raise Exception( |
270 'Problem creating file by file patch, returned code: %s' % ret_code) | 267 'Problem creating file by file patch, returned code: %s' % ret_code) |
271 | 268 |
272 # gzip file by file patch and get its size | 269 # gzip file by file patch and get its size |
273 subprocess.check_output([gzip_path, '-9', filebyfile_patch_path]) | 270 subprocess.check_output([gzip_path, '-9', filebyfile_patch_path]) |
274 gzipped_filebyfile_patch_size = os.stat(gzipped_filebyfile_patch_path).st_size | 271 gzipped_filebyfile_patch_size = os.stat(gzipped_filebyfile_patch_path).st_size |
275 # Clean temp files | 272 # Clean temp files |
276 if os.path.exists(temp_path): os.remove(temp_path) | 273 if os.path.exists(temp_path): os.remove(temp_path) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 341 |
345 print '\nEstimated download size for updates from the old APK,' | 342 print '\nEstimated download size for updates from the old APK,' |
346 print ' using File-by-File:' | 343 print ' using File-by-File:' |
347 print (' File-by-File patch (gzipped) size: %s bytes [%s]\n' | 344 print (' File-by-File patch (gzipped) size: %s bytes [%s]\n' |
348 % (locale.format('%d', gzipped_filebyfile_patch_size, grouping=True), | 345 % (locale.format('%d', gzipped_filebyfile_patch_size, grouping=True), |
349 human_file_size(gzipped_filebyfile_patch_size))) | 346 human_file_size(gzipped_filebyfile_patch_size))) |
350 | 347 |
351 | 348 |
352 if __name__ == '__main__': | 349 if __name__ == '__main__': |
353 main() | 350 main() |
OLD | NEW |