summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2013-06-14 11:27:09 -0600
committerStephen Warren <swarren@nvidia.com>2013-06-14 11:27:09 -0600
commit67fcde63c7a78ea3af21ee3f2f71aa5367840da7 (patch)
tree0582ca81f8d9f25cd9a2369f1846ffabe52733d3
parent49fbb49ef58df858ee5822802ed686ff06223640 (diff)
downloadtegra-uboot-flasher-scripts-67fcde63c7a78ea3af21ee3f2f71aa5367840da7.tar.gz
Convert build script to argparse
Future patches will add some options. This will be easier with argparse. Unfortunately, argparse doesn't support a default sub-command. Hence, the shortcut "./build" for "./build build" is no longer supported. There are ways to work around this by treating the command name as an optional argument rather than sub-commands. However, this limits future flexibility, since the fake sub-commands won't be able to accept sub command- specific options. Signed-off-by: Stephen Warren <swarren@nvidia.com>
-rw-r--r--README-developer.txt2
-rwxr-xr-xbuild51
2 files changed, 25 insertions, 28 deletions
diff --git a/README-developer.txt b/README-developer.txt
index 89fcd2c..d59ec07 100644
--- a/README-developer.txt
+++ b/README-developer.txt
@@ -84,7 +84,7 @@ script assumes a value of arm-linux-gnueabi-.
cd to the scripts sub-directory (i.e. the directory containing this README),
and execute:
-./build
+./build build
Flashing Devices
================
diff --git a/build b/build
index 2a3bf7e..d14231f 100755
--- a/build
+++ b/build
@@ -20,6 +20,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+import argparse
import multiprocessing
import os
import shutil
@@ -172,32 +173,28 @@ def cmd_help():
for cmd in sorted(cmdmap.keys()):
print ' ', cmd
-def cmd_help_error_exit():
- print 'ERROR:',
- cmd_help()
- sys.exit(1)
-
-cmdmap = {
- '-h': cmd_help,
- '--help': cmd_help,
- 'help': cmd_help,
- 'help-error-exit': cmd_help_error_exit,
- 'build-uboots': cmd_build_uboots,
- 'build-bcts-imgs': cmd_build_bcts_imgs,
- 'build-configs': cmd_build_configs,
- 'build': cmd_build,
-}
+parser = argparse.ArgumentParser(description='Build U-Boot, BCT, and flash ' +
+ 'images for Tegra boards.')
+
+subparsers = parser.add_subparsers()
+
+parser_list_configs = subparsers.add_parser('build-uboots',
+ help='Build U-Boot binaries')
+parser_list_configs.set_defaults(func = cmd_build_uboots)
+
+parser_list_configs = subparsers.add_parser('build-bcts-imgs',
+ help='Build BCT and flash images')
+parser_list_configs.set_defaults(func = cmd_build_bcts_imgs)
+
+parser_list_configs = subparsers.add_parser('build-configs',
+ help='Build config files')
+parser_list_configs.set_defaults(func = cmd_build_configs)
+
+parser_list_configs = subparsers.add_parser('build',
+ help='Build everything')
+parser_list_configs.set_defaults(func = cmd_build)
if __name__ == '__main__':
- app = sys.argv.pop(0)
- if len(sys.argv) == 0:
- cmdname = 'build'
- elif len(sys.argv) == 1:
- cmdname = sys.argv.pop(0)
- else:
- cmdname = 'help-error-exit'
- if not cmdmap.has_key(cmdname):
- cmdname = 'help-error-exit'
- load_configs('configs')
- cmd = cmdmap[cmdname]
- cmd()
+ args = parser.parse_args()
+ load_configs(os.path.join(scripts_dir, 'configs'))
+ args.func()