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

Side by Side 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 unified diff | Download patch
OLDNEW
(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} '
22 '&& LD_LIBRARY_PATH={md5sum_lib} {md5sum_bin} {path}')
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 isinstance(paths, basestring):
34 paths = [paths]
35
36 out = cmd_helper.GetCmdOutput(
37 [os.path.join(constants.GetOutDirectory(), 'md5sum_bin_host')] +
38 [p for p in paths])
39 return [HashAndPath(*l.split(None, 1)) for l in out.splitlines()]
40
41
42 def CalculateDeviceMd5Sums(paths, device):
43 """Calculates the MD5 sum value for all items in |paths|.
44
45 Args:
46 paths: A list of device paths to md5sum.
47 Returns:
48 A list of named tuples with 'hash' and 'path' attributes.
49 """
50 if isinstance(paths, basestring):
51 paths = [paths]
52
53 if not device.FileExists(MD5SUM_DEVICE_BIN_PATH):
54 device.adb.Push(
55 os.path.join(constants.GetOutDirectory(), 'md5sum_dist'),
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])
70
71 return [HashAndPath(*l.split(None, 1)) for l in out]
72
OLDNEW
« 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