KiCad / kicad-library-utils

Some scripts for helping with library development
GNU General Public License v3.0
128 stars 95 forks source link

Seperate LibTable class from check_lib_table functionality #298

Closed seppestas closed 4 years ago

seppestas commented 5 years ago

This makes re-using the LibTable class a bit easier and logical. It also remove schematic lib specific code from LibTable making it re-usable for footprint libraries.

Could be used to e.g check custom options in LibTables. I plan to use it together with the functionality of #297 to only check "approved" symbols in a symbol library by having a CSV "SYMBOLS" field in the library options. This makes something like this possible:

# Check "enabled" symbols of all symbol libraries in a symbol library table for KLC compliance
import subprocess
import re
from importlib import import_module
LibTable = import_module("kicad-library-utils.lib_table").LibTable

lib_table = LibTable('sym_lib_table')

for library in lib_table.entries:
    re_symbols= re.search(r'SYMBOLS=([^ ]+)', library['opt'])
    checklib_args = []
    if re_symbols:
        symbols = re_symbols.groups()[0]
        checklib_args.extend(['-c', symbols])

    checklib_args.append(library['uri'].replace('${KICAD_SYMBOL_DIR}', '../symbols'))
    # TODO: make checklib work as python module
    subprocess.call(['./kicad-library-utils/schlib/checklib.py'] + checklib_args)

This could also be used to add an option to ignore certain rules for a symbol library, see #296.

poeschlr commented 4 years ago

thanks