diff --git a/src/techui_builder/generate_jsonmap.py b/src/techui_builder/generate_jsonmap.py index 65ca1ea4..40b20c6c 100644 --- a/src/techui_builder/generate_jsonmap.py +++ b/src/techui_builder/generate_jsonmap.py @@ -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 @@ -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( @@ -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)" diff --git a/src/techui_builder/status.py b/src/techui_builder/status.py index a8f186fa..4847673e 100644 --- a/src/techui_builder/status.py +++ b/src/techui_builder/status.py @@ -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( @@ -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