Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 96 lines (83 sloc) 2.5 KB
#! /usr/bin/env python3
# The MIT License (MIT)
#
# Copyright (c) 2015 Josef Gajdusek
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import csv
import argparse
from eeschema import SchemaLib, Component, Pin
parser = argparse.ArgumentParser(
prog = "csvtokicad"
)
parser.add_argument(
"-i",
"--input",
help = "Input .csv file",
required = True
)
parser.add_argument(
"-o",
"--output",
help = "output KiCad .lib file",
required = True
)
parser.add_argument(
"-n",
"--name",
help = "component name",
required = True
)
parser.add_argument(
"-p",
"--pin-name",
help = "python format string of the pin name",
required = True
)
parser.add_argument(
"-k",
"--pin-number",
help = "python format string of the pin number",
required = True
)
parser.add_argument(
"--allow-non-number",
help = "allow non-number pin numbers",
action = "store_true"
)
args = parser.parse_args()
lib = SchemaLib()
com = Component(args.name)
lib.add_component(com)
with open(args.input) as inp:
reader = csv.reader(inp)
y = -100
for row in reader:
pna = args.pin_name.format(*row).replace(" ", "")
pnu = args.pin_number.format(*row)
if not args.allow_non_number:
try:
int(pnu)
except:
continue
com.add_pin(Pin(pna, pnu, y = y))
y -= 100
print("% 3s\t-- %s" % (pnu, pna))
lib.save(args.output)
print("{0} saved to {1}".format(args.name, args.output))