Skip to content

Commit

Permalink
container_build.py: switch to argparse
Browse files Browse the repository at this point in the history
Given that build.py uses argparse, and the two builders are
kind of parallel, it makes sense to switch container_build
to also use argparse.
  • Loading branch information
chris3torek committed Jul 19, 2017
1 parent 64c9ddb commit 5366523
Showing 1 changed file with 27 additions and 34 deletions.
61 changes: 27 additions & 34 deletions container_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
import os
import os.path
import argparse

IMAGE = 'nefelinetworks/bess_build:latest' + os.getenv('TAG_SUFFIX', '')
BESS_DIR_HOST = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -73,44 +74,36 @@ def do_dist_clean():
run_docker_cmd('%s dist_clean' % BUILD_SCRIPT)


def print_usage():
print('Usage: %s '
'[all|bess|kmod|kmod_buildtest|clean|dist_clean|shell||help]'
% sys.argv[0], file=sys.stderr)
def print_usage(parser):
parser.print_help(file=sys.stderr)
sys.exit(2)


def main():
os.chdir(BESS_DIR_HOST)

if len(sys.argv) == 1:
build_bess()
build_kmod()
elif len(sys.argv) == 2:
if sys.argv[1] == 'all':
build_all()
elif sys.argv[1] == 'bess':
build_bess()
elif sys.argv[1] == 'kmod':
build_kmod()
elif sys.argv[1] == 'kmod_buildtest':
build_kmod_buildtest()
elif sys.argv[1] == 'clean':
do_clean()
elif sys.argv[1] == 'dist_clean':
do_dist_clean()
elif sys.argv[1] == 'shell':
run_shell()
elif sys.argv[1] == 'help':
print_usage()
sys.exit(0)
else:
print('Error - unknown command "%s".' % sys.argv[1],
file=sys.stderr)
print_usage()
sys.exit(2)
else:
print_usage()
sys.exit(2)
parser = argparse.ArgumentParser(description='Build BESS in container')
cmds = {
'all': build_all,
'bess': build_bess,
'kmod': build_kmod,
'kmod_buildtest': build_kmod_buildtest,
'clean': do_clean,
'dist_clean': do_dist_clean,
'shell': run_shell,
'help': lambda: print_usage(parser),
}
cmdlist = sorted(cmds.keys())
parser.add_argument(
'action',
metavar='action',
nargs='?',
default='all',
choices=cmdlist,
help='Action is one of ' + ', '.join(cmdlist))

args = parser.parse_args()

cmds[args.action]()


if __name__ == '__main__':
Expand Down

0 comments on commit 5366523

Please sign in to comment.