Skip to content

Commit

Permalink
Move generic functions to wv_helper.py
Browse files Browse the repository at this point in the history
  • Loading branch information
formatc1702 committed Nov 1, 2020
1 parent 0e84768 commit cf2db16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/wireviz/wv_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
4 changes: 1 addition & 3 deletions src/wireviz/wv_gv_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] [^>]*>([^<]*)</[aA]>', r'\1', inp) if isinstance(inp, str) else inp

def html_line_breaks(inp):
return remove_links(inp).replace('\n', '<br />') if isinstance(inp, str) else inp
11 changes: 9 additions & 2 deletions src/wireviz/wv_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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] [^>]*>([^<]*)</[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')
Expand Down

0 comments on commit cf2db16

Please sign in to comment.