From 4309ec592c4631cd688971dcf477e95a532aede3 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Thu, 9 Jul 2020 23:00:11 +0200 Subject: [PATCH] Move expand() function to wv_helper.py --- src/wireviz/wireviz.py | 29 +---------------------------- src/wireviz/wv_helper.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index 6307ccae..d2b823ce 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -13,6 +13,7 @@ from wireviz.Harness import Harness +from wireviz.wv_helper import expand def parse(yaml_input, file_out=None, generate_bom=False, return_types: (None, str, Tuple[str]) = None): @@ -31,34 +32,6 @@ def parse(yaml_input, file_out=None, generate_bom=False, return_types: (None, st yaml_data = yaml.safe_load(yaml_input) - def expand(yaml_data): - # yaml_data can be: - # - a singleton (normally str or int) - # - a list of str or int - # if str is of the format '#-#', it is treated as a range (inclusive) and expanded - output = [] - if not isinstance(yaml_data, list): - yaml_data = [yaml_data] - for e in yaml_data: - e = str(e) - if '-' in e: # list of pins - a, b = tuple(map(int, e.split('-'))) - if a < b: - for x in range(a, b + 1): - output.append(x) - elif a > b: - for x in range(a, b - 1, -1): - output.append(x) - elif a == b: - output.append(a) - else: - try: - x = int(e) - except Exception: - x = e - output.append(x) - return output - harness = Harness() # add items diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 83ee46ee..9c19a5e4 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -59,6 +59,35 @@ def nested_html_table(rows): return html +def expand(yaml_data): + # yaml_data can be: + # - a singleton (normally str or int) + # - a list of str or int + # if str is of the format '#-#', it is treated as a range (inclusive) and expanded + output = [] + if not isinstance(yaml_data, list): + yaml_data = [yaml_data] + for e in yaml_data: + e = str(e) + if '-' in e: # list of pins + a, b = tuple(map(int, e.split('-'))) + if a < b: + for x in range(a, b + 1): + output.append(x) + elif a > b: + for x in range(a, b - 1, -1): + output.append(x) + elif a == b: + output.append(a) + else: + try: + x = int(e) + except Exception: + x = e + output.append(x) + return output + + def int2tuple(inp): if isinstance(inp, tuple): output = inp