From 4dcf865355ce81e559d02902b59f71f81d955643 Mon Sep 17 00:00:00 2001 From: Seppl Date: Wed, 1 May 2024 21:38:46 +0200 Subject: [PATCH] added support for footprint libs --- .gitignore | 1 + .vscode/launch.json | 9 +++++++++ exporter.py | 22 +++++++++++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 12bc14f..95a5800 100644 --- a/.gitignore +++ b/.gitignore @@ -164,3 +164,4 @@ fp-lib-table sym-lib-table symbols.txt envs.toml +footprints.txt diff --git a/.vscode/launch.json b/.vscode/launch.json index a977844..f02d972 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,6 +12,15 @@ "args": [".\\sym-lib-table", ".\\symbols.txt", "-e", ".\\envs.toml"], "console": "integratedTerminal", "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 } ] } \ No newline at end of file diff --git a/exporter.py b/exporter.py index 2e45337..359d4f6 100644 --- a/exporter.py +++ b/exporter.py @@ -3,10 +3,11 @@ import re import pprint as ppr from kiutils.libraries import LibTable from kiutils.symbol import SymbolLib +from kiutils.footprint import Footprint import tomli import tomli_w import pathlib - +import glob printer = ppr.PrettyPrinter(width=900) pprint = printer.pprint @@ -43,8 +44,7 @@ def main(): if libs.type == 'sym_lib_table': write_syms_to_file(f, lib) if libs.type == 'fp_lib_table': - pass - # TODO + write_fps_to_file(f, lib) pass def write_syms_to_file(f, lib): @@ -55,6 +55,14 @@ def write_syms_to_file(f, lib): print(f'{lib.name}:{sym}') 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): if args.e: with open(args.e, 'rb') as settings: @@ -83,10 +91,14 @@ def table_to_dict(filename, envs = None): 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)] - 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__': main() \ No newline at end of file