diff options
author | Will Drewry <drewry@google.com> | 2015-10-27 22:06:38 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-10-27 22:06:38 +0000 |
commit | e5feb7861f171f6323d9303e94fa7b2bb827874d (patch) | |
tree | 786fc7dbd0f572ab1ee28dca22fc53c51b2418ea | |
parent | 4c1eaabed6e7f1da9c2107bb156d04705089871e (diff) | |
parent | 8c936cfae6611c16e9beba7453b9373a7e7c3aae (diff) | |
download | bdk-e5feb7861f171f6323d9303e94fa7b2bb827874d.tar.gz |
Merge "brunch: make sure all commands return an int" into mnc-brillo-dev
-rw-r--r-- | brunch/lib/cli/clicommand.py | 14 | ||||
-rw-r--r-- | brunch/lib/cli/climanager.py | 11 | ||||
-rw-r--r-- | brunch/lib/commands/bsp/download.py | 4 | ||||
-rw-r--r-- | brunch/lib/commands/bsp/list.py | 1 | ||||
-rw-r--r-- | brunch/lib/commands/bsp/uninstall.py | 2 | ||||
-rw-r--r-- | brunch/lib/commands/config/metrics.py | 2 | ||||
-rw-r--r-- | brunch/lib/commands/product/create.py | 3 | ||||
-rw-r--r-- | brunch/lib/commands/product/envsetup.py | 1 | ||||
-rw-r--r-- | brunch/lib/commands/product/reconfig.py | 1 | ||||
-rw-r--r-- | brunch/lib/commands/root/help.py | 1 | ||||
-rw-r--r-- | brunch/lib/commands/root/version.py | 1 |
11 files changed, 37 insertions, 4 deletions
diff --git a/brunch/lib/cli/clicommand.py b/brunch/lib/cli/clicommand.py index 153d688..c0a3a02 100644 --- a/brunch/lib/cli/clicommand.py +++ b/brunch/lib/cli/clicommand.py @@ -21,8 +21,20 @@ class Command(object): def Args(parser): pass + @classmethod + def set_group(cls, grp): + cls._group = grp + + @classmethod + def group(cls): + try: + return cls._group + except AttributeError, e: + return None + def Run(self, args): - pass + """Called when the command is used. Must return an 'int'.""" + raise NotImplementedError, 'Run() must be overridden' class Group(object): pass diff --git a/brunch/lib/cli/climanager.py b/brunch/lib/cli/climanager.py index 761caf9..ca40944 100644 --- a/brunch/lib/cli/climanager.py +++ b/brunch/lib/cli/climanager.py @@ -50,6 +50,8 @@ class CommandGroup(object): help=help_string) com_parser.set_defaults(command_type=command_type) command_type.Args(com_parser) + # Update the command with its parentage + command_type.set_group(self) def FindTypes(self, module, find_type): class_types = [] @@ -95,4 +97,11 @@ class Cli(object): args = self.root_group.parser.parse_args() command = args.command_type() - return command.Run(args) + result = command.Run(args) + # Enforce the return type with a useful message. + if type(result) != int: + raise TypeError, 'Non-integer return code from "{0} {1}". ' \ + 'Please report this bug!'.format( + args.command_type.group().name, + args.command_type.__name__.lower()) + return result diff --git a/brunch/lib/commands/bsp/download.py b/brunch/lib/commands/bsp/download.py index 704da65..58fe462 100644 --- a/brunch/lib/commands/bsp/download.py +++ b/brunch/lib/commands/bsp/download.py @@ -33,4 +33,6 @@ class Download(clicommand.Command): def Run(self, args): dl = downloader.Downloader() - dl.Download(args.device) + if dl.Download(args.device): + return 0 + return 1 diff --git a/brunch/lib/commands/bsp/list.py b/brunch/lib/commands/bsp/list.py index 1bb21f6..4c6633b 100644 --- a/brunch/lib/commands/bsp/list.py +++ b/brunch/lib/commands/bsp/list.py @@ -51,3 +51,4 @@ class List(clicommand.Command): def Run(self, args): devices = self.Generate() self.Print(devices) + return 0 diff --git a/brunch/lib/commands/bsp/uninstall.py b/brunch/lib/commands/bsp/uninstall.py index 6983029..7b15a87 100644 --- a/brunch/lib/commands/bsp/uninstall.py +++ b/brunch/lib/commands/bsp/uninstall.py @@ -34,3 +34,5 @@ class Uninstall(clicommand.Command): print 'Uninstalled {0} BSP.'.format(args.device) else: print 'Unrecognized device name: {0}'.format(args.device) + return 1 + return 0 diff --git a/brunch/lib/commands/config/metrics.py b/brunch/lib/commands/config/metrics.py index a48a6d2..16c2174 100644 --- a/brunch/lib/commands/config/metrics.py +++ b/brunch/lib/commands/config/metrics.py @@ -40,6 +40,8 @@ class Metrics(clicommand.Command): else: # Should never get here if parser is working correctly print 'Unrecognized option,', args.action + return 1 + return 0 def _Check_Status(self): if config.UserStore().metrics_opt_in != '0': diff --git a/brunch/lib/commands/product/create.py b/brunch/lib/commands/product/create.py index 523a188..e13ba74 100644 --- a/brunch/lib/commands/product/create.py +++ b/brunch/lib/commands/product/create.py @@ -49,5 +49,6 @@ class Create(clicommand.Command): p = product.ProductCreator(args.type, args.name, args.vendor, args.device) if p.exists(): print 'Product "%s" already exists' % args.name - return False + return 1 p.create() + return 0 diff --git a/brunch/lib/commands/product/envsetup.py b/brunch/lib/commands/product/envsetup.py index 18dfd82..cce134b 100644 --- a/brunch/lib/commands/product/envsetup.py +++ b/brunch/lib/commands/product/envsetup.py @@ -51,3 +51,4 @@ class Envsetup(clicommand.Command): else: print 'Generating envsetup.sh . . .' env.envsetup() + return 0 diff --git a/brunch/lib/commands/product/reconfig.py b/brunch/lib/commands/product/reconfig.py index eb340c3..acf7636 100644 --- a/brunch/lib/commands/product/reconfig.py +++ b/brunch/lib/commands/product/reconfig.py @@ -72,3 +72,4 @@ class Reconfig(clicommand.Command): print 'Configuration:' for key, val in store.dict().iteritems(): print ' %s: %s' % (key, val) + return 0 diff --git a/brunch/lib/commands/root/help.py b/brunch/lib/commands/root/help.py index cc4077f..95d0ce9 100644 --- a/brunch/lib/commands/root/help.py +++ b/brunch/lib/commands/root/help.py @@ -28,3 +28,4 @@ class Help(clicommand.Command): def Run(self, args): print "Help" # TODO(leecam): Implement + return 0 diff --git a/brunch/lib/commands/root/version.py b/brunch/lib/commands/root/version.py index 3b35ed2..8c22a87 100644 --- a/brunch/lib/commands/root/version.py +++ b/brunch/lib/commands/root/version.py @@ -23,3 +23,4 @@ class Version(clicommand.Command): def Run(self, args): print "Preview BDK 0.1" + return 0 |