added support for footprint libs

This commit is contained in:
2024-05-01 21:38:46 +02:00
parent bbf4960d28
commit 4dcf865355
3 changed files with 27 additions and 5 deletions

1
.gitignore vendored
View File

@@ -164,3 +164,4 @@ fp-lib-table
sym-lib-table sym-lib-table
symbols.txt symbols.txt
envs.toml envs.toml
footprints.txt

9
.vscode/launch.json vendored
View File

@@ -12,6 +12,15 @@
"args": [".\\sym-lib-table", ".\\symbols.txt", "-e", ".\\envs.toml"], "args": [".\\sym-lib-table", ".\\symbols.txt", "-e", ".\\envs.toml"],
"console": "integratedTerminal", "console": "integratedTerminal",
"justMyCode": false "justMyCode": false
},
{
"name": "exporter fp-lib",
"type": "debugpy",
"request": "launch",
"program": "exporter.py",
"args": [".\\fp-lib-table", ".\\footprints.txt", "-e", ".\\envs.toml"],
"console": "integratedTerminal",
"justMyCode": false
} }
] ]
} }

View File

@@ -3,10 +3,11 @@ import re
import pprint as ppr import pprint as ppr
from kiutils.libraries import LibTable from kiutils.libraries import LibTable
from kiutils.symbol import SymbolLib from kiutils.symbol import SymbolLib
from kiutils.footprint import Footprint
import tomli import tomli
import tomli_w import tomli_w
import pathlib import pathlib
import glob
printer = ppr.PrettyPrinter(width=900) printer = ppr.PrettyPrinter(width=900)
pprint = printer.pprint pprint = printer.pprint
@@ -43,8 +44,7 @@ def main():
if libs.type == 'sym_lib_table': if libs.type == 'sym_lib_table':
write_syms_to_file(f, lib) write_syms_to_file(f, lib)
if libs.type == 'fp_lib_table': if libs.type == 'fp_lib_table':
pass write_fps_to_file(f, lib)
# TODO
pass pass
def write_syms_to_file(f, lib): def write_syms_to_file(f, lib):
@@ -55,6 +55,14 @@ def write_syms_to_file(f, lib):
print(f'{lib.name}:{sym}') print(f'{lib.name}:{sym}')
f.write(f'{lib.name}:{sym}\n') f.write(f'{lib.name}:{sym}\n')
def write_fps_to_file(f, lib):
if lib.type == 'KiCad':
fps = footprints_to_list(lib.uri)
if fps:
for fp in fps:
print(f'{lib.name}:{fp}')
f.write(f'{lib.name}:{fp}\n')
def load_envs(args): def load_envs(args):
if args.e: if args.e:
with open(args.e, 'rb') as settings: with open(args.e, 'rb') as settings:
@@ -83,10 +91,14 @@ def table_to_dict(filename, envs = None):
def symbols_to_list(path): def symbols_to_list(path):
sym = SymbolLib.from_file(path) sym = SymbolLib.from_file(path)
symlst = [s.entryName for s in sym.symbols if (s.inBom and not s.isPower)] symlst = [s.entryName for s in sym.symbols if (s.inBom and not s.isPower)]
return symlst return symlst
def footprints_to_list(path):
fplst = [Footprint.from_file(mod).entryName
for mod in glob.glob(f'{path}/*.kicad_mod')
if not Footprint.from_file(mod).attributes.excludeFromBom]
return fplst
if __name__ == '__main__': if __name__ == '__main__':
main() main()