def test_load_maps_finds_all_maps(mapped_doubler): mapped_doubler.map(range(1)) mapped_doubler.map(range(1)) mapped_doubler.map(range(1)) results = htmap.load_maps() assert len(results) == 3
def status(state, meta, format, live, color): """ Print a status table for all of your maps. Transient maps are prefixed with a leading "*". """ if format != "text" and live: click.echo("ERROR: cannot produce non-text live data.", err=True) sys.exit(1) maps = sorted( (_cli_load(tag) for tag in htmap.get_tags()), key=lambda m: (m.is_transient, m.tag), ) for map in maps: if state: with make_spinner( text=f"Reading component statuses for map {map.tag}..."): map.component_statuses if meta: with make_spinner( text=f"Determining local data usage for map {map.tag}..."): map.local_data shared_kwargs = dict( include_state=state, include_meta=meta, ) if format == "json": msg = htmap.status_json(maps, **shared_kwargs) elif format == "json_compact": msg = htmap.status_json(maps, **shared_kwargs, compact=True) elif format == "csv": msg = htmap.status_csv(maps, **shared_kwargs) elif format == "text": msg = _status( maps, **shared_kwargs, header_fmt=_HEADER_FMT if color else None, row_fmt=_RowFmt(maps) if color else None, ) else: # pragma: unreachable # this is a safeguard; this code is actually unreachable, because # click detects the invalid choice before we hit this click.echo(f'ERROR: unknown format option "{format}"', err=True) sys.exit(2) click.echo(msg) try: while live: prev_lines = list(msg.splitlines()) prev_len_lines = [len(line) for line in prev_lines] maps = sorted(htmap.load_maps(), key=lambda m: (m.is_transient, m.tag)) msg = _status( maps, **shared_kwargs, header_fmt=_HEADER_FMT if color else None, row_fmt=_RowFmt(maps) if color else None, # don't cache, must pass fresh each time ) move = f"\033[{len(prev_len_lines)}A\r" clear = "\n".join(" " * len(click.unstyle(line)) for line in prev_lines) + "\n" sys.stdout.write(move + clear + move) click.echo(msg) time.sleep(1) except KeyboardInterrupt: # bypass click's interrupt handling and let it exit quietly return
def status(no_state, no_meta, format, live, no_color): """ Print the status of all maps. Transient maps are prefixed with a * """ if format != 'text' and live: click.echo('ERROR: cannot produce non-text live data.', err=True) sys.exit(1) maps = sorted((_cli_load(tag) for tag in htmap.get_tags()), key=lambda m: (m.is_transient, m.tag)) if not no_state: with make_spinner(text='Reading map component statuses...'): read_events(maps) shared_kwargs = dict( include_state=not no_state, include_meta=not no_meta, ) if format == 'json': msg = htmap.status_json(maps, **shared_kwargs) elif format == 'json_compact': msg = htmap.status_json(maps, **shared_kwargs, compact=True) elif format == 'csv': msg = htmap.status_csv(maps, **shared_kwargs) elif format == 'text': msg = _status( maps, **shared_kwargs, header_fmt=_HEADER_FMT if not no_color else None, row_fmt=_RowFmt(maps) if not no_color else None, ) else: click.echo(f'ERROR: unknown format option "{format}"', err=True) sys.exit(1) click.echo(msg) try: while live: prev_len_lines = [len(line) for line in msg.splitlines()] maps = sorted(htmap.load_maps(), key=lambda m: (m.is_transient, m.tag)) msg = _status( maps, **shared_kwargs, header_fmt=_HEADER_FMT if not no_color else None, row_fmt=_RowFmt(maps) if not no_color else None, # don't cache, must pass fresh each time ) move = f'\033[{len(prev_len_lines)}A\r' clear = '\n'.join(' ' * l for l in prev_len_lines) + '\n' sys.stdout.write(move + clear + move) click.echo(msg) time.sleep(1) except KeyboardInterrupt: # bypass click's interrupt handling and let it exit quietly return