Merge branch 'dev' of https://github.com/formatc1702/WireViz into dev
# Conflicts: # src/wireviz/build_examples.py # src/wireviz/wv_helper.py
This commit is contained in:
commit
448c4e6bdc
@ -11,8 +11,8 @@ from wireviz import wv_colors
|
||||
class Connector:
|
||||
name: str
|
||||
manufacturer: Optional[str] = None
|
||||
manufacturer_part_number: Optional[str] = None
|
||||
internal_part_number: Optional[str] = None
|
||||
mpn: Optional[str] = None
|
||||
pn: Optional[str] = None
|
||||
style: Optional[str] = None
|
||||
category: Optional[str] = None
|
||||
type: Optional[str] = None
|
||||
@ -80,8 +80,8 @@ class Connector:
|
||||
class Cable:
|
||||
name: str
|
||||
manufacturer: Optional[Union[str, List[str]]] = None
|
||||
manufacturer_part_number: Optional[Union[str, List[str]]] = None
|
||||
internal_part_number: Optional[Union[str, List[str]]] = None
|
||||
mpn: Optional[Union[str, List[str]]] = None
|
||||
pn: Optional[Union[str, List[str]]] = None
|
||||
category: Optional[str] = None
|
||||
type: Optional[str] = None
|
||||
gauge: Optional[float] = None
|
||||
@ -140,7 +140,7 @@ class Cable:
|
||||
self.wirecount = len(self.colors)
|
||||
|
||||
# if lists of part numbers are provided check this is a bundle and that it matches the wirecount.
|
||||
for idfield in [self.manufacturer, self.manufacturer_part_number, self.internal_part_number]:
|
||||
for idfield in [self.manufacturer, self.mpn, self.pn]:
|
||||
if isinstance(idfield, list):
|
||||
if self.category == "bundle":
|
||||
# check the length
|
||||
|
||||
@ -7,7 +7,8 @@ from wireviz import wv_colors, wv_helper, bom_helper
|
||||
from wireviz.wv_colors import get_color_hex
|
||||
from wireviz.wv_helper import awg_equiv, mm2_equiv, \
|
||||
nested_html_table, flatten2d, index_if_list, html_line_breaks, \
|
||||
graphviz_line_breaks, remove_line_breaks, open_file_read, open_file_write
|
||||
graphviz_line_breaks, remove_line_breaks, open_file_read, open_file_write, \
|
||||
manufacturer_info_field
|
||||
from collections import Counter
|
||||
from typing import List
|
||||
from pathlib import Path
|
||||
@ -88,9 +89,8 @@ class Harness:
|
||||
for key, connector in self.connectors.items():
|
||||
|
||||
rows = [[connector.name if connector.show_name else None],
|
||||
[connector.manufacturer,
|
||||
f'MPN: {connector.manufacturer_part_number}' if connector.manufacturer_part_number else None,
|
||||
f'IPN: {connector.internal_part_number}' if connector.internal_part_number else None],
|
||||
[f'P/N: {connector.pn}' if connector.pn else None,
|
||||
manufacturer_info_field(connector.manufacturer, connector.mpn)],
|
||||
[html_line_breaks(connector.type),
|
||||
html_line_breaks(connector.subtype),
|
||||
f'{connector.pincount}-pin' if connector.show_pincount else None,
|
||||
@ -139,6 +139,10 @@ class Harness:
|
||||
dot.edge(f'{connector.name}:p{loop[0]}{loop_side}:{loop_dir}',
|
||||
f'{connector.name}:p{loop[1]}{loop_side}:{loop_dir}')
|
||||
|
||||
# determine if there are double- or triple-colored wires in the harness;
|
||||
# if so, pad single-color wires to make all wires of equal thickness
|
||||
pad = any(len(colorstr) > 2 for cable in self.cables.values() for colorstr in cable.colors)
|
||||
|
||||
for _, cable in self.cables.items():
|
||||
|
||||
awg_fmt = ''
|
||||
@ -151,9 +155,9 @@ class Harness:
|
||||
elif cable.gauge_unit.upper() == 'AWG':
|
||||
awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)'
|
||||
|
||||
identification = [cable.manufacturer if not isinstance(cable.manufacturer, list) else '',
|
||||
f'MPN: {cable.manufacturer_part_number}' if (cable.manufacturer_part_number and not isinstance(cable.manufacturer_part_number, list)) else '',
|
||||
f'IPN: {cable.internal_part_number}' if (cable.internal_part_number and not isinstance(cable.internal_part_number, list)) else '']
|
||||
identification = [f'P/N: {cable.pn}' if (cable.pn and not isinstance(cable.pn, list)) else '',
|
||||
manufacturer_info_field(cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
|
||||
cable.mpn if not isinstance(cable.mpn, list) else None)]
|
||||
identification = list(filter(None, identification))
|
||||
|
||||
attributes = [html_line_breaks(cable.type) if cable.type else '',
|
||||
@ -187,11 +191,6 @@ class Harness:
|
||||
|
||||
html = f'{html}<tr><td><table border="0" cellspacing="0" cellborder="0">' # conductor table
|
||||
|
||||
# determine if there are double- or triple-colored wires;
|
||||
# if so, pad single-color wires to make all wires of equal thickness
|
||||
colorlengths = list(map(len, cable.colors))
|
||||
pad = 4 in colorlengths or 6 in colorlengths
|
||||
|
||||
for i, connection_color in enumerate(cable.colors, 1):
|
||||
p = []
|
||||
p.append(f'<!-- {i}_in -->')
|
||||
@ -210,12 +209,12 @@ class Harness:
|
||||
if(cable.category == 'bundle'): # for bundles individual wires can have part information
|
||||
# create a list of wire parameters
|
||||
wireidentification = []
|
||||
if isinstance(cable.manufacturer, list):
|
||||
wireidentification.append(cable.manufacturer[i - 1])
|
||||
if isinstance(cable.manufacturer_part_number, list):
|
||||
wireidentification.append(f'MPN: {cable.manufacturer_part_number[i - 1]}')
|
||||
if isinstance(cable.internal_part_number, list):
|
||||
wireidentification.append(f'IPN: {cable.internal_part_number[i - 1]}')
|
||||
if isinstance(cable.pn, list):
|
||||
wireidentification.append(f'P/N: {cable.pn[i - 1]}')
|
||||
manufacturer_info = manufacturer_info_field(cable.manufacturer[i - 1] if isinstance(cable.manufacturer, list) else None,
|
||||
cable.mpn[i - 1] if isinstance(cable.mpn, list) else None)
|
||||
if manufacturer_info:
|
||||
wireidentification.append(manufacturer_info)
|
||||
# print parameters into a table row under the wire
|
||||
if(len(wireidentification) > 0):
|
||||
html = f'{html}<tr><td colspan="{len(p)}"><table border="0" cellspacing="0" cellborder="0"><tr>'
|
||||
@ -230,7 +229,14 @@ class Harness:
|
||||
for bla in p:
|
||||
html = html + f'<td>{bla}</td>'
|
||||
html = f'{html}</tr>'
|
||||
html = f'{html}<tr><td colspan="{len(p)}" cellpadding="0" height="6" border="2" sides="b" port="ws"></td></tr>'
|
||||
if isinstance(cable.shield, str):
|
||||
# shield is shown with specified color and black borders
|
||||
shield_color_hex = wv_colors.get_color_hex(cable.shield)[0]
|
||||
attributes = f'height="6" bgcolor="{shield_color_hex}" border="2" sides="tb"'
|
||||
else:
|
||||
# shield is shown as a thin black wire
|
||||
attributes = f'height="2" bgcolor="#000000" border="0"'
|
||||
html = f'{html}<tr><td colspan="{len(p)}" cellpadding="0" {attributes} port="ws"></td></tr>'
|
||||
|
||||
html = f'{html}<tr><td> </td></tr>' # spacer at the end
|
||||
|
||||
@ -248,8 +254,8 @@ class Harness:
|
||||
if isinstance(connection_color.via_port, int): # check if it's an actual wire and not a shield
|
||||
dot.attr('edge', color=':'.join(['#000000'] + wv_colors.get_color_hex(cable.colors[connection_color.via_port - 1], pad=pad) + ['#000000']))
|
||||
else: # it's a shield connection
|
||||
# shield is shown as a thin tinned wire
|
||||
dot.attr('edge', color=':'.join(['#000000', wv_colors.get_color_hex('SN', pad=False)[0], '#000000']))
|
||||
# shield is shown with specified color and black borders, or as a thin black wire otherwise
|
||||
dot.attr('edge', color=':'.join(['#000000', shield_color_hex, '#000000']) if isinstance(cable.shield, str) else '#000000')
|
||||
if connection_color.from_port is not None: # connect to left
|
||||
from_port = f':p{connection_color.from_port}r' if self.connectors[connection_color.from_name].style != 'simple' else ''
|
||||
code_left_1 = f'{connection_color.from_name}{from_port}:e'
|
||||
@ -372,7 +378,7 @@ class Harness:
|
||||
bom_cables = []
|
||||
bom_extra = []
|
||||
# connectors
|
||||
connector_group = lambda c: (c.type, c.subtype, c.pincount, c.manufacturer, c.manufacturer_part_number, c.internal_part_number)
|
||||
connector_group = lambda c: (c.type, c.subtype, c.pincount, c.manufacturer, c.mpn, c.pn)
|
||||
for group in Counter([connector_group(v) for v in self.connectors.values()]):
|
||||
items = {k: v for k, v in self.connectors.items() if connector_group(v) == group}
|
||||
shared = next(iter(items.values()))
|
||||
@ -384,14 +390,14 @@ class Harness:
|
||||
conn_color = f', {shared.color}' if shared.color else ''
|
||||
name = f'Connector{conn_type}{conn_subtype}{conn_pincount}{conn_color}'
|
||||
item = {'item': name, 'qty': len(designators), 'unit': '', 'designators': designators if shared.show_name else '',
|
||||
'manufacturer': shared.manufacturer, 'manufacturer part number': shared.manufacturer_part_number, 'internal part number': shared.internal_part_number}
|
||||
'manufacturer': shared.manufacturer, 'mpn': shared.mpn, 'pn': shared.pn}
|
||||
bom_connectors.append(item)
|
||||
bom_connectors = sorted(bom_connectors, key=lambda k: k['item']) # https://stackoverflow.com/a/73050
|
||||
bom.extend(bom_connectors)
|
||||
# cables
|
||||
# TODO: If category can have other non-empty values than 'bundle', maybe it should be part of item name?
|
||||
# The category needs to be included in cable_group to keep the bundles excluded.
|
||||
cable_group = lambda c: (c.category, c.type, c.gauge, c.gauge_unit, c.wirecount, c.shield, c.manufacturer, c.manufacturer_part_number, c.internal_part_number)
|
||||
cable_group = lambda c: (c.category, c.type, c.gauge, c.gauge_unit, c.wirecount, c.shield, c.manufacturer, c.mpn, c.pn)
|
||||
for group in Counter([cable_group(v) for v in self.cables.values() if v.category != 'bundle']):
|
||||
items = {k: v for k, v in self.cables.items() if cable_group(v) == group}
|
||||
shared = next(iter(items.values()))
|
||||
@ -403,7 +409,7 @@ class Harness:
|
||||
shield_name = ' shielded' if shared.shield else ''
|
||||
name = f'Cable{cable_type}, {shared.wirecount}{gauge_name}{shield_name}'
|
||||
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators,
|
||||
'manufacturer': shared.manufacturer, 'manufacturer part number': shared.manufacturer_part_number, 'internal part number': shared.internal_part_number}
|
||||
'manufacturer': shared.manufacturer, 'mpn': shared.mpn, 'pn': shared.pn}
|
||||
bom_cables.append(item)
|
||||
# bundles (ignores wirecount)
|
||||
wirelist = []
|
||||
@ -414,10 +420,10 @@ class Harness:
|
||||
for index, color in enumerate(bundle.colors, 0):
|
||||
wirelist.append({'type': bundle.type, 'gauge': bundle.gauge, 'gauge_unit': bundle.gauge_unit, 'length': bundle.length, 'color': color, 'designator': bundle.name,
|
||||
'manufacturer': index_if_list(bundle.manufacturer, index),
|
||||
'manufacturer part number': index_if_list(bundle.manufacturer_part_number, index),
|
||||
'internal part number': index_if_list(bundle.internal_part_number, index)})
|
||||
'mpn': index_if_list(bundle.mpn, index),
|
||||
'pn': index_if_list(bundle.pn, index)})
|
||||
# join similar wires from all the bundles to a single BOM item
|
||||
wire_group = lambda w: (w.get('type', None), w['gauge'], w['gauge_unit'], w['color'], w['manufacturer'], w['manufacturer part number'], w['internal part number'])
|
||||
wire_group = lambda w: (w.get('type', None), w['gauge'], w['gauge_unit'], w['color'], w['manufacturer'], w['mpn'], w['pn'])
|
||||
for group in Counter([wire_group(v) for v in wirelist]):
|
||||
items = [v for v in wirelist if wire_group(v) == group]
|
||||
shared = items[0]
|
||||
@ -430,7 +436,7 @@ class Harness:
|
||||
gauge_color = f', {shared["color"]}' if 'color' in shared != '' else ''
|
||||
name = f'Wire{wire_type}{gauge_name}{gauge_color}'
|
||||
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators,
|
||||
'manufacturer': shared['manufacturer'], 'manufacturer part number': shared['manufacturer part number'], 'internal part number': shared['internal part number']}
|
||||
'manufacturer': shared['manufacturer'], 'mpn': shared['mpn'], 'pn': shared['pn']}
|
||||
bom_cables.append(item)
|
||||
bom_cables = sorted(bom_cables, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050)
|
||||
bom.extend(bom_cables)
|
||||
@ -440,7 +446,7 @@ class Harness:
|
||||
if isinstance(item.get('designators', None), List):
|
||||
item['designators'].sort() # sort designators if a list is provided
|
||||
item = {'item': name, 'qty': item.get('qty', None), 'unit': item.get('unit', None), 'designators': item.get('designators', None),
|
||||
'manufacturer': item.get('manufacturer', None), 'manufacturer part number': item.get('manufacturer_part_number', None), 'internal part number': item.get('internal_part_number', None)}
|
||||
'manufacturer': item.get('manufacturer', None), 'mpn': item.get('mpn', None), 'pn': item.get('pn', None)}
|
||||
bom_extra.append(item)
|
||||
bom_extra = sorted(bom_extra, key=lambda k: k['item'])
|
||||
bom.extend(bom_extra)
|
||||
@ -449,11 +455,16 @@ class Harness:
|
||||
def _bom_list(self):
|
||||
bom = self._bom()
|
||||
keys = ['item', 'qty', 'unit', 'designators'] # these BOM columns will always be included
|
||||
for fieldname in ['manufacturer', 'manufacturer part number', 'internal part number']: # these optional BOM columns will only be included if at least one BOM item actually uses them
|
||||
for fieldname in ['pn', 'manufacturer', 'mpn']: # these optional BOM columns will only be included if at least one BOM item actually uses them
|
||||
if any(fieldname in x and x.get(fieldname, None) for x in bom):
|
||||
keys.append(fieldname)
|
||||
bom_list = []
|
||||
bom_list.append([k.capitalize() for k in keys]) # create header row with keys
|
||||
# list of staic bom header names, headers not specified here are generated by capitilising the internal name
|
||||
bom_headings = {
|
||||
"pn": "P/N",
|
||||
"mpn": "MPN"
|
||||
}
|
||||
bom_list.append([(bom_headings[k] if k in bom_headings else k.capitalize()) for k in keys]) # create header row with keys
|
||||
for item in bom:
|
||||
item_list = [item.get(key, '') for key in keys] # fill missing values with blanks
|
||||
item_list = [', '.join(subitem) if isinstance(subitem, List) else subitem for subitem in item_list] # convert any lists into comma separated strings
|
||||
|
||||
@ -1,124 +1,149 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from fnmatch import fnmatch
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
from wv_helper import open_file_write, open_file_read
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
script_path = Path(__file__).absolute()
|
||||
|
||||
sys.path.insert(0, str(script_path.parent.parent)) # to find wireviz module
|
||||
from wireviz import wireviz
|
||||
from wireviz.wv_helper import open_file_write, open_file_read, open_file_append
|
||||
|
||||
examples_path = Path('../../examples').absolute()
|
||||
tutorials_path = Path('../../tutorial').absolute()
|
||||
demos_path = examples_path
|
||||
|
||||
readme = 'readme.md'
|
||||
groups = {
|
||||
'examples': {
|
||||
'path': Path(script_path).parent.parent.parent / 'examples',
|
||||
'prefix': 'ex',
|
||||
readme: [], # Include no files
|
||||
'title': 'Example Gallery',
|
||||
},
|
||||
'tutorial' : {
|
||||
'path': Path(script_path).parent.parent.parent / 'tutorial',
|
||||
'prefix': 'tutorial',
|
||||
readme: ['md', 'yml'], # Include .md and .yml files
|
||||
'title': 'WireViz Tutorial',
|
||||
},
|
||||
'demos' : {
|
||||
'path': Path(script_path).parent.parent.parent / 'examples',
|
||||
'prefix': 'demo',
|
||||
},
|
||||
}
|
||||
|
||||
input_extensions = ['.yml']
|
||||
extensions_not_containing_graphviz_output = ['.gv', '.bom.tsv']
|
||||
extensions_containing_graphviz_output = ['.png', '.svg', '.html']
|
||||
generated_extensions = extensions_not_containing_graphviz_output + extensions_containing_graphviz_output
|
||||
|
||||
|
||||
def build_demos():
|
||||
for fn in sorted(os.listdir(demos_path)):
|
||||
if fnmatch(fn, "demo*.yml"):
|
||||
path = Path(os.path.join(demos_path, fn))
|
||||
|
||||
print(path)
|
||||
wireviz.main(path.absolute(), prepend=None, out=['png', 'svg', 'html', 'csv'])
|
||||
def collect_filenames(description, groupkey, ext_list):
|
||||
path = groups[groupkey]['path']
|
||||
patterns = [f"{groups[groupkey]['prefix']}*{ext}" for ext in ext_list]
|
||||
if ext_list != input_extensions and readme in groups[groupkey]:
|
||||
patterns.append(readme)
|
||||
print(f'{description} {groupkey} in "{path}"')
|
||||
return sorted([filename for pattern in patterns for filename in path.glob(pattern)])
|
||||
|
||||
|
||||
def build_examples():
|
||||
with open_file_write(examples_path / readme) as file:
|
||||
file.write('# Example gallery\n')
|
||||
for fn in sorted(os.listdir(examples_path)):
|
||||
if fnmatch(fn, "ex*.yml"):
|
||||
i = ''.join(filter(str.isdigit, fn))
|
||||
def build_generated(groupkeys):
|
||||
for key in groupkeys:
|
||||
# preparation
|
||||
path = groups[key]['path']
|
||||
build_readme = readme in groups[key]
|
||||
if build_readme:
|
||||
include_readme = 'md' in groups[key][readme]
|
||||
include_source = 'yml' in groups[key][readme]
|
||||
with open_file_write(path / readme) as out:
|
||||
out.write(f'# {groups[key]["title"]}\n\n')
|
||||
# collect and iterate input YAML files
|
||||
for yaml_file in collect_filenames('Building', key, input_extensions):
|
||||
print(f' "{yaml_file}"')
|
||||
wireviz.main(yaml_file, prepend=None, out=['png', 'svg', 'html', 'csv'])
|
||||
|
||||
path = examples_path / f'{fn}'
|
||||
os.chdir(path.parent.absolute())
|
||||
outfile_name = path.name.replace('.yml', '')
|
||||
if build_readme:
|
||||
i = ''.join(filter(str.isdigit, yaml_file.stem))
|
||||
|
||||
print(path)
|
||||
wireviz.main(path, prepend=None, out=['png', 'svg', 'html', 'csv'])
|
||||
with open_file_append(path / readme) as out:
|
||||
if include_readme:
|
||||
with open_file_read(yaml_file.with_suffix('.md')) as info:
|
||||
for line in info:
|
||||
out.write(line.replace('## ', f'## {i} - '))
|
||||
out.write('\n\n')
|
||||
else:
|
||||
out.write(f'## Example {i}\n')
|
||||
|
||||
file.write(f'## Example {i}\n')
|
||||
file.write(f'\n\n')
|
||||
file.write(f'[Source]({fn}) - [Bill of Materials]({outfile_name}.bom.tsv)\n\n\n')
|
||||
if include_source:
|
||||
with open_file_read(yaml_file) as src:
|
||||
out.write('```yaml\n')
|
||||
for line in src:
|
||||
out.write(line)
|
||||
out.write('```\n')
|
||||
out.write('\n')
|
||||
|
||||
out.write(f'\n\n')
|
||||
out.write(f'[Source]({yaml_file.name}) - [Bill of Materials]({yaml_file.stem}.bom.tsv)\n\n\n')
|
||||
|
||||
|
||||
def build_tutorials():
|
||||
with open_file_write(os.path.join(tutorials_path, readme)) as file:
|
||||
file.write('# WireViz Tutorial\n')
|
||||
for fn in sorted(os.listdir(tutorials_path)):
|
||||
if fnmatch(fn, "tutorial*.yml"):
|
||||
i = ''.join(filter(str.isdigit, fn))
|
||||
|
||||
path = tutorials_path / f'{fn}'
|
||||
os.chdir(path.parent.absolute())
|
||||
outfile_name = path.name.replace('.yml', '')
|
||||
|
||||
print(path)
|
||||
|
||||
wireviz.main(path, prepend=None, out=['png', 'svg', 'html', 'csv'])
|
||||
|
||||
with open_file_read(outfile_name + '.md') as info:
|
||||
for line in info:
|
||||
file.write(line.replace('## ', '## {} - '.format(i)))
|
||||
file.write(f'\n[Source]({fn}):\n\n')
|
||||
|
||||
with open_file_read(path) as src:
|
||||
file.write('```yaml\n')
|
||||
for line in src:
|
||||
file.write(line)
|
||||
file.write('```\n')
|
||||
file.write('\n')
|
||||
|
||||
file.write('\nOutput:\n\n'.format(i))
|
||||
|
||||
file.write(f'\n\n')
|
||||
|
||||
file.write(f'[Bill of Materials - TSV](tutorial{outfile_name}.bom.tsv)\n\n')
|
||||
file.write(f'[Bill of Materials - CSV](tutorial{outfile_name}.bom.csv)\n\n\n')
|
||||
def clean_generated(groupkeys):
|
||||
for key in groupkeys:
|
||||
# collect and remove files
|
||||
for filename in collect_filenames('Cleaning', key, generated_extensions):
|
||||
if filename.is_file():
|
||||
print(f' rm "{filename}"')
|
||||
os.remove(filename)
|
||||
|
||||
|
||||
def clean_examples():
|
||||
generated_extensions = ['.gv', '.png', '.svg', '.html', '.bom.tsv', '.bom.csv']
|
||||
def compare_generated(groupkeys, include_graphviz_output = False):
|
||||
compare_extensions = generated_extensions if include_graphviz_output else extensions_not_containing_graphviz_output
|
||||
for key in groupkeys:
|
||||
# collect and compare files
|
||||
for filename in collect_filenames('Comparing', key, compare_extensions):
|
||||
cmd = f'git --no-pager diff "{filename}"'
|
||||
print(f' {cmd}')
|
||||
os.system(cmd)
|
||||
|
||||
for filepath in [examples_path, demos_path, tutorials_path]:
|
||||
print(filepath)
|
||||
for file in sorted(os.listdir(filepath)):
|
||||
if os.path.exists(os.path.join(filepath, file)):
|
||||
if list(filter(file.endswith, generated_extensions)) or file == 'readme.md':
|
||||
print('rm ' + os.path.join(filepath, file))
|
||||
os.remove(os.path.join(filepath, file))
|
||||
|
||||
def restore_generated(groupkeys):
|
||||
for key in groupkeys:
|
||||
# collect input YAML files
|
||||
filename_list = collect_filenames('Restoring', key, input_extensions)
|
||||
# collect files to restore
|
||||
filename_list = [fn.with_suffix(ext) for fn in filename_list for ext in generated_extensions]
|
||||
if readme in groups[key]:
|
||||
filename_list.append(groups[key]['path'] / readme)
|
||||
# restore files
|
||||
for filename in filename_list:
|
||||
cmd = f'git checkout -- "{filename}"'
|
||||
print(f' {cmd}')
|
||||
os.system(cmd)
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Wireviz Example Manager',
|
||||
)
|
||||
parser.add_argument('action', nargs='?', action='store', default='build')
|
||||
parser.add_argument('-generate', nargs='*', choices=['examples', 'demos', 'tutorials'], default=['examples', 'demos', 'tutorials'])
|
||||
parser = argparse.ArgumentParser(description='Wireviz Example Manager',)
|
||||
parser.add_argument('action', nargs='?', action='store',
|
||||
choices=['build','clean','compare','restore'], default='build',
|
||||
help='what to do with the generated files (default: build)')
|
||||
parser.add_argument('-c', '--compare-graphviz-output', action='store_true',
|
||||
help='the Graphviz output is also compared (default: False)')
|
||||
parser.add_argument('-g', '--groups', nargs='+',
|
||||
choices=groups.keys(), default=groups.keys(),
|
||||
help='the groups of generated files (default: all)')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
if args.action == 'build':
|
||||
generate_types = {
|
||||
'examples': build_examples,
|
||||
'demos': build_demos,
|
||||
'tutorials': build_tutorials
|
||||
}
|
||||
|
||||
for gentype in args.generate:
|
||||
if gentype in generate_types:
|
||||
generate_types.get(gentype)()
|
||||
|
||||
build_generated(args.groups)
|
||||
elif args.action == 'clean':
|
||||
clean_examples()
|
||||
clean_generated(args.groups)
|
||||
elif args.action == 'compare':
|
||||
compare_generated(args.groups, args.compare_graphviz_output)
|
||||
elif args.action == 'restore':
|
||||
restore_generated(args.groups)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@ -113,7 +113,17 @@ def remove_line_breaks(inp):
|
||||
return inp.replace('\n', ' ').rstrip() if isinstance(inp, str) else inp
|
||||
|
||||
def open_file_read(filename):
|
||||
# TODO: Intelligently determine encoding
|
||||
return open(filename, 'r', encoding='UTF-8')
|
||||
|
||||
def open_file_write(filename, newline='\n'):
|
||||
return open(filename, 'w', encoding='UTF-8', newline=newline)
|
||||
def open_file_write(filename):
|
||||
return open(filename, 'w', encoding='UTF-8')
|
||||
|
||||
def open_file_append(filename):
|
||||
return open(filename, 'a', encoding='UTF-8')
|
||||
|
||||
def manufacturer_info_field(manufacturer, mpn):
|
||||
if manufacturer or mpn:
|
||||
return f'{manufacturer if manufacturer else "MPN"}{": " + str(mpn) if mpn else ""}'
|
||||
else:
|
||||
return None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user