Source code for eppy3000.rawidf
# Copyright (c) 2019 Santosh Philip
# =======================================================================
# Distributed under the MIT License.
# (See accompanying file LICENSE or copy at
# http://opensource.org/licenses/MIT)
# =======================================================================
"""read and save idf files without using eppy"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
[docs]def readrawidf(fhandle):
"""read the idf file as a dict. Dict keys are idfobjkeys,
dict values are list in list"""
astr = fhandle.read()
nocom = removecomment(astr, "!")
idfst = nocom
alist = idfst.split(";")
rawdata = {}
for element in alist:
lst = element.split(",")
lst = [item.strip() for item in lst]
# key = lst[0].strip().upper()
# not sure of implications here
key = lst[0].strip()
if not key:
continue
rawdata.setdefault(key, [])
rawdata[key].append(lst)
return rawdata
[docs]def rawidf2str(rawdata, order=None): # rname var rawidf -> potential nameclash
"""string rep of rawdata"""
lst = []
if order:
keys = order
else:
keys = rawdata.keys()
for key in keys:
try:
for vals in rawdata[key]:
lst.append("{},".format(key))
for val in vals[1:]:
lst.append(" {},".format(val))
lst.pop(-1)
lst.append(" {};".format(val))
lst.append("")
except KeyError as e:
continue
return "\n".join(lst)