Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import collections | |
| 6 import logging | |
| 7 import os | |
| 8 import tempfile | |
| 9 import types | |
| 10 | |
| 11 from pylib import cmd_helper | |
| 12 from pylib import constants | |
| 13 from pylib.utils import device_temp_file | |
| 14 | |
| 15 HashAndPath = collections.namedtuple('HashAndPath', ['hash', 'path']) | |
| 16 | |
| 17 MD5SUM_DEVICE_LIB_PATH = '/data/local/tmp/md5sum/' | |
| 18 MD5SUM_DEVICE_BIN_PATH = MD5SUM_DEVICE_LIB_PATH + 'md5sum_bin' | |
| 19 | |
| 20 MD5SUM_DEVICE_SCRIPT_FORMAT = ( | |
| 21 'test -f {path} -o -d {path} ' | |
|
perezju
2014/11/20 17:04:53
why not just 'test -e {path}' ?
jbudorick
2014/11/20 19:38:07
This avoids file types we don't want to md5sum, e.
perezju
2014/11/20 20:38:41
Ok!
| |
| 22 '&& LD_LIBRARY_PATH={md5sum_lib} {md5sum_bin} {path}') | |
|
perezju
2014/11/20 17:04:53
could we send the LD_LIBRARY_PATH using the RunShe
jbudorick
2014/11/20 19:38:08
No, not with the way this script is rolled.
| |
| 23 | |
| 24 | |
| 25 def CalculateHostMd5Sums(paths): | |
| 26 """Calculates the MD5 sum value for all items in |paths|. | |
| 27 | |
| 28 Args: | |
| 29 paths: A list of host paths to md5sum. | |
| 30 Returns: | |
| 31 A list of named tuples with 'hash' and 'path' attributes. | |
| 32 """ | |
| 33 if not isinstance(paths, list): | |
| 34 paths = [paths] | |
|
perezju
2014/11/20 17:04:53
I would check 'if isinstance(paths, basestr)' so t
jbudorick
2014/11/20 19:38:07
With the list addition below, we actually do want
perezju
2014/11/20 20:38:42
But what if I want to pass a tuple? or some other
jbudorick
2014/11/20 20:58:13
Good point.
| |
| 35 out = cmd_helper.GetCmdOutput( | |
| 36 [os.path.join(constants.GetOutDirectory(), 'md5sum_bin_host')] + paths) | |
|
perezju
2014/11/20 17:04:53
if GetOutDirectory() is a constant, can we move th
jbudorick
2014/11/20 19:38:07
It's one of the not-quite-constant constants. I wa
perezju
2014/11/20 20:38:42
Ok!
| |
| 37 return [HashAndPath(*l.split(None, 1)) for l in out.splitlines()] | |
| 38 | |
| 39 | |
| 40 def CalculateDeviceMd5Sums(paths, device): | |
| 41 """Calculates the MD5 sum value for all items in |paths|. | |
| 42 | |
| 43 Args: | |
| 44 paths: A list of device paths to md5sum. | |
| 45 Returns: | |
| 46 A list of named tuples with 'hash' and 'path' attributes. | |
| 47 """ | |
| 48 if isinstance(paths, types.GeneratorType): | |
| 49 paths = list(paths) | |
| 50 elif not isinstance(paths, list): | |
| 51 paths = [paths] | |
|
perezju
2014/11/20 17:04:53
Same here, we could just write:
if isinstance(pat
jbudorick
2014/11/20 19:38:07
Sticking with this for consistency with the above,
jbudorick
2014/11/20 20:58:13
(also switched)
| |
| 52 | |
| 53 if not device.FileExists(MD5SUM_DEVICE_BIN_PATH): | |
|
perezju
2014/11/20 17:04:53
Probably not something to do now, but maybe Device
jbudorick
2014/11/20 19:38:07
Definitely not something to do now, but not a bad
| |
| 54 device.adb.Push( | |
| 55 os.path.join(constants.GetOutDirectory(), 'md5sum_dist'), | |
|
perezju
2014/11/20 17:04:53
Same thing about the constant, though.
jbudorick
2014/11/20 19:38:07
same response.
| |
| 56 MD5SUM_DEVICE_LIB_PATH) | |
| 57 | |
| 58 out = [] | |
| 59 with tempfile.NamedTemporaryFile() as md5sum_script_file: | |
| 60 with device_temp_file.DeviceTempFile(device) as md5sum_device_script_file: | |
| 61 md5sum_script = ( | |
| 62 MD5SUM_DEVICE_SCRIPT_FORMAT.format( | |
| 63 path=p, md5sum_lib=MD5SUM_DEVICE_LIB_PATH, | |
| 64 md5sum_bin=MD5SUM_DEVICE_BIN_PATH) | |
| 65 for p in paths) | |
| 66 md5sum_script_file.write('; '.join(md5sum_script)) | |
| 67 md5sum_script_file.flush() | |
| 68 device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name) | |
| 69 out = device.RunShellCommand(['sh', md5sum_device_script_file.name]) | |
|
perezju
2014/11/20 17:04:53
Why don't we just run the script on the device rat
perezju
2014/11/20 17:16:13
Another btw: looking at md5sum.cc, it also seems t
jbudorick
2014/11/20 19:38:07
Because the script is pretty likely to be longer t
jbudorick
2014/11/20 19:38:08
We can. I tried doing so (https://codereview.chrom
perezju
2014/11/20 20:38:42
Yeah, I thought about all those problems just afte
| |
| 70 | |
| 71 return [HashAndPath(*l.split(None, 1)) for l in out] | |
| 72 | |
| OLD | NEW |