first commit
This commit is contained in:
91
exporter.py
Normal file
91
exporter.py
Normal file
@@ -0,0 +1,91 @@
|
||||
import argparse
|
||||
import re
|
||||
import pprint as ppr
|
||||
# from kiutils.libraries import LibTable # using own parser for easier env var substitution
|
||||
from kiutils.symbol import SymbolLib
|
||||
|
||||
|
||||
printer = ppr.PrettyPrinter(width=900)
|
||||
pprint = printer.pprint
|
||||
|
||||
debug = True
|
||||
|
||||
|
||||
def parse_inputs():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('input', type=str, help='input file')
|
||||
parser.add_argument('output', type=str, help='output file')
|
||||
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_inputs()
|
||||
|
||||
filename = args.input
|
||||
|
||||
libs = table_to_dict(filename)
|
||||
|
||||
with open(args.output, 'w+') as f:
|
||||
for name, path in libs.items():
|
||||
if libs['lib_table_type'] == 'sym_lib_table':
|
||||
ent = symbols_to_list(path)
|
||||
pass
|
||||
|
||||
pass
|
||||
|
||||
def table_to_dict(filename):
|
||||
with open(filename, 'r') as f:
|
||||
lib_table = f.read()
|
||||
|
||||
# check for env fields
|
||||
p = r'\${.*}'
|
||||
m = re.findall(p, lib_table)
|
||||
envs = {env: None for env in m}
|
||||
|
||||
# ask for env field values
|
||||
for env, _ in envs.items():
|
||||
env_cleaned = env.strip('$').strip('}').strip('{')
|
||||
envs[env] = input(f'Please enter the path for {env_cleaned}: ')
|
||||
|
||||
# replace envs
|
||||
for env, val in envs.items():
|
||||
lib_table = re.sub(fr'\{env}', val, lib_table)
|
||||
|
||||
libs = {}
|
||||
p = r'name "([^"]*)".*type "([^"]*)".*uri "([^"]*)"'
|
||||
for line in lib_table.splitlines():
|
||||
m = re.search(p, line)
|
||||
if not m: continue
|
||||
if m[2] == 'KiCad':
|
||||
libs[m[1]] = m[3]
|
||||
|
||||
libs['lib_table_type'] = lib_table.splitlines()[0][1:]
|
||||
|
||||
return libs
|
||||
|
||||
def symbols_to_list(path):
|
||||
sym = SymbolLib.from_file(path)
|
||||
|
||||
symlst = [s.entryName for s in sym.symbols if (s.inBom and not s.isPower)]
|
||||
|
||||
pass
|
||||
|
||||
# with open(path, 'r') as sym_f:
|
||||
# symbols = sym_f.read()
|
||||
|
||||
# symlst = []
|
||||
|
||||
# p = r'symbol "([^"]*)"'
|
||||
# level = 0
|
||||
# for line in symbols.splitlines():
|
||||
# level += line.count('(') - line.count(')')
|
||||
# name = re.search(p, line)
|
||||
# if name and level == 2:
|
||||
# symlst.append(name[1])
|
||||
# # print(f' {level:2} |\t{line}')
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user