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

Side by Side Diff: build/android/gyp/apk_install.py

Issue 132463007: Enable presubmit pylint in build/android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address frankf review comments. Created 6 years, 10 months 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Installs an APK. 7 """Installs an APK.
8 8
9 """ 9 """
10 10
11 import optparse 11 import optparse
12 import os 12 import os
13 import re 13 import re
14 import subprocess
15 import sys 14 import sys
16 15
17 from util import build_device 16 from util import build_device
18 from util import build_utils 17 from util import build_utils
19 from util import md5_check 18 from util import md5_check
20 19
21 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') 20 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..')
22 sys.path.append(BUILD_ANDROID_DIR) 21 sys.path.append(BUILD_ANDROID_DIR)
23 22
24 from pylib import constants 23 from pylib import constants
25 from pylib.utils import apk_helper 24 from pylib.utils import apk_helper
26 25
27 def GetNewMetadata(device, apk_package): 26 def GetNewMetadata(device, apk_package):
28 """Gets the metadata on the device for the apk_package apk.""" 27 """Gets the metadata on the device for the apk_package apk."""
29 output = device.RunShellCommand('ls -l /data/app/') 28 output = device.RunShellCommand('ls -l /data/app/')
29 # pylint: disable=C0301
30 # Matches lines like: 30 # Matches lines like:
31 # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome.t estshell.apk 31 # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome.t estshell.apk
32 # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome.t estshell-1.apk 32 # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome.t estshell-1.apk
33 # pylint: enable=C0301
33 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s) 34 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s)
34 matches = filter(apk_matcher, output) 35 matches = filter(apk_matcher, output)
35 return matches[0] if matches else None 36 return matches[0] if matches else None
36 37
37 def HasInstallMetadataChanged(device, apk_package, metadata_path): 38 def HasInstallMetadataChanged(device, apk_package, metadata_path):
38 """Checks if the metadata on the device for apk_package has changed.""" 39 """Checks if the metadata on the device for apk_package has changed."""
39 if not os.path.exists(metadata_path): 40 if not os.path.exists(metadata_path):
40 return True 41 return True
41 42
42 with open(metadata_path, 'r') as expected_file: 43 with open(metadata_path, 'r') as expected_file:
43 return expected_file.read() != device.GetInstallMetadata(apk_package) 44 return expected_file.read() != device.GetInstallMetadata(apk_package)
44 45
45 46
46 def RecordInstallMetadata(device, apk_package, metadata_path): 47 def RecordInstallMetadata(device, apk_package, metadata_path):
47 """Records the metadata from the device for apk_package.""" 48 """Records the metadata from the device for apk_package."""
48 metadata = GetNewMetadata(device, apk_package) 49 metadata = GetNewMetadata(device, apk_package)
49 if not metadata: 50 if not metadata:
50 raise Exception('APK install failed unexpectedly.') 51 raise Exception('APK install failed unexpectedly.')
51 52
52 with open(metadata_path, 'w') as outfile: 53 with open(metadata_path, 'w') as outfile:
53 outfile.write(metadata) 54 outfile.write(metadata)
54 55
55 56
56 def main(argv): 57 def main():
57 parser = optparse.OptionParser() 58 parser = optparse.OptionParser()
58 parser.add_option('--apk-path', 59 parser.add_option('--apk-path',
59 help='Path to .apk to install.') 60 help='Path to .apk to install.')
60 parser.add_option('--install-record', 61 parser.add_option('--install-record',
61 help='Path to install record (touched only when APK is installed).') 62 help='Path to install record (touched only when APK is installed).')
62 parser.add_option('--build-device-configuration', 63 parser.add_option('--build-device-configuration',
63 help='Path to build device configuration.') 64 help='Path to build device configuration.')
64 parser.add_option('--stamp', 65 parser.add_option('--stamp',
65 help='Path to touch on success.') 66 help='Path to touch on success.')
66 parser.add_option('--configuration-name', 67 parser.add_option('--configuration-name',
(...skipping 27 matching lines...) Expand all
94 Install, 95 Install,
95 record_path=record_path, 96 record_path=record_path,
96 input_paths=[options.apk_path], 97 input_paths=[options.apk_path],
97 force=force_install) 98 force=force_install)
98 99
99 if options.stamp: 100 if options.stamp:
100 build_utils.Touch(options.stamp) 101 build_utils.Touch(options.stamp)
101 102
102 103
103 if __name__ == '__main__': 104 if __name__ == '__main__':
104 sys.exit(main(sys.argv)) 105 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698