Chromium Code Reviews| Index: build/android/pylib/utils/md5sum.py |
| diff --git a/build/android/pylib/utils/md5sum.py b/build/android/pylib/utils/md5sum.py |
| index da3cd15c785b0da5a2382816078d6817f63fc7aa..9bbd8bc8d5e568eb620be4951e326acb3cab9c8d 100644 |
| --- a/build/android/pylib/utils/md5sum.py |
| +++ b/build/android/pylib/utils/md5sum.py |
| @@ -5,6 +5,7 @@ |
| import collections |
| import logging |
| import os |
| +import re |
| import tempfile |
| import types |
| @@ -21,6 +22,8 @@ MD5SUM_DEVICE_SCRIPT_FORMAT = ( |
| 'test -f {path} -o -d {path} ' |
| '&& LD_LIBRARY_PATH={md5sum_lib} {device_pie_wrapper} {md5sum_bin} {path}') |
| +_STARTS_WITH_CHECKSUM_RE = re.compile(r'^\s*[0-9a-fA-f]{32}\s+') |
| + |
| def CalculateHostMd5Sums(paths): |
| """Calculates the MD5 sum value for all items in |paths|. |
| @@ -28,7 +31,7 @@ def CalculateHostMd5Sums(paths): |
| Args: |
| paths: A list of host paths to md5sum. |
| Returns: |
| - A list of named tuples with 'hash' and 'path' attributes. |
| + A dict mapping paths to their respective md5sum checksums. |
| """ |
| if isinstance(paths, basestring): |
| paths = [paths] |
| @@ -36,7 +39,8 @@ def CalculateHostMd5Sums(paths): |
| out = cmd_helper.GetCmdOutput( |
| [os.path.join(constants.GetOutDirectory(), 'md5sum_bin_host')] + |
| [p for p in paths]) |
| - return [HashAndPath(*l.split(None, 1)) for l in out.splitlines()] |
| + |
| + return _ParseMd5SumOutput(out.splitlines()) |
| def CalculateDeviceMd5Sums(paths, device): |
| @@ -45,7 +49,7 @@ def CalculateDeviceMd5Sums(paths, device): |
| Args: |
| paths: A list of device paths to md5sum. |
| Returns: |
| - A list of named tuples with 'hash' and 'path' attributes. |
| + A dict mapping paths to their respective md5sum checksums. |
| """ |
| if isinstance(paths, basestring): |
| paths = [paths] |
| @@ -72,5 +76,11 @@ def CalculateDeviceMd5Sums(paths, device): |
| device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name) |
| out = device.RunShellCommand(['sh', md5sum_device_script_file.name]) |
| - return [HashAndPath(*l.split(None, 1)) for l in out if l] |
| + return _ParseMd5SumOutput(out) |
| + |
| + |
| +def _ParseMd5SumOutput(out): |
| + hash_and_path = (l.split(None, 1) for l in out |
| + if l and _STARTS_WITH_CHECKSUM_RE.match(l)) |
| + return dict((p, h) for h, p in hash_and_path) |
|
perezju
2015/04/24 08:06:32
nit: can be written as:
return {p: h for h, p i
jbudorick
2015/04/24 13:56:36
We have generally avoided dictionary comprehension
perezju
2015/04/24 14:13:25
hmmm, strange, but ok.
|