Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 ''' | 5 ''' |
| 6 Utility functions for all things related to manipulating google play services | 6 Utility functions for all things related to manipulating google play services |
| 7 related files. | 7 related files. |
| 8 ''' | 8 ''' |
| 9 | 9 |
| 10 import argparse | 10 import argparse |
| 11 import filecmp | 11 import filecmp |
| 12 import logging | 12 import logging |
| 13 import os | 13 import os |
| 14 import re | 14 import re |
| 15 import sys | 15 import sys |
| 16 import yaml | 16 import yaml |
| 17 import zipfile | 17 import zipfile |
| 18 | 18 |
| 19 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) | 19 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) |
| 20 from devil.utils import cmd_helper | 20 from devil.utils import cmd_helper |
| 21 from pylib import constants | |
| 22 | |
| 23 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, | |
| 24 'third_party', 'colorama', 'src')) | |
| 25 import colorama | |
| 21 | 26 |
| 22 | 27 |
| 23 _CONFIG_VERSION_NUMBER_KEY = 'version_number' | 28 _CONFIG_VERSION_NUMBER_KEY = 'version_number' |
| 24 _YAML_VERSION_NUMBER_PATTERN = re.compile( | 29 _YAML_VERSION_NUMBER_PATTERN = re.compile( |
| 25 r'(^\s*%s\s*:\s*)(\d+)(.*$)' % _CONFIG_VERSION_NUMBER_KEY, re.MULTILINE) | 30 r'(^\s*%s\s*:\s*)(\d+)(.*$)' % _CONFIG_VERSION_NUMBER_KEY, re.MULTILINE) |
| 26 _XML_VERSION_NUMBER_PATTERN = re.compile( | 31 _XML_VERSION_NUMBER_PATTERN = re.compile( |
| 27 r'<integer name="google_play_services_version">(\d+)<\/integer>') | 32 r'<integer name="google_play_services_version">(\d+)<\/integer>') |
| 28 | 33 |
| 29 | 34 |
| 30 class DefaultsRawHelpFormatter(argparse.ArgumentDefaultsHelpFormatter, | 35 class DefaultsRawHelpFormatter(argparse.ArgumentDefaultsHelpFormatter, |
| 31 argparse.RawDescriptionHelpFormatter): | 36 argparse.RawDescriptionHelpFormatter): |
| 32 ''' | 37 ''' |
| 33 Combines the features of RawDescriptionHelpFormatter and | 38 Combines the features of RawDescriptionHelpFormatter and |
| 34 ArgumentDefaultsHelpFormatter, providing defaults for the arguments and raw | 39 ArgumentDefaultsHelpFormatter, providing defaults for the arguments and raw |
| 35 text for the description. | 40 text for the description. |
| 36 ''' | 41 ''' |
| 37 pass | 42 pass |
| 38 | 43 |
| 39 | 44 |
| 45 def EmphasizeMessage(message): | |
|
dgn
2015/10/28 13:54:33
Should I make a proper stream handler for the logg
jbudorick
2015/10/28 14:08:25
Have warnings print yellow and errors print red? I
dgn
2015/10/28 14:27:13
Should I put that in pylib?
jbudorick
2015/10/28 14:28:53
Yeah, that'd be great.
You may see it in the test
jbudorick
2015/10/28 14:29:31
(specifically, pylib/utils/)
dgn
2015/10/28 16:32:58
Addressed in https://codereview.chromium.org/14185
| |
| 46 # pylint warning: does not see members added dynamically in the constructor. | |
| 47 # pylint: disable=no-member | |
| 48 return (colorama.Fore.YELLOW + colorama.Style.DIM + message + | |
| 49 colorama.Style.RESET_ALL) | |
| 50 | |
| 51 | |
| 40 def FileEquals(expected_file, actual_file): | 52 def FileEquals(expected_file, actual_file): |
| 41 ''' | 53 ''' |
| 42 Returns whether the two files are equal. Returns False if any of the files | 54 Returns whether the two files are equal. Returns False if any of the files |
| 43 doesn't exist. | 55 doesn't exist. |
| 44 ''' | 56 ''' |
| 45 | 57 |
| 46 if not os.path.isfile(actual_file) or not os.path.isfile(expected_file): | 58 if not os.path.isfile(actual_file) or not os.path.isfile(expected_file): |
| 47 return False | 59 return False |
| 48 return filecmp.cmp(expected_file, actual_file) | 60 return filecmp.cmp(expected_file, actual_file) |
| 49 | 61 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 | 129 |
| 118 | 130 |
| 119 def ZipDir(output, base_dir): | 131 def ZipDir(output, base_dir): |
| 120 '''Creates a zip file from a directory.''' | 132 '''Creates a zip file from a directory.''' |
| 121 | 133 |
| 122 base = os.path.join(base_dir, os.pardir) | 134 base = os.path.join(base_dir, os.pardir) |
| 123 with zipfile.ZipFile(output, 'w') as out_file: | 135 with zipfile.ZipFile(output, 'w') as out_file: |
| 124 for root, _, files in os.walk(base_dir): | 136 for root, _, files in os.walk(base_dir): |
| 125 for in_file in files: | 137 for in_file in files: |
| 126 out_file.write(os.path.join(root, in_file), base) | 138 out_file.write(os.path.join(root, in_file), base) |
| OLD | NEW |