def run(self, project): """Simulate subject to the parameters specified in the given project. """ sq.echo(f"Running {project.name!r}...") project.run() sq.echo(f"Project {project.name!r} finished.")
def execute(command): try: cmd = getattr(EXAMPLE_MODULE_MAP[command], command) except AttributeError: sq.echo(f"Example {command!r} not recognized.") return cmd()
def timer_sleep(interval, i=None, n=None): if None not in (i, n): msg = f"{i+1}/{n} " else: msg = "" msg += f"Sleeping {interval} seconds..." sq.echo(msg) time.sleep(interval)
def run(self, interval, n): """Count at the given interval the given number of times. Positional arguments: interval - (int) Interval, in seconds. n - (int) Number of times to count the given interval. """ self.interval = interval timer_sleep_all(interval, n) sq.echo(f"Slept {interval * n} seconds total.")
def print_help(): sq.echo(f"Usage: python -m examples [OPTIONS] COMMAND [ARGS]...\n") sq.echo("Options:") for opts, desc in OPTIONS: sq.echo(f" {', '.join(opts)} {desc}") sq.echo() sq.echo("Commands:") max_modname_len = max(len(mod) for mod in EXAMPLE_MODULE_MAP) for cmd, descr in zip(EXAMPLE_MODULE_MAP.keys(), EXAMPLE_MODULE_DESCRIPTIONS): sq.echo(f" {cmd:<{max_modname_len+2}}{descr}")
def view_queue(): sq.echo(tabulate_task_items(max_entries=5))
def run(self): n = 4 for i in range(n): msg = f"{i+1}/{n} Simulation step" sq.echo(msg) time.sleep(2)
def view_work(): sq.echo(pprint.pformat(list(sq.work_items(max_entries=5))))