From c313e6de8c06017739402ea89f55ce3b36ac0f2b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 9 Feb 2019 23:37:02 +0100 Subject: o kicad-mkdeps: new tool, new -M option for kicad-gerber. Both output a Makefile-compatible dependencies file. --- src/ee/tools/kicad_gerber.py | 81 +++++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 19 deletions(-) (limited to 'src/ee/tools/kicad_gerber.py') diff --git a/src/ee/tools/kicad_gerber.py b/src/ee/tools/kicad_gerber.py index be0e34d..7f15154 100755 --- a/src/ee/tools/kicad_gerber.py +++ b/src/ee/tools/kicad_gerber.py @@ -1,8 +1,29 @@ -#!/usr/bin/env python +from __future__ import print_function import sys import os import argparse -from pcbnew import * + +try: + from pcbnew import * +except ImportError: + + ee_hack = os.environ.get("EE_HACK", "0") + print("ee_hack={}".format(ee_hack), file=sys.stderr) + try_p2 = sys.version_info.major == 2 and ee_hack != "1" + print("Could not import 'pcbnew' module. Make sure you run this command with KiCAD's python.", file=sys.stderr) + + argv = sys.argv[1:] + cmd = "python2 {} {}".format(__file__, " ".join(argv)) + print(cmd, file=sys.stderr) + + import subprocess + + subprocess.call("sleep 1", shell=True) + env = dict(os.environ) + env["EE_HACK"] = "1" + ret = subprocess.call(cmd, shell=True, env=env) + print("ret={}".format(ret), file=sys.stderr) + sys.exit(ret) def layer_name_parser(s): @@ -32,6 +53,11 @@ parser.add_argument('--detect-files-only', action='store_true', help='Don\'t create the GERBER files, just list the files to be created') +parser.add_argument('-M', + dest='mkdep', + action='store_true', + help='Don\'t create the GERBER files, output a Makefile-compatible file') + parser.add_argument('--create-drill-map-file', dest='create_drill_map_file', action='store_true', @@ -42,6 +68,11 @@ parser.add_argument('--protel-extensions', action='store_true', help='Use Protel filename extensions instead of .gbr') +parser.add_argument('--extended-gerber-attributes', + dest='extended_gerber_attributes', + action='store_true', + help='Use extended Gerber attributes') + parser.add_argument('--uppercase-extensions', action='store_true', help='Uppercase all extensions') @@ -101,7 +132,16 @@ for layerNum in layers.CuStack(): pctl = PLOT_CONTROLLER(board) popt = pctl.GetPlotOptions() -popt.SetOutputDirectory(args.output_directory) + +output_directory = args.output_directory +popt.SetOutputDirectory(output_directory) + +if not os.path.isdir(output_directory): + try: + os.makedirs(output_directory) + except: + print("Could not make output directory", file=sys.stderr) + sys.exit(1) # A nasty hack to get the base filename pctl.SetLayer(F_Cu) @@ -113,12 +153,12 @@ except: pass pctl.ClosePlot() -if args.protel_extensions: - popt.SetUseGerberProtelExtensions(True) +# "Use protel filename extensions", default=False +popt.SetUseGerberProtelExtensions(args.protel_extensions) basename = os.path.splitext(filename)[0] -drlFileOut = drlFile = basename + ".drl" +drlFileOut = drlFile = basename + "-PTH.drl" drlNpthFileOut = drlNpthFile = basename + "-NPTH.drl" if args.protel_extensions: @@ -162,16 +202,21 @@ for plan in plot_plan: # print "filename = " + plan.filename + ", postfix=" + plan.postfix # print "filename: " + plan.filename -if args.detect_files_only: - for plan in plot_plan: - print - plan.filename +if args.detect_files_only or args.mkdep: + if not args.mkdep: + for plan in plot_plan: + print(plan.filename) + + print(drlFileOut) + print(drlNpthFileOut) + else: + print("GERBERS = ") + for plan in plot_plan: + print("GERBERS += {}".format(plan.filename)) + print("GERBERS += {}".format(drlFileOut, args.pcb)) + print("GERBERS += {}".format(drlNpthFileOut, args.pcb)) + print("$(GERBERS): {}".format(args.pcb)) - if args.protel_extensions: - print - drlFileOut - print - drlNpthFileOut sys.exit(0) # Set some important plot options: @@ -181,7 +226,7 @@ popt.SetLineWidth(FromMM(0.35)) popt.SetAutoScale(False) popt.SetScale(1) popt.SetMirror(False) -popt.SetUseGerberAttributes(True) +popt.SetUseGerberAttributes(args.extended_gerber_attributes) popt.SetScale(1) popt.SetUseAuxOrigin(True) @@ -226,8 +271,6 @@ drlwriter.CreateDrillandMapFilesSet(pctl.GetPlotDirName(), genDrl, genMap) if drlFile != drlFileOut: os.rename(drlFile, drlFileOut) - pass -if drlFile != drlNpthFileOut: +if drlNpthFile != drlNpthFileOut: os.rename(drlNpthFile, drlNpthFileOut) - pass -- cgit v1.2.3