add a way to specify actions to take in the UI on the command line
--script takes a little python snippet to run in a helpful namespace --click is a wrapper around --script to click a button
This commit is contained in:
parent
07438a1049
commit
db4d8a537e
|
@ -48,6 +48,10 @@ checks:
|
|||
- /usr/bin/curtin
|
||||
'''
|
||||
|
||||
class ClickAction(argparse.Action):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
namespace.scripts.append("c(" + repr(values) + ")")
|
||||
|
||||
def parse_options(argv):
|
||||
parser = argparse.ArgumentParser(
|
||||
description='SUbiquity - Ubiquity for Servers',
|
||||
|
@ -65,6 +69,8 @@ def parse_options(argv):
|
|||
dest='uefi',
|
||||
help='run in uefi support mode')
|
||||
parser.add_argument('--screens', action='append', dest='screens', default=[])
|
||||
parser.add_argument('--script', metavar="SCRIPT", action='append', dest='scripts', default=[], help='Execute SCRIPT in a namespace containing view helpers and "ui"')
|
||||
parser.add_argument('--click', metavar="PAT", action=ClickAction, help='Synthesize a click on a button matching PAT')
|
||||
parser.add_argument('--answers')
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
|
|
@ -321,6 +321,13 @@ class Application:
|
|||
def exit(self):
|
||||
raise urwid.ExitMainLoop()
|
||||
|
||||
def run_scripts(self, loop, user_data):
|
||||
scripts, d = user_data
|
||||
script, scripts = scripts[0], scripts[1:]
|
||||
exec(script, d)
|
||||
if scripts:
|
||||
self.common['loop'].set_alarm_in(0.05, self.run_scripts, (scripts, d))
|
||||
|
||||
def run(self):
|
||||
if not hasattr(self, 'loop'):
|
||||
if self.common['opts'].run_on_serial:
|
||||
|
@ -338,6 +345,17 @@ class Application:
|
|||
self.common['base_model'] = self.model_class(self.common)
|
||||
try:
|
||||
self.common['loop'].set_alarm_in(0.05, self.next_screen)
|
||||
if self.common['opts'].scripts:
|
||||
from subiquitycore.testing import view_helpers
|
||||
d = view_helpers.__dict__.copy()
|
||||
def c(pat):
|
||||
but = view_helpers.find_button_matching(self.common['ui'], '.*' + pat + '.*')
|
||||
if not but:
|
||||
raise Exception("no button found matching %r"%(pat,))
|
||||
view_helpers.click(but)
|
||||
d['c'] = c
|
||||
d['ui'] = self.common['ui']
|
||||
self.common['loop'].set_alarm_in(0.06, self.run_scripts, (self.common['opts'].scripts, d))
|
||||
controllers_mod = __import__('%s.controllers' % self.project, None, None, [''])
|
||||
for k in self.controllers:
|
||||
log.debug("Importing controller: {}".format(k))
|
||||
|
|
Loading…
Reference in New Issue