OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import collections | 5 import collections |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import tempfile | 8 import tempfile |
9 import types | 9 import types |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 """Calculates the MD5 sum value for all items in |paths|. | 26 """Calculates the MD5 sum value for all items in |paths|. |
27 | 27 |
28 Args: | 28 Args: |
29 paths: A list of host paths to md5sum. | 29 paths: A list of host paths to md5sum. |
30 Returns: | 30 Returns: |
31 A list of named tuples with 'hash' and 'path' attributes. | 31 A list of named tuples with 'hash' and 'path' attributes. |
32 """ | 32 """ |
33 if isinstance(paths, basestring): | 33 if isinstance(paths, basestring): |
34 paths = [paths] | 34 paths = [paths] |
35 | 35 |
| 36 md5sum_bin_host_path = os.path.join( |
| 37 constants.GetOutDirectory(), 'md5sum_bin_host') |
| 38 if not os.path.exists(md5sum_bin_host_path): |
| 39 raise OSError('File not built: %s' % md5sum_bin_host_path) |
| 40 |
36 out = cmd_helper.GetCmdOutput( | 41 out = cmd_helper.GetCmdOutput( |
37 [os.path.join(constants.GetOutDirectory(), 'md5sum_bin_host')] + | 42 [md5sum_bin_host_path] + [p for p in paths]) |
38 [p for p in paths]) | |
39 return [HashAndPath(*l.split(None, 1)) for l in out.splitlines()] | 43 return [HashAndPath(*l.split(None, 1)) for l in out.splitlines()] |
40 | 44 |
41 | 45 |
42 def CalculateDeviceMd5Sums(paths, device): | 46 def CalculateDeviceMd5Sums(paths, device): |
43 """Calculates the MD5 sum value for all items in |paths|. | 47 """Calculates the MD5 sum value for all items in |paths|. |
44 | 48 |
45 Args: | 49 Args: |
46 paths: A list of device paths to md5sum. | 50 paths: A list of device paths to md5sum. |
47 Returns: | 51 Returns: |
48 A list of named tuples with 'hash' and 'path' attributes. | 52 A list of named tuples with 'hash' and 'path' attributes. |
49 """ | 53 """ |
50 if isinstance(paths, basestring): | 54 if isinstance(paths, basestring): |
51 paths = [paths] | 55 paths = [paths] |
52 | 56 |
| 57 md5sum_dist_path = os.path.join(constants.GetOutDirectory(), 'md5sum_dist') |
| 58 if not os.path.exists(md5sum_dist_path): |
| 59 raise OSError('File not built: %s' % md5sum_dist_path) |
| 60 |
53 if not device.FileExists(MD5SUM_DEVICE_BIN_PATH): | 61 if not device.FileExists(MD5SUM_DEVICE_BIN_PATH): |
54 device.adb.Push( | 62 device.adb.Push(md5sum_dist_path, MD5SUM_DEVICE_LIB_PATH) |
55 os.path.join(constants.GetOutDirectory(), 'md5sum_dist'), | |
56 MD5SUM_DEVICE_LIB_PATH) | |
57 | 63 |
58 out = [] | 64 out = [] |
59 | 65 |
60 with tempfile.NamedTemporaryFile() as md5sum_script_file: | 66 with tempfile.NamedTemporaryFile() as md5sum_script_file: |
61 with device_temp_file.DeviceTempFile( | 67 with device_temp_file.DeviceTempFile( |
62 device.adb) as md5sum_device_script_file: | 68 device.adb) as md5sum_device_script_file: |
63 device_pie_wrapper = device.GetDevicePieWrapper() | 69 device_pie_wrapper = device.GetDevicePieWrapper() |
64 md5sum_script = ( | 70 md5sum_script = ( |
65 MD5SUM_DEVICE_SCRIPT_FORMAT.format( | 71 MD5SUM_DEVICE_SCRIPT_FORMAT.format( |
66 path=p, md5sum_lib=MD5SUM_DEVICE_LIB_PATH, | 72 path=p, md5sum_lib=MD5SUM_DEVICE_LIB_PATH, |
67 device_pie_wrapper=device_pie_wrapper, | 73 device_pie_wrapper=device_pie_wrapper, |
68 md5sum_bin=MD5SUM_DEVICE_BIN_PATH) | 74 md5sum_bin=MD5SUM_DEVICE_BIN_PATH) |
69 for p in paths) | 75 for p in paths) |
70 md5sum_script_file.write('; '.join(md5sum_script)) | 76 md5sum_script_file.write('; '.join(md5sum_script)) |
71 md5sum_script_file.flush() | 77 md5sum_script_file.flush() |
72 device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name) | 78 device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name) |
73 out = device.RunShellCommand(['sh', md5sum_device_script_file.name]) | 79 out = device.RunShellCommand(['sh', md5sum_device_script_file.name]) |
74 | 80 |
75 return [HashAndPath(*l.split(None, 1)) for l in out if l] | 81 return [HashAndPath(*l.split(None, 1)) for l in out if l] |
76 | 82 |
OLD | NEW |