Add interactive option
This commit is contained in:
parent
3937dfd0f5
commit
ae5a6a47a3
|
@ -38,6 +38,9 @@ def load_args():
|
|||
parser.add_argument(
|
||||
'-d', '--debug', action='store_true',
|
||||
help=("Debugging output"))
|
||||
parser.add_argument(
|
||||
'-i', '--interactive', action='store_true',
|
||||
help=("If set, prompt to continue running after a failed script."))
|
||||
parser.add_argument(
|
||||
'--dry-run', action='store_true',
|
||||
help=("Dry run only, don't actually modify system, prints out "
|
||||
|
@ -59,10 +62,14 @@ def set_environment():
|
|||
def main():
|
||||
args = load_args()
|
||||
set_environment()
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
format="%(levelname)s:%(asctime)s:%(name)s:%(message)s")
|
||||
if args.debug:
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
format="%(levelname)s:%(asctime)s:%(name)s:%(message)s")
|
||||
else:
|
||||
logging.basicConfig(level=logging.INFO,
|
||||
format="%(levelname)s:%(asctime)s:%(name)s:%(message)s")
|
||||
em = manager.ElementManager(args.element, args.hook, args.element_path,
|
||||
args.dry_run, args.debug)
|
||||
args.dry_run, args.interactive)
|
||||
em.run()
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ from distutils import dir_util
|
|||
import logging
|
||||
import os
|
||||
import string
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from dib_elements.element import Element
|
||||
|
@ -27,7 +28,8 @@ from diskimage_builder.elements import expand_dependencies
|
|||
|
||||
class ElementManager(object):
|
||||
|
||||
def __init__(self, elements, hooks, element_paths=None, dry_run=False):
|
||||
def __init__(self, elements, hooks, element_paths=None, dry_run=False,
|
||||
interactive=False):
|
||||
"""
|
||||
:param elements: Element names to apply.
|
||||
:type elements: list.
|
||||
|
@ -41,6 +43,7 @@ class ElementManager(object):
|
|||
self.elements = elements
|
||||
self.dry_run = dry_run
|
||||
self.hooks = hooks
|
||||
self.interactive = interactive
|
||||
self.loaded_elements = {}
|
||||
|
||||
# the environment variable should override anything passed in
|
||||
|
@ -126,5 +129,12 @@ class ElementManager(object):
|
|||
rc = call(['sudo', '-E', '/bin/bash', script])
|
||||
if rc != 0:
|
||||
logging.error("scripted failed: %s" % script)
|
||||
if self.interactive:
|
||||
entry = raw_input("Continue? (y/n): ")
|
||||
if entry.lower() == 'y':
|
||||
logging.info("continuing on user command.")
|
||||
continue
|
||||
logging.error("exiting after failure.")
|
||||
sys.exit(1)
|
||||
else:
|
||||
logging.info("script to execute: %s" % script)
|
||||
|
|
Loading…
Reference in New Issue