Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/techui_builder/generate_jsonmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ class JsonMap:
class JsonMapGenerator:
bob_path: Path = field(default=Path("index.bob"))
techui: Path = field(default=Path("techui.yaml"))
output: Path | None = field(default=None)

def __post_init__(self):
# Get the directory to that holds the bob file and techui_yaml,
self._write_directory: Path = self.bob_path.parent
# Determine the directory to write the json map file to.
# By default, this looks at the location of the bob file, but can
# be overwritten using the --output flag
self._write_directory: Path = (
self.output if self.output is not None else self.bob_path.parent
)
# Check if techui is default value and that it doesn't exist
if (
self.techui == self.__class__.__dataclass_fields__["techui"].default
Expand Down Expand Up @@ -474,6 +479,14 @@ def generate_jsonmap(
Path,
typer.Argument(help="Top level bobfile to generate json mapping from."),
],
output_path: Annotated[
Path | None,
typer.Option(
"--output",
"-o",
help="Alternative output location for generated json map file.",
),
] = None,
loglevel: Annotated[
str,
typer.Option(
Expand All @@ -486,7 +499,9 @@ def generate_jsonmap(
] = "INFO",
) -> None:
"""Default function called from cmd line tool."""
jg = JsonMapGenerator(bob_path=bob_path)
if output_path is not None:
logger_.info(f"Using user provided output location of: {output_path}")
jg = JsonMapGenerator(bob_path=bob_path, output=output_path)
jg.write_json_map()
logger_.info(
f"Json map generated for {jg.techui_yaml.beamline.location} (from index.bob)"
Expand Down
18 changes: 16 additions & 2 deletions src/techui_builder/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@
class GenerateStatusPvs:
techui_path: Path = field(repr=False)
status_pvs: dict[str, Record] = field(default_factory=dict, init=False)
output: Path | None = field(default=None)

def __post_init__(self):
self._write_directory = self.techui_path.parent
# Determine the directory to write the json map file to.
# By default, this looks at the location of the techui file, but can
# be overwritten using the --output flag
self._write_directory: Path = (
self.output if self.output is not None else self.techui_path.parent
)

try:
self.techui_yaml: TechUi = TechUi.model_validate(
Expand Down Expand Up @@ -89,8 +95,16 @@ def write_status_pvs(self):
@app.callback(invoke_without_command=True)
def status_run(
techui: Annotated[Path, typer.Argument(help="The path to techui.yaml")],
output_path: Annotated[
Path | None,
typer.Option(
"--output",
"-o",
help="Alternative output location for generated status db file.",
),
] = None,
):
status_gen = GenerateStatusPvs(techui)
status_gen = GenerateStatusPvs(techui, output=output_path)
for component in status_gen.techui_yaml.components.values():
if component.status is not None:
# if a status field is provided, generate a status PV for the component
Expand Down