Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 1, 2024
1 parent cce05ef commit 3af74fa
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions WrightTools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,23 @@ def tree(path, internal_path, depth=9, verbose=False):
@click.argument("path")
def load(path):
import code

# def raise_sys_exit():
# raise SystemExit
shell = code.InteractiveConsole() # locals={"exit": raise_sys_exit, "quit": raise_sys_exit})
shell = code.InteractiveConsole() # locals={"exit": raise_sys_exit, "quit": raise_sys_exit})
_interact(shell, path)


@cli.command(name="crawl", help="Crawl a directory and survey the wt5 objects found.")
@click.option("--directory", "-d", default=None, help="Directory to crawl. Defaults to current directory.")
@click.option(
"--directory", "-d", default=None, help="Directory to crawl. Defaults to current directory."
)
@click.option("--recursive", "-r", is_flag=True, help="Explore all levels of the directory")
@click.option("--format", "-f", default=None, help="Formatting keys (default only atm)")
# TODO: write output as an option; format kwarg?
def crawl(directory=None, recursive=False, format=None):
import glob, os, code

# from rich.console import Console
from rich.live import Live
from rich.table import Table
Expand All @@ -72,12 +76,22 @@ def _parse_entry(i, relpath):
nvars = len(wt5.variables)
nchan = len(wt5.channels)
elif isinstance(wt5, wt.Collection):
shape = axes = nvars = nchan = "---"
shape = axes = nvars = nchan = "---"
return [
str(i), relpath, f"{size:0.1f}", created, name, str(shape), str(axes), str(nvars), str(nchan)
str(i),
relpath,
f"{size:0.1f}",
created,
name,
str(shape),
str(axes),
str(nvars),
str(nchan),
]

table = Table(title=directory + f" ({len(paths)} wt5 file{'s' if len(paths) != 1 else None} found)")
table = Table(
title=directory + f" ({len(paths)} wt5 file{'s' if len(paths) != 1 else None} found)"
)
table.add_column("", justify="right") # index
table.add_column("path", max_width=60, no_wrap=True)
table.add_column("size (MB)", justify="center")
Expand All @@ -92,15 +106,17 @@ def _parse_entry(i, relpath):
for i, path in enumerate(paths):
table.add_row(*_parse_entry(i, path))
live.update(table)

# give option to interact
shell = code.InteractiveConsole()
msg = shell.raw_input("Do you wish to load an entry? (specify an index to load, or don't and exit) ")
msg = shell.raw_input(
"Do you wish to load an entry? (specify an index to load, or don't and exit) "
)
try:
valid = 0 < int(msg) + 1 < len(paths)
except ValueError:
print("invalid index")
return
return
if valid:
_interact(shell, os.path.join(directory, paths[int(msg)]))

Expand Down

0 comments on commit 3af74fa

Please sign in to comment.