From 06d7f040323b14612684befe6328d57002e84405 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Wed, 7 Dec 2022 14:55:49 +1300 Subject: [PATCH] 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? --- console_conf/cmd/tui.py | 11 ------- subiquity/cmd/tui.py | 11 ------- subiquitycore/tui.py | 66 ----------------------------------------- 3 files changed, 88 deletions(-) diff --git a/console_conf/cmd/tui.py b/console_conf/cmd/tui.py index 00d6805a..649c3b26 100755 --- a/console_conf/cmd/tui.py +++ b/console_conf/cmd/tui.py @@ -24,11 +24,6 @@ from subiquitycore import __version__ as VERSION 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): parser = argparse.ArgumentParser( description=( @@ -49,12 +44,6 @@ def parse_options(argv): help="Don't Probe. Use probe data file") 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') parser.add_argument('--recovery-chooser-mode', action='store_true', dest='chooser_systems', diff --git a/subiquity/cmd/tui.py b/subiquity/cmd/tui.py index d62271d8..947fe3f7 100755 --- a/subiquity/cmd/tui.py +++ b/subiquity/cmd/tui.py @@ -31,11 +31,6 @@ from .common import ( 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(): parser = argparse.ArgumentParser( description='Subiquity - Ubiquity for Servers', @@ -63,12 +58,6 @@ def make_client_args_parser(): help='Run the installer in unicode 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') parser.add_argument('--server-pid') parser.add_argument('--output-base', action='store', dest='output_base', diff --git a/subiquitycore/tui.py b/subiquitycore/tui.py index cec7d94b..7a433fde 100644 --- a/subiquitycore/tui.py +++ b/subiquitycore/tui.py @@ -254,70 +254,6 @@ class TuiApplication(Application): def select_initial_screen(self): 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): if rich == self.rich_mode: return @@ -374,8 +310,6 @@ class TuiApplication(Application): self.start_urwid() async def run(self): - if self.opts.scripts: - self.run_scripts(self.opts.scripts) try: await super().run() finally: