-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathutils.py
46 lines (36 loc) · 973 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import re
import jinja2
def deduplicate_list(l):
out = []
for i in l:
if i not in out:
out.append(i)
return out
def parse_vue_template(path):
with open(path) as f:
vue = f.read()
match = re.search(r'<template>[\s\S]+</template>', vue, re.MULTILINE)
template = match.group(0)
return template
def write_to_file(template, destination, **kwargs):
env = jinja2.Environment(loader=jinja2.FileSystemLoader("./"))
template = env.get_template(template)
rendered = template.render(**kwargs)
with open(destination, "w") as f:
f.write(rendered)
def diff(old, new):
for i in new:
if i not in old:
print("+", i)
for i in old:
if i not in new:
print("-", i)
print("")
def type_html_to_py(type_):
if type_ == "number":
type_ = "int"
elif type_ == "checkbox":
type_ = "bool"
else:
type_ = "str"
return type_