From bf2792da802e96add2e230b2022b34c63afff567 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 1 Nov 2020 15:10:08 +0100 Subject: [PATCH] Move generic functions to `wv_helper.py` --- src/wireviz/wv_bom.py | 4 +--- src/wireviz/wv_gv_html.py | 4 +--- src/wireviz/wv_helper.py | 11 +++++++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index 9d01cba4..a854ac86 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -6,6 +6,7 @@ from wireviz.DataClasses import Connector, Cable from wireviz.wv_gv_html import html_line_breaks +from wireviz.wv_helper import clean_whitespace def get_additional_component_table(harness, component: Union[Connector, Cable]) -> List[str]: rows = [] @@ -172,9 +173,6 @@ def manufacturer_info_field(manufacturer, mpn): else: return None -def clean_whitespace(inp): - return ' '.join(inp.split()).replace(' ,', ',') if isinstance(inp, str) else inp - # Return the value indexed if it is a list, or simply the value otherwise. def index_if_list(value, index): return value[index] if isinstance(value, list) else value diff --git a/src/wireviz/wv_gv_html.py b/src/wireviz/wv_gv_html.py index 35c07f20..ee5b2e28 100644 --- a/src/wireviz/wv_gv_html.py +++ b/src/wireviz/wv_gv_html.py @@ -5,6 +5,7 @@ import re from wireviz.wv_colors import translate_color +from wireviz.wv_helper import remove_links def nested_html_table(rows): # input: list, each item may be scalar or list @@ -61,8 +62,5 @@ def html_size_attr(image): + (f' height="{image.height}"' if image.height else '') + ( ' fixedsize="true"' if image.fixedsize else '')) if image else '' -def remove_links(inp): - return re.sub(r'<[aA] [^>]*>([^<]*)', r'\1', inp) if isinstance(inp, str) else inp - def html_line_breaks(inp): return remove_links(inp).replace('\n', '
') if isinstance(inp, str) else inp diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 9e9e0a38..ffc4bd84 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -4,8 +4,6 @@ from typing import List import re -from wireviz.wv_gv_html import remove_links - awg_equiv_table = { '0.09': '28', '0.14': '26', @@ -89,6 +87,15 @@ def tuplelist2tsv(inp, header=None): output = output + '\t'.join(str(remove_links(item)) for item in row) + '\n' return output + +def remove_links(inp): + return re.sub(r'<[aA] [^>]*>([^<]*)', r'\1', inp) if isinstance(inp, str) else inp + + +def clean_whitespace(inp): + return ' '.join(inp.split()).replace(' ,', ',') if isinstance(inp, str) else inp + + def open_file_read(filename): # TODO: Intelligently determine encoding return open(filename, 'r', encoding='UTF-8')