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 IOError('File not built: %s' % md5sum_bin_host_path) |
36 out = cmd_helper.GetCmdOutput( | 40 out = cmd_helper.GetCmdOutput( |
37 [os.path.join(constants.GetOutDirectory(), 'md5sum_bin_host')] + | 41 [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()] | 42 return [HashAndPath(*l.split(None, 1)) for l in out.splitlines()] |
40 | 43 |
41 | 44 |
42 def CalculateDeviceMd5Sums(paths, device): | 45 def CalculateDeviceMd5Sums(paths, device): |
43 """Calculates the MD5 sum value for all items in |paths|. | 46 """Calculates the MD5 sum value for all items in |paths|. |
44 | 47 |
45 Args: | 48 Args: |
46 paths: A list of device paths to md5sum. | 49 paths: A list of device paths to md5sum. |
47 Returns: | 50 Returns: |
48 A list of named tuples with 'hash' and 'path' attributes. | 51 A list of named tuples with 'hash' and 'path' attributes. |
49 """ | 52 """ |
50 if isinstance(paths, basestring): | 53 if isinstance(paths, basestring): |
51 paths = [paths] | 54 paths = [paths] |
52 | 55 |
53 if not device.FileExists(MD5SUM_DEVICE_BIN_PATH): | 56 if not device.FileExists(MD5SUM_DEVICE_BIN_PATH): |
54 device.adb.Push( | 57 md5sum_dist_path = os.path.join(constants.GetOutDirectory(), 'md5sum_dist') |
55 os.path.join(constants.GetOutDirectory(), 'md5sum_dist'), | 58 if not os.path.exists(md5sum_dist_path): |
56 MD5SUM_DEVICE_LIB_PATH) | 59 raise IOError('File not built: %s' % md5sum_dist_path) |
| 60 device.adb.Push(md5sum_dist_path, MD5SUM_DEVICE_LIB_PATH) |
57 | 61 |
58 out = [] | 62 out = [] |
59 | 63 |
60 with tempfile.NamedTemporaryFile() as md5sum_script_file: | 64 with tempfile.NamedTemporaryFile() as md5sum_script_file: |
61 with device_temp_file.DeviceTempFile( | 65 with device_temp_file.DeviceTempFile( |
62 device.adb) as md5sum_device_script_file: | 66 device.adb) as md5sum_device_script_file: |
63 device_pie_wrapper = device.GetDevicePieWrapper() | 67 device_pie_wrapper = device.GetDevicePieWrapper() |
64 md5sum_script = ( | 68 md5sum_script = ( |
65 MD5SUM_DEVICE_SCRIPT_FORMAT.format( | 69 MD5SUM_DEVICE_SCRIPT_FORMAT.format( |
66 path=p, md5sum_lib=MD5SUM_DEVICE_LIB_PATH, | 70 path=p, md5sum_lib=MD5SUM_DEVICE_LIB_PATH, |
67 device_pie_wrapper=device_pie_wrapper, | 71 device_pie_wrapper=device_pie_wrapper, |
68 md5sum_bin=MD5SUM_DEVICE_BIN_PATH) | 72 md5sum_bin=MD5SUM_DEVICE_BIN_PATH) |
69 for p in paths) | 73 for p in paths) |
70 md5sum_script_file.write('; '.join(md5sum_script)) | 74 md5sum_script_file.write('; '.join(md5sum_script)) |
71 md5sum_script_file.flush() | 75 md5sum_script_file.flush() |
72 device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name) | 76 device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name) |
73 out = device.RunShellCommand(['sh', md5sum_device_script_file.name]) | 77 out = device.RunShellCommand(['sh', md5sum_device_script_file.name]) |
74 | 78 |
75 return [HashAndPath(*l.split(None, 1)) for l in out if l] | 79 return [HashAndPath(*l.split(None, 1)) for l in out if l] |
76 | 80 |
OLD | NEW |