first commit
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -160,3 +160,6 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
fp-lib-table
|
||||
sym-lib-table
|
||||
symbols.txt
|
||||
|
||||
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "exporter sym-lib",
|
||||
"type": "debugpy",
|
||||
"request": "launch",
|
||||
"program": "exporter.py",
|
||||
"args": [".\\sym-lib-table", ".\\symbols.txt"],
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
# kicad-symbol-exporter
|
||||
|
||||
exports a list of all available symbols and footprints in the format `LIBRARY:PART` to one text file each
|
||||
exports a list of all available symbols/footprints in the format `LIBRARY:PART` to a text file
|
||||
|
||||
## usage
|
||||
```
|
||||
python fp-lib-table footprints.txt
|
||||
python sym-lib-table symbols.txt
|
||||
```
|
||||
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