Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3178)

Unified Diff: build/android/pylib/utils/md5sum.py

Issue 738413002: [Android] Extract MD5sum logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/instrumentation/test_jar.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/utils/md5sum.py
diff --git a/build/android/pylib/utils/md5sum.py b/build/android/pylib/utils/md5sum.py
new file mode 100644
index 0000000000000000000000000000000000000000..9d073dc48cd9f9526b81cf941fa387cd4321e708
--- /dev/null
+++ b/build/android/pylib/utils/md5sum.py
@@ -0,0 +1,72 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import collections
+import logging
+import os
+import tempfile
+import types
+
+from pylib import cmd_helper
+from pylib import constants
+from pylib.utils import device_temp_file
+
+HashAndPath = collections.namedtuple('HashAndPath', ['hash', 'path'])
+
+MD5SUM_DEVICE_LIB_PATH = '/data/local/tmp/md5sum/'
+MD5SUM_DEVICE_BIN_PATH = MD5SUM_DEVICE_LIB_PATH + 'md5sum_bin'
+
+MD5SUM_DEVICE_SCRIPT_FORMAT = (
+ '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!
+ '&& 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.
+
+
+def CalculateHostMd5Sums(paths):
+ """Calculates the MD5 sum value for all items in |paths|.
+
+ Args:
+ paths: A list of host paths to md5sum.
+ Returns:
+ A list of named tuples with 'hash' and 'path' attributes.
+ """
+ if not isinstance(paths, list):
+ 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.
+ out = cmd_helper.GetCmdOutput(
+ [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!
+ return [HashAndPath(*l.split(None, 1)) for l in out.splitlines()]
+
+
+def CalculateDeviceMd5Sums(paths, device):
+ """Calculates the MD5 sum value for all items in |paths|.
+
+ Args:
+ paths: A list of device paths to md5sum.
+ Returns:
+ A list of named tuples with 'hash' and 'path' attributes.
+ """
+ if isinstance(paths, types.GeneratorType):
+ paths = list(paths)
+ elif not isinstance(paths, list):
+ 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)
+
+ 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
+ device.adb.Push(
+ 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.
+ MD5SUM_DEVICE_LIB_PATH)
+
+ out = []
+ with tempfile.NamedTemporaryFile() as md5sum_script_file:
+ with device_temp_file.DeviceTempFile(device) as md5sum_device_script_file:
+ md5sum_script = (
+ MD5SUM_DEVICE_SCRIPT_FORMAT.format(
+ path=p, md5sum_lib=MD5SUM_DEVICE_LIB_PATH,
+ md5sum_bin=MD5SUM_DEVICE_BIN_PATH)
+ for p in paths)
+ md5sum_script_file.write('; '.join(md5sum_script))
+ md5sum_script_file.flush()
+ device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name)
+ 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
+
+ return [HashAndPath(*l.split(None, 1)) for l in out]
+
« no previous file with comments | « build/android/pylib/instrumentation/test_jar.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698