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