-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetadata.py
45 lines (32 loc) · 1.15 KB
/
metadata.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
import json
class Metadata(object):
def __init__(self):
self.tstamp = ''
# Not used, no processing done
# def From_PCB(self, pcb):
# def To_PCB(self):
def To_SVG(self, input):
# This will just take whatever data and store it in an XML tag as JSON
# Hacky, but we don't care about it other than to be able to load it back in later
tag = str(input[0])
input = input[1:]
body = json.dumps(input)
svg = '<' + tag + '>'
svg += str(body)
svg += '</' + tag + '>'
return svg
def From_SVG(self, svg):
# content = svg.svg.kicad.contents[0][0:-1]
pcb = []
for tag in svg.svg.kicad.children:
if tag.name != None:
chunk = [tag.name]
try:
chunk += json.loads(tag.decode_contents())
except:
assert False,"Bad metadata {}: {} - {}".format(type(tag), tag, chunk)
pcb += [chunk]
# content = '[' + content + ' ]'
# meta = json.loads(content)
# print(meta)
return pcb