Find arrows with RegEx
This commit is contained in:
parent
37cedb960e
commit
2c78e46c77
@ -357,7 +357,7 @@ class Harness:
|
|||||||
elif mate.shape[-1] == '>':
|
elif mate.shape[-1] == '>':
|
||||||
dir = 'forward'
|
dir = 'forward'
|
||||||
else:
|
else:
|
||||||
dir = 'none' # should not happen?
|
dir = 'none' # should not happen
|
||||||
|
|
||||||
if isinstance(mate, MatePin):
|
if isinstance(mate, MatePin):
|
||||||
color = '#000000'
|
color = '#000000'
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import os
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, Tuple
|
from typing import Any, Tuple
|
||||||
|
import re
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
from wireviz import __version__
|
from wireviz import __version__
|
||||||
from wireviz.Harness import Harness
|
from wireviz.Harness import Harness
|
||||||
from wireviz.wv_helper import expand, open_file_read
|
from wireviz.wv_helper import expand, open_file_read, isarrow
|
||||||
|
|
||||||
|
|
||||||
def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, str, Tuple[str]) = None) -> Any:
|
def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, str, Tuple[str]) = None) -> Any:
|
||||||
@ -97,8 +98,6 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st
|
|||||||
designators_and_templates[designator] = template
|
designators_and_templates[designator] = template
|
||||||
return (template, designator)
|
return (template, designator)
|
||||||
|
|
||||||
arrows = ['<--','<->','-->','<==','<=>','==>']
|
|
||||||
|
|
||||||
connection_sets = yaml_data['connections']
|
connection_sets = yaml_data['connections']
|
||||||
for connection_set in connection_sets:
|
for connection_set in connection_sets:
|
||||||
print('')
|
print('')
|
||||||
@ -186,7 +185,7 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st
|
|||||||
print(' ', designator, 'is a new cable instance of type', template)
|
print(' ', designator, 'is a new cable instance of type', template)
|
||||||
harness.add_cable(name = designator, **template_cables[template])
|
harness.add_cable(name = designator, **template_cables[template])
|
||||||
|
|
||||||
elif designator in arrows:
|
elif isarrow(designator):
|
||||||
print(f' {template} is an arrow')
|
print(f' {template} is an arrow')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -221,7 +220,7 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st
|
|||||||
to_pin = connection_set[index_entry][index_item+1][to_name]
|
to_pin = connection_set[index_entry][index_item+1][to_name]
|
||||||
print(' > connect ', from_name, from_pin, via_name, via_pin, to_name, to_pin)
|
print(' > connect ', from_name, from_pin, via_name, via_pin, to_name, to_pin)
|
||||||
harness.connect(from_name, from_pin, via_name, via_pin, to_name, to_pin)
|
harness.connect(from_name, from_pin, via_name, via_pin, to_name, to_pin)
|
||||||
elif designator in arrows:
|
elif isarrow(designator):
|
||||||
print(f' - {designator} is an arrow')
|
print(f' - {designator} is an arrow')
|
||||||
if index_item == 0: # list startess with an arrow
|
if index_item == 0: # list startess with an arrow
|
||||||
raise Exception('An arrow cannot be at the start of a connection set')
|
raise Exception('An arrow cannot be at the start of a connection set')
|
||||||
@ -240,8 +239,6 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st
|
|||||||
elif '=' in designator and index_entry == 0: # mate two connectors as a whole
|
elif '=' in designator and index_entry == 0: # mate two connectors as a whole
|
||||||
print(f' Mate {from_name} {designator} {to_name} ({index_entry})')
|
print(f' Mate {from_name} {designator} {to_name} ({index_entry})')
|
||||||
harness.add_mate_component(from_name, to_name, designator)
|
harness.add_mate_component(from_name, to_name, designator)
|
||||||
elif '=' in designator: # mate connectors as a whole
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if "additional_bom_items" in yaml_data:
|
if "additional_bom_items" in yaml_data:
|
||||||
|
|||||||
@ -106,6 +106,17 @@ def open_file_write(filename):
|
|||||||
def open_file_append(filename):
|
def open_file_append(filename):
|
||||||
return open(filename, 'a', encoding='UTF-8')
|
return open(filename, 'a', encoding='UTF-8')
|
||||||
|
|
||||||
|
def isarrow(inp):
|
||||||
|
"""
|
||||||
|
Matches strings of one or multiple `-` or `=` (TODO: but not mixed)
|
||||||
|
optionally starting with `<` and/or ending with `>`.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
<-, --, ->, <->
|
||||||
|
<==, ==, ==>, <=>
|
||||||
|
"""
|
||||||
|
return bool(re.match(r"^<?[=-]+>?$", inp))
|
||||||
|
|
||||||
def aspect_ratio(image_src):
|
def aspect_ratio(image_src):
|
||||||
try:
|
try:
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user