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 tempfile | 9 import tempfile |
9 import types | 10 import types |
10 | 11 |
11 from pylib import cmd_helper | 12 from pylib import cmd_helper |
12 from pylib import constants | 13 from pylib import constants |
13 from pylib.utils import device_temp_file | 14 from pylib.utils import device_temp_file |
14 | 15 |
15 HashAndPath = collections.namedtuple('HashAndPath', ['hash', 'path']) | 16 HashAndPath = collections.namedtuple('HashAndPath', ['hash', 'path']) |
16 | 17 |
17 MD5SUM_DEVICE_LIB_PATH = '/data/local/tmp/md5sum/' | 18 MD5SUM_DEVICE_LIB_PATH = '/data/local/tmp/md5sum/' |
18 MD5SUM_DEVICE_BIN_PATH = MD5SUM_DEVICE_LIB_PATH + 'md5sum_bin' | 19 MD5SUM_DEVICE_BIN_PATH = MD5SUM_DEVICE_LIB_PATH + 'md5sum_bin' |
19 | 20 |
20 MD5SUM_DEVICE_SCRIPT_FORMAT = ( | 21 MD5SUM_DEVICE_SCRIPT_FORMAT = ( |
21 'test -f {path} -o -d {path} ' | 22 'test -f {path} -o -d {path} ' |
22 '&& LD_LIBRARY_PATH={md5sum_lib} {device_pie_wrapper} {md5sum_bin} {path}') | 23 '&& LD_LIBRARY_PATH={md5sum_lib} {device_pie_wrapper} {md5sum_bin} {path}') |
23 | 24 |
| 25 _STARTS_WITH_CHECKSUM_RE = re.compile(r'^\s*[0-9a-fA-f]{32}\s+') |
| 26 |
24 | 27 |
25 def CalculateHostMd5Sums(paths): | 28 def CalculateHostMd5Sums(paths): |
26 """Calculates the MD5 sum value for all items in |paths|. | 29 """Calculates the MD5 sum value for all items in |paths|. |
27 | 30 |
28 Args: | 31 Args: |
29 paths: A list of host paths to md5sum. | 32 paths: A list of host paths to md5sum. |
30 Returns: | 33 Returns: |
31 A list of named tuples with 'hash' and 'path' attributes. | 34 A list of named tuples with 'hash' and 'path' attributes. |
32 """ | 35 """ |
33 if isinstance(paths, basestring): | 36 if isinstance(paths, basestring): |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 MD5SUM_DEVICE_SCRIPT_FORMAT.format( | 68 MD5SUM_DEVICE_SCRIPT_FORMAT.format( |
66 path=p, md5sum_lib=MD5SUM_DEVICE_LIB_PATH, | 69 path=p, md5sum_lib=MD5SUM_DEVICE_LIB_PATH, |
67 device_pie_wrapper=device_pie_wrapper, | 70 device_pie_wrapper=device_pie_wrapper, |
68 md5sum_bin=MD5SUM_DEVICE_BIN_PATH) | 71 md5sum_bin=MD5SUM_DEVICE_BIN_PATH) |
69 for p in paths) | 72 for p in paths) |
70 md5sum_script_file.write('; '.join(md5sum_script)) | 73 md5sum_script_file.write('; '.join(md5sum_script)) |
71 md5sum_script_file.flush() | 74 md5sum_script_file.flush() |
72 device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name) | 75 device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name) |
73 out = device.RunShellCommand(['sh', md5sum_device_script_file.name]) | 76 out = device.RunShellCommand(['sh', md5sum_device_script_file.name]) |
74 | 77 |
75 return [HashAndPath(*l.split(None, 1)) for l in out if l] | 78 return [HashAndPath(*l.split(None, 1)) |
| 79 for l in out |
| 80 if l and _STARTS_WITH_CHECKSUM_RE.match(l)] |
76 | 81 |
OLD | NEW |