Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
3dde1f73aThis file is pinned to the selected release. Download the original to open it in your design tool.
#!/usr/bin/python3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os, re, sys, getopt
VERSION_STR = "0.1.0"
def version(fp):
fp.write("kicad-sym-lib-table v" + VERSION_STR + "\n")
def usage(fp):
version(fp)
fp.write("\nusage:\n")
fp.write("\n")
fp.write(" kicad-sym-lib-table [-h] [-v] [-N project_name] [-L project_location] <libdir> (<libdir>) ... (<libdir>)\n")
fp.write("\n")
fp.write(" [-N project_name] project name\n")
fp.write(" [-L project_location] project location\n")
fp.write(" [-h] help (this screen)\n")
fp.write(" [-v] show version\n")
fp.write("\n")
KICAD_PROJ = "x"
KICAD_MOD_VAR = "KIPRJMOD"
KIPRJMOD=os.environ['HOME'] + "/kicad/" + KICAD_PROJ
sym_lib_table = {
"sym_lib_table": [
#{"lib" : [ {"name":"4xxx"}, {"type":"Legacy"}, {"uri": "${" + KICAD_MOD_VAR + "}/4xxx.lib"}, {"options":'""'}, {"descr":"4xxx series symbols"} ] }
]
}
INDIRS = []
KICAD_MOD_LOCAL_SUBDIR = "custom"
try:
opts,args = getopt.getopt(sys.argv[1:], "hvN:L:", ["help", "version"])
except getopt.GetoptError as err:
sys.stderr.write(err)
sys.stderr.write("\n")
usage(sys.stderr)
sys.exit(2)
for o,a in opts:
if o in ("-h", "--help"):
usage(sys.stdout)
sys.exit(0)
elif o in ("-v", "--version"):
version(sys.stdout)
sys.exit(0)
elif o == "-P":
KICAD_PROJ = a
elif o == "-L":
KICAD_MOD_LOCAL_SUBDIR = a
if len(args) > 0:
for a in args:
INDIRS.append(a)
if len(INDIRS) == 0:
sys.stderr.write("provide input component lib directory\n")
usage(sys.stderr)
sys.exit(3)
uri_base = "${" + KICAD_MOD_VAR + "}/" + KICAD_MOD_LOCAL_SUBDIR
def print_sym_lib_table(ofp,x):
ofp.write("(sym_lib_table\n")
for ent in sym_lib_table["sym_lib_table"]:
ofp.write(" (lib")
for idx in range(len(ent["lib"])):
ofp.write( " (" + str(ent["lib"][idx][0]) + " " + str(ent["lib"][idx][1]) + ")" )
ofp.write(")\n")
ofp.write(")\n")
for INDIR in INDIRS:
z = os.listdir(INDIR)
for fn in z:
s = "\.lib"
m = re.search(s, fn)
if not m: continue
tok = fn.split(".")
#lib_ent = {"lib" : [ ["name",tok[0]], ["type","Legacy"], ["uri", "${" + KICAD_MOD_VAR + "}/" + fn], ["options",'""'], ["descr", tok[0] + " symbol"] ] }
lib_ent = {"lib" : [ ["name",tok[0]], ["type","Legacy"], ["uri", uri_base + "/" + fn], ["options",'""'], ["descr", '"' + tok[0] + ' symbol"'] ] }
sym_lib_table["sym_lib_table"].append(lib_ent)
print_sym_lib_table(sys.stdout, sym_lib_table)