Use main() in direct executables
This commit is contained in:
parent
ca10263696
commit
ad1bfc8860
@ -65,4 +65,8 @@ parser_extract.add_argument('container', help='Container name')
|
||||
parser_extract.add_argument('source', help='Source file or directory within the container')
|
||||
parser_extract.add_argument('destination', help='Destination file or directory on the host')
|
||||
|
||||
main(parser.parse_args())
|
||||
args = parser.parse_args()
|
||||
if hasattr(args, 'action'):
|
||||
main(args)
|
||||
else:
|
||||
parser.print_usage()
|
||||
|
@ -105,6 +105,7 @@ parser = argparse.ArgumentParser(description='LXC container and package manager'
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
parser_list = subparsers.add_parser('list')
|
||||
parser_list.set_defaults(action='list-installed')
|
||||
subparsers_list = parser_list.add_subparsers()
|
||||
parser_list_installed = subparsers_list.add_parser('installed')
|
||||
parser_list_installed.set_defaults(action='list-installed')
|
||||
@ -125,4 +126,8 @@ parser_uninstall = subparsers.add_parser('uninstall')
|
||||
parser_uninstall.set_defaults(action='uninstall')
|
||||
parser_uninstall.add_argument('app', help='Application to uninstall')
|
||||
|
||||
main(parser.parse_args())
|
||||
args = parser.parse_args()
|
||||
if hasattr(args, 'action'):
|
||||
main(args)
|
||||
else:
|
||||
parser.print_usage()
|
||||
|
@ -6,6 +6,24 @@ import argparse
|
||||
from vmmgr.config import Config
|
||||
from vmmgr.vmmgr import VMMgr
|
||||
|
||||
def main(args):
|
||||
vmmgr = VMMgr(Config())
|
||||
if args.action == 'register-app':
|
||||
# Used by package install.sh script
|
||||
vmmgr.register_app(args.app, args.host, args.login, args.password)
|
||||
elif args.action == 'unregister-app':
|
||||
# Used by package uninstall.sh script
|
||||
vmmgr.unregister_app(args.app)
|
||||
elif args.action == 'rebuild-issue':
|
||||
# Used by inittab on VM startup
|
||||
vmmgr.rebuild_issue()
|
||||
elif args.action == 'register-proxy':
|
||||
# Used in init scripts on application startup
|
||||
vmmgr.register_proxy(args.app)
|
||||
elif args.action == 'unregister-proxy':
|
||||
# Used in init scripts on application stop
|
||||
vmmgr.unregister_proxy(args.app)
|
||||
|
||||
parser = argparse.ArgumentParser(description='VM application manager')
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
@ -32,19 +50,7 @@ parser_unregister_proxy.set_defaults(action='unregister-proxy')
|
||||
parser_unregister_proxy.add_argument('app', help='Application name')
|
||||
|
||||
args = parser.parse_args()
|
||||
vmmgr = VMMgr(Config())
|
||||
if args.action == 'register-app':
|
||||
# Used by package install.sh script
|
||||
vmmgr.register_app(args.app, args.host, args.login, args.password)
|
||||
elif args.action == 'unregister-app':
|
||||
# Used by package uninstall.sh script
|
||||
vmmgr.unregister_app(args.app)
|
||||
elif args.action == 'rebuild-issue':
|
||||
# Used by inittab on VM startup
|
||||
vmmgr.rebuild_issue()
|
||||
elif args.action == 'register-proxy':
|
||||
# Used in init scripts on application startup
|
||||
vmmgr.register_proxy(args.app)
|
||||
elif args.action == 'unregister-proxy':
|
||||
# Used in init scripts on application stop
|
||||
vmmgr.unregister_proxy(args.app)
|
||||
if hasattr(args, 'action'):
|
||||
main(args)
|
||||
else:
|
||||
parser.print_usage()
|
||||
|
Loading…
Reference in New Issue
Block a user