Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
validate_args(args)
except RuntimeError as e:
print(e)
sys.exit(1)
if args["type"] == "html":
renderer = Renderer(mistune.Renderer)
outputfile = "index.html"
try:
template = read_template(find_data_file(args["template"], '.handlebars', TEMPLATES_SUBDIR))
except IOError:
print("Cannot open template file " + args["template"])
sys.exit(1)
else:
renderer = Renderer(pcbdraw.mdrenderer.MdRenderer)
outputfile = "index.md"
content = parse_content(renderer, content)
content = generate_images(content, args["board"], args["libs"],
args["params"], args["img_name"], args["output"])
if args["type"] == "html":
output = generate_html(template, content)
else:
output = generate_markdown(content)
with open(os.path.join(args["output"], outputfile), "wb") as f:
f.write(output)
def table(self, header, body):
hrows = []
while header:
header, type, t = MdRenderer.get_block(header)
if type == 'r':
flags = {}
cols = []
while t:
t, type2, t2 = MdRenderer.get_block(t)
if type2 == 'f':
fl, v = t2.split('=')
flags[fl] = v
elif type2 == 'c':
cols.append(type('',(object,),{'flags':flags,'text':t2})())
hrows.append(cols)
brows = []
while body:
body, type, t = MdRenderer.get_block(body)
if type == 'r':
flags = {}
for group in svg_elements:
for svg_element in group:
if svg_element.tag == "path":
elements.append(SvgPathItem(svg_element.attrib["d"]))
elif svg_element.tag == "circle":
# Convert circle to path
att = svg_element.attrib
s = " M {0} {1} m-{2} 0 a {2} {2} 0 1 0 {3} 0 a {2} {2} 0 1 0 -{3} 0 ".format(
att["cx"], att["cy"], att["r"], 2 * float(att["r"]))
path += s
outline = [elements[0]]
elements = elements[1:]
while True:
size = len(outline)
for i, e in enumerate(elements):
if SvgPathItem.is_same(outline[0].start, e.end):
outline.insert(0, e)
elif SvgPathItem.is_same(outline[0].start, e.start):
e.flip()
outline.insert(0, e)
elif SvgPathItem.is_same(outline[-1].end, e.start):
outline.append(e)
elif SvgPathItem.is_same(outline[-1].end, e.end):
e.flip()
outline.append(e)
else:
continue
del elements[i]
break
if size == len(outline):
first = True
for x in outline:
# Convert circle to path
att = svg_element.attrib
s = " M {0} {1} m-{2} 0 a {2} {2} 0 1 0 {3} 0 a {2} {2} 0 1 0 -{3} 0 ".format(
att["cx"], att["cy"], att["r"], 2 * float(att["r"]))
path += s
outline = [elements[0]]
elements = elements[1:]
while True:
size = len(outline)
for i, e in enumerate(elements):
if SvgPathItem.is_same(outline[0].start, e.end):
outline.insert(0, e)
elif SvgPathItem.is_same(outline[0].start, e.start):
e.flip()
outline.insert(0, e)
elif SvgPathItem.is_same(outline[-1].end, e.start):
outline.append(e)
elif SvgPathItem.is_same(outline[-1].end, e.end):
e.flip()
outline.append(e)
else:
continue
del elements[i]
break
if size == len(outline):
first = True
for x in outline:
path += x.format(first)
first = False
if elements:
outline = [elements[0]]
elements = elements[1:]
s = " M {0} {1} m-{2} 0 a {2} {2} 0 1 0 {3} 0 a {2} {2} 0 1 0 -{3} 0 ".format(
att["cx"], att["cy"], att["r"], 2 * float(att["r"]))
path += s
outline = [elements[0]]
elements = elements[1:]
while True:
size = len(outline)
for i, e in enumerate(elements):
if SvgPathItem.is_same(outline[0].start, e.end):
outline.insert(0, e)
elif SvgPathItem.is_same(outline[0].start, e.start):
e.flip()
outline.insert(0, e)
elif SvgPathItem.is_same(outline[-1].end, e.start):
outline.append(e)
elif SvgPathItem.is_same(outline[-1].end, e.end):
e.flip()
outline.append(e)
else:
continue
del elements[i]
break
if size == len(outline):
first = True
for x in outline:
path += x.format(first)
first = False
if elements:
outline = [elements[0]]
elements = elements[1:]
else:
e = etree.Element("path", d=path, style="fill-rule=evenodd;")
if svg_element.tag == "path":
elements.append(SvgPathItem(svg_element.attrib["d"]))
elif svg_element.tag == "circle":
# Convert circle to path
att = svg_element.attrib
s = " M {0} {1} m-{2} 0 a {2} {2} 0 1 0 {3} 0 a {2} {2} 0 1 0 -{3} 0 ".format(
att["cx"], att["cy"], att["r"], 2 * float(att["r"]))
path += s
outline = [elements[0]]
elements = elements[1:]
while True:
size = len(outline)
for i, e in enumerate(elements):
if SvgPathItem.is_same(outline[0].start, e.end):
outline.insert(0, e)
elif SvgPathItem.is_same(outline[0].start, e.start):
e.flip()
outline.insert(0, e)
elif SvgPathItem.is_same(outline[-1].end, e.start):
outline.append(e)
elif SvgPathItem.is_same(outline[-1].end, e.end):
e.flip()
outline.append(e)
else:
continue
del elements[i]
break
if size == len(outline):
first = True
for x in outline:
path += x.format(first)
first = False
def get_board_polygon(svg_elements):
"""
Try to connect independents segments on Edge.Cuts and form a polygon
return SVG path element with the polygon
"""
elements = []
path = ""
for group in svg_elements:
for svg_element in group:
if svg_element.tag == "path":
elements.append(SvgPathItem(svg_element.attrib["d"]))
elif svg_element.tag == "circle":
# Convert circle to path
att = svg_element.attrib
s = " M {0} {1} m-{2} 0 a {2} {2} 0 1 0 {3} 0 a {2} {2} 0 1 0 -{3} 0 ".format(
att["cx"], att["cy"], att["r"], 2 * float(att["r"]))
path += s
outline = [elements[0]]
elements = elements[1:]
while True:
size = len(outline)
for i, e in enumerate(elements):
if SvgPathItem.is_same(outline[0].start, e.end):
outline.insert(0, e)
elif SvgPathItem.is_same(outline[0].start, e.start):
e.flip()
outline.insert(0, e)
def __init__(self, renderer, rules=None, **kwargs):
super(PcbDrawInlineLexer, self).__init__(renderer, rules=None, **kwargs)
self.enable_pcbdraw()
def parse_content(renderer, content):
lexer = PcbDrawInlineLexer(renderer)
processor = mistune.Markdown(renderer=renderer, inline=lexer)
processor(content)
return renderer.output()
def list(self, text, ordered=True):
r = ''
while text:
text, type, t = MdRenderer.get_block(text)
if type == 'l':
r += (ordered and ('# ' + t) or ('* ' + t)) + '\n'
return r