diff options
author | Steve Fung <stevefung@google.com> | 2016-04-19 17:35:01 -0700 |
---|---|---|
committer | Treehugger Robot <treehugger-gerrit@google.com> | 2016-04-20 21:35:46 +0000 |
commit | 53928b12e7f0daa07cabe0274096f252af8a8589 (patch) | |
tree | 31a9d6962a5500aefb9274e73e06cf97693d8958 | |
parent | bb621f2078fb37008f80c61c460daa6f42915812 (diff) | |
download | bdk-53928b12e7f0daa07cabe0274096f252af8a8589.tar.gz |
Convert remaining files to 4 space indent
Convert all the remaining files to a 4 space indent
to comply with PEP8 style rules. ALso fixed up a few
other style issues that were recently introduced.
Bug: 28007659
Test: `python test_runner.py` passes.
Test: pylint passes.
Change-Id: I519246493407ca8cd4a7a5da84140a6e67618592
-rw-r--r-- | cli/lib/bdk.py | 82 | ||||
-rw-r--r-- | cli/lib/commands/v2/build/image.py | 81 | ||||
-rw-r--r-- | cli/lib/core/provision.py | 1 | ||||
-rw-r--r-- | cli/lib/core/tool.py | 8 | ||||
-rw-r--r-- | cli/lib/error.py | 32 | ||||
-rw-r--r-- | cli/lib/test/stubs.py | 10 | ||||
-rw-r--r-- | cli/lib/test_runner.py | 8 |
7 files changed, 112 insertions, 110 deletions
diff --git a/cli/lib/bdk.py b/cli/lib/bdk.py index 86140b8..e861ec1 100644 --- a/cli/lib/bdk.py +++ b/cli/lib/bdk.py @@ -29,57 +29,57 @@ from metrics.data_types import exception def CommandPath(name): - bdk_lib_path = os.path.dirname(__file__) - path = os.path.join(bdk_lib_path, 'commands', name) - return path + bdk_lib_path = os.path.dirname(__file__) + path = os.path.join(bdk_lib_path, 'commands', name) + return path def GetBdkCli(): - """Creates the fully populated BDK CLI. + """Creates the fully populated BDK CLI. - Returns: - The climanager.Cli object. - """ - # Create the CLI. - bdk_cli = climanager.Cli('bdk', CommandPath('root')) + Returns: + The climanager.Cli object. + """ + # Create the CLI. + bdk_cli = climanager.Cli('bdk', CommandPath('root')) - # Add command groups. - bdk_cli.AddCommandGroup('bsp', CommandPath('bsp')) - bdk_cli.AddCommandGroup('config', CommandPath('config')) - bdk_cli.AddCommandGroup('product', CommandPath('product')) + # Add command groups. + bdk_cli.AddCommandGroup('bsp', CommandPath('bsp')) + bdk_cli.AddCommandGroup('config', CommandPath('config')) + bdk_cli.AddCommandGroup('product', CommandPath('product')) - if 'BDK_V2_DEVELOPMENT' in os.environ: - bdk_cli.AddCommandGroup('build', CommandPath('v2/build')) - bdk_cli.AddCommandGroup('environment', CommandPath('v2/environment')) - bdk_cli.AddCommandGroup('root', CommandPath('v2/root')) + if 'BDK_V2_DEVELOPMENT' in os.environ: + bdk_cli.AddCommandGroup('build', CommandPath('v2/build')) + bdk_cli.AddCommandGroup('environment', CommandPath('v2/environment')) + bdk_cli.AddCommandGroup('root', CommandPath('v2/root')) - return bdk_cli + return bdk_cli def main(): - # Initialize metrics. - metrics_util.initialize() - - bdk_cli = GetBdkCli() - try: - return bdk_cli.Execute() - # pylint: disable=broad-except - except Exception as e: - metrics_util.send_hit_and_retries( - exception.ExceptionHit.from_exception(e, is_fatal=True)) - if bdk_cli.args.debug: - raise - else: - print(e, file=sys.stderr) - if isinstance(e, error.Error): - return e.errno - return 1 + # Initialize metrics. + metrics_util.initialize() + + bdk_cli = GetBdkCli() + try: + return bdk_cli.Execute() + # pylint: disable=broad-except + except Exception as e: + metrics_util.send_hit_and_retries( + exception.ExceptionHit.from_exception(e, is_fatal=True)) + if bdk_cli.args.debug: + raise + else: + print(e, file=sys.stderr) + if isinstance(e, error.Error): + return e.errno + return 1 if __name__ == '__main__': - try: - sys.exit(main()) - except KeyboardInterrupt: - # Handle Ctrl+C so we don't print stack traces. - sys.stderr.write('bdk killed by user\n') - sys.exit(1) + try: + sys.exit(main()) + except KeyboardInterrupt: + # Handle Ctrl+C so we don't print stack traces. + sys.stderr.write('bdk killed by user\n') + sys.exit(1) diff --git a/cli/lib/commands/v2/build/image.py b/cli/lib/commands/v2/build/image.py index dff42bb..53e21fc 100644 --- a/cli/lib/commands/v2/build/image.py +++ b/cli/lib/commands/v2/build/image.py @@ -26,48 +26,51 @@ from project import dependency class Image(clicommand.Command): - """Build a image for a product.""" + """Build a image for a product.""" - @staticmethod - def Args(parser): - Image.AddProductArgs(parser) - parser.add_argument('--type', choices=image_build.IMAGE_TYPES, - default=image_build.IMAGE_TYPE_ODM, required=False, - help='Specifies which image type to build.' - '(default: {})'.format(image_build.IMAGE_TYPE_ODM)) + @staticmethod + def Args(parser): + Image.AddProductArgs(parser) + parser.add_argument('--type', choices=image_build.IMAGE_TYPES, + default=image_build.IMAGE_TYPE_ODM, required=False, + help='Specifies which image type to build.' + '(default: {})'.format( + image_build.IMAGE_TYPE_ODM)) - def Run(self, args): - try: - # Technically we don't need to validate the board; the user could have - # built with it then uninstalled it, and the build is checked elsewhere. - # We do still need the os downloaded, as it contains necessary tools. - spec, target = self.GetSpecAndTarget(args, board=False) - except clicommand.Error as error: - print str(error) - return 1 + def Run(self, args): + try: + # Technically we don't need to validate the board; the user could + # have built with it then uninstalled it, and the build is checked + # elsewhere. We do still need the os downloaded, as it contains + # necessary tools. + spec, target = self.GetSpecAndTarget(args, board=False) + except clicommand.Error as error: + print str(error) + return 1 - image_build.AddTargetOsPacks(spec, target) + image_build.AddTargetOsPacks(spec, target) - target_dir = os.path.join(spec.config.cache_dir, - '{}.cache'.format(target.name)) - try: - mountpoint = os.path.join(os.path.sep, args.type) - image_build.CreateTargetCache(spec, target, target_dir, mountpoint, - update=True) - except dependency.Error as e: - print 'Dependencies unmet for target {}: {}'.format(target.name, e) - return 1 + target_dir = os.path.join(spec.config.cache_dir, + '{}.cache'.format(target.name)) + try: + mountpoint = os.path.join(os.path.sep, args.type) + image_build.CreateTargetCache(spec, target, target_dir, mountpoint, + update=True) + except dependency.Error as e: + print 'Dependencies unmet for target {}: {}'.format(target.name, e) + return 1 - try: - ret = image_build.BuildImage(args.type, target, target_dir, - spec.config.output_dir) - except image_build.Error as e: - print 'Error building image for target {} at {}: {}'.format( - target.name, target.origin, e) - return 1 + try: + ret = image_build.BuildImage(args.type, target, target_dir, + spec.config.output_dir) + except image_build.Error as e: + print 'Error building image for target {} at {}: {}'.format( + target.name, target.origin, e) + return 1 - if ret: - print 'Failed to build image (unknown error code {})'.format(ret) - else: - print 'Successfully built image in {}'.format(spec.config.output_dir) - return ret + if ret: + print 'Failed to build image (unknown error code {})'.format(ret) + else: + print 'Successfully built image in {}'.format( + spec.config.output_dir) + return ret diff --git a/cli/lib/core/provision.py b/cli/lib/core/provision.py index 2063845..0261abc 100644 --- a/cli/lib/core/provision.py +++ b/cli/lib/core/provision.py @@ -22,7 +22,6 @@ import shutil import tempfile from core import tool -from core import util import error diff --git a/cli/lib/core/tool.py b/cli/lib/core/tool.py index 3bafcb3..ab4db82 100644 --- a/cli/lib/core/tool.py +++ b/cli/lib/core/tool.py @@ -228,9 +228,9 @@ class PathToolWrapper(ToolWrapper): class PathToolRunner(object): """Serves as a PathToolWrapper factory.""" - def run(self, path, args): + def run(self, path, args, piped=False): path_tool = PathToolWrapper(path) - return path_tool.run(args) + return path_tool.run(args, piped=piped) class ProvisionDeviceTool(ToolWrapper): @@ -270,9 +270,9 @@ class ProvisionDeviceTool(ToolWrapper): # to find utilities. self.add_caller_env_path() - def run(self, arg_array=None): + def run(self, arg_array=None, piped=False): with self._target.get_device().linked(self._target.os_version): - super(ProvisionDeviceTool, self).run(arg_array) + super(ProvisionDeviceTool, self).run(arg_array, piped=piped) class BrunchToolWrapper(ToolWrapper): diff --git a/cli/lib/error.py b/cli/lib/error.py index 85878a2..bdbc8cc 100644 --- a/cli/lib/error.py +++ b/cli/lib/error.py @@ -22,19 +22,19 @@ GENERIC_ERRNO = 1 class Error(Exception): - """A root class for all BDK errors.""" - - description = 'BDK Error' - - def __init__(self, message='', errno=GENERIC_ERRNO): - if errno == 0: - raise ValueError('Error numbers can not be 0.') - - full_message = self.description - if message is not None: - # Just in case someone passes a non-string. - message = str(message) - if message: - full_message += ': ' + message - super(Error, self).__init__(full_message) - self.errno = errno + """A root class for all BDK errors.""" + + description = 'BDK Error' + + def __init__(self, message='', errno=GENERIC_ERRNO): + if errno == 0: + raise ValueError('Error numbers can not be 0.') + + full_message = self.description + if message is not None: + # Just in case someone passes a non-string. + message = str(message) + if message: + full_message += ': ' + message + super(Error, self).__init__(full_message) + self.errno = errno diff --git a/cli/lib/test/stubs.py b/cli/lib/test/stubs.py index f4687a1..45f5c7d 100644 --- a/cli/lib/test/stubs.py +++ b/cli/lib/test/stubs.py @@ -743,13 +743,13 @@ class StubUrllib(object): class StubUuid(object): - """Stubs for uuid as necessary.""" + """Stubs for uuid as necessary.""" - def __init__(self, generate='generated_uuid'): - self.generate = generate + def __init__(self, generate='generated_uuid'): + self.generate = generate - def uuid4(self): - return self.generate + def uuid4(self): + return self.generate class StubContextManager(object): diff --git a/cli/lib/test_runner.py b/cli/lib/test_runner.py index 3dab7ce..0c86281 100644 --- a/cli/lib/test_runner.py +++ b/cli/lib/test_runner.py @@ -22,7 +22,7 @@ import unittest if __name__ == '__main__': - testsuite = unittest.TestLoader().discover( - start_dir=os.path.dirname(__file__), - pattern='*_unittest.py') - unittest.TextTestRunner(verbosity=1, buffer=True).run(testsuite) + testsuite = unittest.TestLoader().discover( + start_dir=os.path.dirname(__file__), + pattern='*_unittest.py') + unittest.TextTestRunner(verbosity=1, buffer=True).run(testsuite) |