Chromium Code Reviews| 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 |
| 11 from pylib import cmd_helper | 11 from pylib import cmd_helper |
| 12 from pylib import constants | 12 from pylib import constants |
| 13 from pylib.utils import device_temp_file | 13 from pylib.utils import device_temp_file |
| 14 | 14 |
| 15 HashAndPath = collections.namedtuple('HashAndPath', ['hash', 'path']) | 15 HashAndPath = collections.namedtuple('HashAndPath', ['hash', 'path']) |
| 16 | 16 |
| 17 MD5SUM_DEVICE_LIB_PATH = '/data/local/tmp/md5sum/' | 17 MD5SUM_DEVICE_LIB_PATH = '/data/local/tmp/md5sum/' |
| 18 MD5SUM_DEVICE_BIN_PATH = MD5SUM_DEVICE_LIB_PATH + 'md5sum_bin' | 18 MD5SUM_DEVICE_BIN_PATH = MD5SUM_DEVICE_LIB_PATH + 'md5sum_bin' |
| 19 | 19 |
| 20 MD5SUM_DEVICE_SCRIPT_FORMAT = ( | 20 MD5SUM_DEVICE_SCRIPT_FORMAT = ( |
| 21 'test -f {path} -o -d {path} ' | 21 'test -f {path} -o -d {path} ' |
| 22 '&& LD_LIBRARY_PATH={md5sum_lib} {md5sum_bin} {path}') | 22 '&& LD_LIBRARY_PATH={md5sum_lib} {device_pie_wrapper} {md5sum_bin} {path}') |
| 23 | 23 |
| 24 | 24 |
| 25 def CalculateHostMd5Sums(paths): | 25 def CalculateHostMd5Sums(paths): |
| 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 """ |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 49 """ | 49 """ |
| 50 if isinstance(paths, basestring): | 50 if isinstance(paths, basestring): |
| 51 paths = [paths] | 51 paths = [paths] |
| 52 | 52 |
| 53 if not device.FileExists(MD5SUM_DEVICE_BIN_PATH): | 53 if not device.FileExists(MD5SUM_DEVICE_BIN_PATH): |
| 54 device.adb.Push( | 54 device.adb.Push( |
| 55 os.path.join(constants.GetOutDirectory(), 'md5sum_dist'), | 55 os.path.join(constants.GetOutDirectory(), 'md5sum_dist'), |
| 56 MD5SUM_DEVICE_LIB_PATH) | 56 MD5SUM_DEVICE_LIB_PATH) |
| 57 | 57 |
| 58 out = [] | 58 out = [] |
| 59 | |
| 59 with tempfile.NamedTemporaryFile() as md5sum_script_file: | 60 with tempfile.NamedTemporaryFile() as md5sum_script_file: |
| 60 with device_temp_file.DeviceTempFile( | 61 with device_temp_file.DeviceTempFile( |
| 61 device.adb) as md5sum_device_script_file: | 62 device.adb) as md5sum_device_script_file: |
| 63 device_pie_wrapper = device.GetDevicePieWrapper() | |
| 62 md5sum_script = ( | 64 md5sum_script = ( |
| 63 MD5SUM_DEVICE_SCRIPT_FORMAT.format( | 65 MD5SUM_DEVICE_SCRIPT_FORMAT.format( |
| 64 path=p, md5sum_lib=MD5SUM_DEVICE_LIB_PATH, | 66 path=p, md5sum_lib=MD5SUM_DEVICE_LIB_PATH, |
| 67 device_pie_wrapper=device_pie_wrapper, | |
| 65 md5sum_bin=MD5SUM_DEVICE_BIN_PATH) | 68 md5sum_bin=MD5SUM_DEVICE_BIN_PATH) |
| 66 for p in paths) | 69 for p in paths) |
| 67 md5sum_script_file.write('; '.join(md5sum_script)) | 70 md5sum_script_file.write('; '.join(md5sum_script)) |
| 68 md5sum_script_file.flush() | 71 md5sum_script_file.flush() |
| 69 device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name) | 72 device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name) |
| 70 out = device.RunShellCommand(['sh', md5sum_device_script_file.name]) | 73 out = device.RunShellCommand(['sh', md5sum_device_script_file.name]) |
|
perezju
2015/02/16 10:25:23
while we are at it, could we remove the hand-rolle
jbudorick
2015/02/17 15:15:10
I'd like to do that, but I don't want to do so in
perezju
2015/02/17 16:04:26
Acknowledged. Maybe start a bug so that we don't f
| |
| 71 | 74 |
| 72 return [HashAndPath(*l.split(None, 1)) for l in out] | 75 return [HashAndPath(*l.split(None, 1)) for l in out if l] |
| 73 | 76 |
| OLD | NEW |