|
6 | 6 | from rich.table import Table |
7 | 7 |
|
8 | 8 | import waveform_editor |
| 9 | +from waveform_editor.waveform_exporter import WaveformExporter |
| 10 | +from waveform_editor.yaml_parser import YamlParser |
9 | 11 |
|
10 | 12 | logger = logging.getLogger(__name__) |
11 | 13 |
|
@@ -52,5 +54,52 @@ def print_version(): |
52 | 54 | console.Console().print(grid) |
53 | 55 |
|
54 | 56 |
|
| 57 | +@cli.command("export-csv") |
| 58 | +@click.argument("yaml", type=click.Path(exists=True)) |
| 59 | +@click.argument("output", type=str) |
| 60 | +def export_csv(yaml, output): |
| 61 | + """Export waveform data to a CSV file.""" |
| 62 | + waveform = load_waveform_from_yaml(yaml) |
| 63 | + exporter = WaveformExporter(waveform) |
| 64 | + exporter.to_csv(output) |
| 65 | + |
| 66 | + |
| 67 | +@cli.command("export-png") |
| 68 | +@click.argument("yaml", type=click.Path(exists=True)) |
| 69 | +@click.argument("output", type=str) |
| 70 | +def export_png(yaml, output): |
| 71 | + """Export waveform data to a CSV file.""" |
| 72 | + waveform = load_waveform_from_yaml(yaml) |
| 73 | + exporter = WaveformExporter(waveform) |
| 74 | + exporter.to_png(output) |
| 75 | + |
| 76 | + |
| 77 | +# # TODO: |
| 78 | +# @cli.command("export-ids") |
| 79 | +# @click.argument("yaml", type=str) |
| 80 | +# @click.argument("uri", type=str) |
| 81 | +# @click.option("--dd-version", type=str) |
| 82 | +# def export_ids(yaml, uri, path): |
| 83 | +# """Export waveform data to an IDS.""" |
| 84 | +# # waveform = load_waveform_from_yaml(yaml) |
| 85 | +# # exporter = WaveformExporter(waveform) |
| 86 | +# # exporter.to_ids(uri, path) |
| 87 | + |
| 88 | + |
| 89 | +def load_waveform_from_yaml(yaml_file): |
| 90 | + with open(yaml_file) as file: |
| 91 | + yaml_str = file.read() |
| 92 | + yaml_parser = YamlParser() |
| 93 | + yaml_parser.parse_waveforms(yaml_str) |
| 94 | + annotations = yaml_parser.waveform.annotations |
| 95 | + if annotations: |
| 96 | + click.secho( |
| 97 | + "The following errors and warnings were detected in the YAML file:\n" |
| 98 | + f"{annotations}", |
| 99 | + fg="red", |
| 100 | + ) |
| 101 | + return yaml_parser.waveform |
| 102 | + |
| 103 | + |
55 | 104 | if __name__ == "__main__": |
56 | 105 | cli() |
0 commit comments