Skip to content

Commit

Permalink
Remove _produce and update Device convert
Browse files Browse the repository at this point in the history
- Remove submodules for now unused dbd definitions
- Remove source convert
- Pull still needed functionality into _asyn_convert and _parameters
- Simplify _template_convert
- Update __main__
- Update test to use tempalte name for group name instead of placeholder
  • Loading branch information
GDYendell committed Jul 14, 2023
1 parent 262bbf1 commit 308cb97
Show file tree
Hide file tree
Showing 17 changed files with 323 additions and 1,573 deletions.
120 changes: 4 additions & 116 deletions src/pvi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
import typer

from pvi import __version__
from pvi._convert._source_convert import SourceConverter
from pvi._convert._template_convert import TemplateConverter
from pvi._convert.utils import extract_device_and_parent_class
from pvi._format import Formatter
from pvi._produce import Producer
from pvi._produce.asyn import AsynParameter, AsynProducer
from pvi._pv_group import group_parameters
from pvi._schema_utils import make_json_schema
from pvi._yaml_utils import deserialize_yaml, serialize_yaml
from pvi.device import Device, walk
from pvi.device import Device

app = typer.Typer()
convert_app = typer.Typer()
Expand Down Expand Up @@ -50,8 +47,6 @@ def schema(output: Path = typer.Argument(..., help="filename to write the schema
), f"Expected '{output.name}' to end with '.schema.json'"
if output.name == "pvi.device.schema.json":
cls = Device
elif output.name == "pvi.producer.schema.json":
cls = Producer
elif output.name == "pvi.formatter.schema.json":
cls = Formatter
else:
Expand All @@ -61,27 +56,6 @@ def schema(output: Path = typer.Argument(..., help="filename to write the schema
output.write_text(json.dumps(schema, indent=2))


@app.command()
def produce(
output: Path = typer.Argument(..., help="filename to write the product to"),
producer: Path = typer.Argument(..., help="path to the producer .pvi.yaml file"),
yaml_paths: List[Path] = typer.Option(
[], "--yaml-path", help="Paths to directories with .pvi.producer.yaml files"
),
):
"""Create template/csv/device/other product from producer YAML"""
producer_inst = deserialize_yaml(Producer, producer)
if output.suffix == ".template":
producer_inst.produce_records(output)
elif output.suffix == ".csv":
producer_inst.produce_csv(output)
elif output.suffixes == [".pvi", ".device", ".yaml"]:
device = producer_inst.produce_device()
serialize_yaml(device, output)
else:
producer_inst.produce_other(output, yaml_paths)


@app.command()
def format(
output_path: Path = typer.Argument(
Expand All @@ -103,68 +77,6 @@ def format(
formatter_inst.format(device, "$(P)$(R)", output_path)


@convert_app.command()
def asyn(
output: Path = typer.Argument(..., help="Directory to write output file(s) to"),
cpp: Path = typer.Argument(..., help="Path to the .cpp file to convert"),
h: Path = typer.Argument(..., help="Path to the .h file to convert"),
templates: List[Path] = typer.Option(
[], help="Paths to .template files to convert"
),
yaml_paths: List[Path] = typer.Option(
[], "--yaml-path", help="Paths to directories with .pvi.producer.yaml files"
),
):
"""Convert cpp/h/template to producer YAML and stripped cpp/h/template"""
if not output.exists():
os.mkdir(output)

# if a template is given, convert it and populate drv_infos
template_converter: Optional[TemplateConverter] = None
if templates:
template_converter = TemplateConverter(templates)

# Generate initial yaml to provide parameter info strings to source converter
producer = template_converter.convert()
drv_infos = [
parameter.get_drv_info()
for parameter in walk(producer.parameters)
if isinstance(parameter, AsynParameter)
]
else:
producer = AsynProducer(label=h.stem)
drv_infos = []

source_converter = SourceConverter(cpp, h, yaml_paths, drv_infos)

if template_converter is not None:
# Process and recreate template files - pass source device for param set include
extracted_templates = template_converter.top_level_text(
source_converter.device_class
)
for template_text, template_path in zip(extracted_templates, templates):
(output / template_path.name).write_text(template_text)

# Process and recreate source files
extracted_source = source_converter.get_top_level_text()
(output / cpp.name).write_text(extracted_source.cpp)
(output / h.name).write_text(extracted_source.h)

# Update yaml based on source file definitions and write
producer.parent = source_converter.parent_class
if source_converter.define_strings:
index_map = source_converter.get_info_index_map()
for parameter in walk(producer.parameters):
if isinstance(parameter, AsynParameter):
parameter.index_name = index_map.get(
parameter.get_drv_info(), "INPUT MANUALLY"
)

serialize_yaml(
producer, output / f"{source_converter.device_class}.pvi.producer.yaml"
)


@convert_app.command()
def device(
output: Path = typer.Argument(..., help="Directory to write output file to"),
Expand All @@ -177,37 +89,13 @@ def device(
if not output.exists():
os.mkdir(output)

if templates:
asyn_producer = TemplateConverter(templates).convert()
else:
asyn_producer = AsynProducer(label=h.stem)
name, parent = extract_device_and_parent_class(h.read_text())
component_group = TemplateConverter(templates).convert()
device = Device(name, parent, component_group)

name, asyn_producer.parent = extract_device_and_parent_class(h.read_text())
device = asyn_producer.produce_device()
serialize_yaml(device, output / f"{name}.pvi.device.yaml")


@app.command()
def convertplaceholder(
output: Path = typer.Argument(..., help="Directory to write output file(s) to"),
cpp: Path = typer.Argument(..., help="Path to the .cpp file to convert"),
h: Path = typer.Argument(..., help="Path to the .h file to convert"),
yaml_paths: List[Path] = typer.Option(
[], "--yaml-path", help="Paths to directories with .pvi.producer.yaml files"
),
):
"""Alter cpp and h files of unconverted drivers"""
if not output.exists():
os.mkdir(output)

drv_infos: List[str] = []
source_converter = SourceConverter(cpp, h, yaml_paths, drv_infos)
extracted_source = source_converter.get_top_level_placeholder()

(output / cpp.name).write_text(extracted_source.cpp)
(output / h.name).write_text(extracted_source.h)


@app.command()
def regroup(
device_path: Path = typer.Argument(
Expand Down
Loading

0 comments on commit 308cb97

Please sign in to comment.