The attached patch adds a command line flag to disable interaction in virt-install. I think this would be handy for anyone using virt-install for scripting or automated testing. Setting the flag causes virt-install to throw an exception when there would normally be a prompt for input. I used a global variable in cli.py to accomplish this, which is simple, but there may be a 'more correct' way to do this that I'm missing. Anyone have any input on the method, or the feature itself? Thanks, Cole -- Cole Robinson crobinso@xxxxxxxxxx
diff -r c0b20d1eaaf2 virt-install --- a/virt-install Wed Oct 03 15:39:18 2007 -0400 +++ b/virt-install Thu Oct 04 16:00:34 2007 -0400 @@ -276,6 +276,9 @@ def parse_args(): # Misc options parser.add_option("-d", "--debug", action="store_true", dest="debug", help=_("Print debugging information")) + parser.add_option("", "--nointeract", action="store_false", + dest="interact", default="true", + help=_("Do not use interactive prompts, just error instead.")) (options,args) = parser.parse_args() @@ -333,6 +336,7 @@ def main(): options = parse_args() cli.setupLogging("virt-install", options.debug) + cli.set_interaction(options.interact) conn = cli.getConnection(options.connect) type = None diff -r c0b20d1eaaf2 virtinst/cli.py --- a/virtinst/cli.py Wed Oct 03 15:39:18 2007 -0400 +++ b/virtinst/cli.py Thu Oct 04 16:09:54 2007 -0400 @@ -70,9 +70,19 @@ def getConnection(connect): # Prompting # -def prompt_for_input(prompt = "", val = None): +global_interact=True + +def set_interaction(val): + global global_interact + global_interact = val + +def prompt_for_input(prompt = "", val = None, interact = None): if val is not None: return val + if interact is None: + interact=global_interact + if not interact: + raise RuntimeError, _("Attempted to prompt for input with interactivity disabled. Prompt was '%s'") % prompt print prompt + " ", return sys.stdin.readline().strip()
_______________________________________________ et-mgmt-tools mailing list et-mgmt-tools@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/et-mgmt-tools