remove --script/--click command line arguments

I implemented these a long time ago to help working on parts of the ui
by allowing a way to script moving past some screens. I haven't used
them in ages, it's pretty bad code and probably a fragmentary answers
file is a better solution to the same problem. What do you think?
This commit is contained in:
Michael Hudson-Doyle 2022-12-07 14:55:49 +13:00
parent b510afbc65
commit 06d7f04032
3 changed files with 0 additions and 88 deletions

View File

@ -24,11 +24,6 @@ from subiquitycore import __version__ as VERSION
from console_conf.core import ConsoleConf, RecoveryChooser from console_conf.core import ConsoleConf, RecoveryChooser
class ClickAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
namespace.scripts.append("c(" + repr(values) + ")")
def parse_options(argv): def parse_options(argv):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=( description=(
@ -49,12 +44,6 @@ def parse_options(argv):
help="Don't Probe. Use probe data file") help="Don't Probe. Use probe data file")
parser.add_argument('--screens', action='append', dest='screens', parser.add_argument('--screens', action='append', dest='screens',
default=[]) 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') parser.add_argument('--answers')
parser.add_argument('--recovery-chooser-mode', action='store_true', parser.add_argument('--recovery-chooser-mode', action='store_true',
dest='chooser_systems', dest='chooser_systems',

View File

@ -31,11 +31,6 @@ from .common import (
from .server import make_server_args_parser from .server import make_server_args_parser
class ClickAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
namespace.scripts.append("c(" + repr(values) + ")")
def make_client_args_parser(): def make_client_args_parser():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Subiquity - Ubiquity for Servers', description='Subiquity - Ubiquity for Servers',
@ -63,12 +58,6 @@ def make_client_args_parser():
help='Run the installer in unicode mode.') help='Run the installer in unicode mode.')
parser.add_argument('--screens', action='append', dest='screens', parser.add_argument('--screens', action='append', dest='screens',
default=[]) 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') parser.add_argument('--answers')
parser.add_argument('--server-pid') parser.add_argument('--server-pid')
parser.add_argument('--output-base', action='store', dest='output_base', parser.add_argument('--output-base', action='store', dest='output_base',

View File

@ -254,70 +254,6 @@ class TuiApplication(Application):
def select_initial_screen(self): def select_initial_screen(self):
self.next_screen() self.next_screen()
def run_scripts(self, scripts):
# run_scripts runs (or rather arranges to run, it's all async)
# a series of python snippets in a helpful namespace. This is
# all in aid of being able to test some part of the UI without
# having to click the same buttons over and over again to get
# the UI to the part you are working on.
#
# In the namespace are:
# * everything from view_helpers
# * wait, delay execution of subsequent scripts for a while
# * c, a function that finds a button and clicks it. uses
# wait, above to wait for the button to appear in case it
# takes a while.
from subiquitycore.testing import view_helpers
class ScriptState:
def __init__(self):
self.ns = view_helpers.__dict__.copy()
self.waiting = False
self.wait_count = 0
self.scripts = scripts
ss = ScriptState()
def _run_script():
log.debug("running %s", ss.scripts[0])
exec(ss.scripts[0], ss.ns)
if ss.waiting:
return
ss.scripts = ss.scripts[1:]
if ss.scripts:
self.aio_loop.call_soon(_run_script)
def c(pat):
but = view_helpers.find_button_matching(self.ui, '.*' + pat + '.*')
if not but:
ss.wait_count += 1
if ss.wait_count > 10:
raise Exception("no button found matching %r after"
"waiting for 10 secs" % pat)
wait(1, func=lambda: c(pat))
return
ss.wait_count = 0
view_helpers.click(but)
def wait(delay, func=None):
ss.waiting = True
def next():
ss.waiting = False
if func is not None:
func()
if not ss.waiting:
ss.scripts = ss.scripts[1:]
if ss.scripts:
_run_script()
self.aio_loop.call_later(delay, next)
ss.ns['c'] = c
ss.ns['wait'] = wait
ss.ns['ui'] = self.ui
self.aio_loop.call_later(0.06, _run_script)
def set_rich(self, rich): def set_rich(self, rich):
if rich == self.rich_mode: if rich == self.rich_mode:
return return
@ -374,8 +310,6 @@ class TuiApplication(Application):
self.start_urwid() self.start_urwid()
async def run(self): async def run(self):
if self.opts.scripts:
self.run_scripts(self.opts.scripts)
try: try:
await super().run() await super().run()
finally: finally: