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

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') | build/android/pylib/utils/md5sum_test.py » ('j') | 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..8c10bb0b88eb85d4e59a8832c5a22270b605b1b8
--- /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} '
+ '&& LD_LIBRARY_PATH={md5sum_lib} {md5sum_bin} {path}')
+
+
+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 isinstance(paths, basestring):
+ paths = [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()]
+
+
+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, basestring):
+ paths = [paths]
+
+ if not device.FileExists(MD5SUM_DEVICE_BIN_PATH):
+ device.adb.Push(
+ os.path.join(constants.GetOutDirectory(), 'md5sum_dist'),
+ 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])
+
+ return [HashAndPath(*l.split(None, 1)) for l in out]
+
« no previous file with comments | « build/android/pylib/instrumentation/test_jar.py ('k') | build/android/pylib/utils/md5sum_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698