diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-06-13 00:20:21 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-06-13 00:20:21 +0200 |
commit | 2554f0e774be0e473d650fc206ac7668d4561412 (patch) | |
tree | bcc879666dbc12d817dbdcddc63699c68c7e1687 | |
parent | d9bb11a8c1f28727afd7c0fe74038a72affb959a (diff) | |
download | ee-python-2554f0e774be0e473d650fc206ac7668d4561412.tar.gz ee-python-2554f0e774be0e473d650fc206ac7668d4561412.tar.bz2 ee-python-2554f0e774be0e473d650fc206ac7668d4561412.tar.xz ee-python-2554f0e774be0e473d650fc206ac7668d4561412.zip |
o Working Gerber export.
-rwxr-xr-x | src/ee/tools/kicad_gerber.py | 60 | ||||
-rw-r--r-- | src/ee/tools/mkzip.py | 24 | ||||
-rw-r--r-- | src/ee/tools/ninja.py | 4 | ||||
-rw-r--r-- | src/ee/tools/templates/build.ninja.j2 | 20 |
4 files changed, 78 insertions, 30 deletions
diff --git a/src/ee/tools/kicad_gerber.py b/src/ee/tools/kicad_gerber.py index d9b0dc1..9f5ade7 100755 --- a/src/ee/tools/kicad_gerber.py +++ b/src/ee/tools/kicad_gerber.py @@ -8,10 +8,10 @@ try: from pcbnew import * except ImportError as e: ee_hack = os.environ.get("EE_HACK", "0") - print("ee_hack={}".format(ee_hack), file=sys.stderr) + # print("ee_hack={}".format(ee_hack), file=sys.stderr) try_p2 = ee_hack == "0" try_system = ee_hack == "1" - print("Could not import 'pcbnew' module. Make sure you run this command with KiCAD's python.", file=sys.stderr) + # print("Could not import 'pcbnew' module. Make sure you run this command with KiCAD's python.", file=sys.stderr) ret = 1 try: @@ -23,20 +23,19 @@ except ImportError as e: cmd = "/usr/bin/python2 {} {}".format(__file__, " ".join(argv)) env = dict(os.environ) env["EE_HACK"] = "1" - print(cmd, file=sys.stderr) + # print(cmd, file=sys.stderr) ret = subprocess.call(cmd, shell=True, env=env) - print("ret={}".format(ret), file=sys.stderr) elif try_system: argv = sys.argv[1:] # Try with the OS's main python, hopefully the KiCAD packages support that cmd = "/usr/bin/python3 {} {}".format(__file__, " ".join(argv)) env = dict(os.environ) env["EE_HACK"] = "2" - print(cmd, file=sys.stderr) + # print(cmd, file=sys.stderr) ret = subprocess.call(cmd, shell=True, env=env) - print("ret={}".format(ret), file=sys.stderr) finally: pass + # print("ret={}".format(ret), file=sys.stderr) sys.exit(ret) @@ -70,8 +69,10 @@ parser.add_argument('--detect-files-only', parser.add_argument('-M', dest='mkdep', - action='store_true', - help='Don\'t create the GERBER files, output a Makefile-compatible file') + help='Output a Makefile-compatible file') + +parser.add_argument('--index', + dest='index') parser.add_argument('--create-drill-map-file', dest='create_drill_map_file', @@ -149,6 +150,7 @@ pctl = PLOT_CONTROLLER(board) popt = pctl.GetPlotOptions() output_directory = args.output_directory +output_directory = os.path.abspath(args.output_directory) popt.SetOutputDirectory(output_directory) if not os.path.isdir(output_directory): @@ -217,20 +219,40 @@ for plan in plot_plan: # print "filename = " + plan.filename + ", postfix=" + plan.postfix # print "filename: " + plan.filename -if args.detect_files_only or args.mkdep: - if not args.mkdep: +if args.mkdep: + with open(args.mkdep, "w") as f: + pcb = os.path.abspath(args.pcb) + + def w(path): + p = path[len(os.path.commonprefix([path, pcb])):] + print("{}: {}".format(p, args.pcb), file=f) + for plan in plot_plan: - print(plan.filename) + w(plan.filename) + + w(drlFileOut) + w(drlNpthFileOut) + +if args.index: + with open(args.index, "w") as f: + pcb = os.path.abspath(args.pcb) + + def w(path): + p = path[len(os.path.commonprefix([path, pcb])):] + print("{}".format(p), file=f) - 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)) + w(plan.filename) + + w(drlFileOut) + w(drlNpthFileOut) + +if args.detect_files_only: + for plan in plot_plan: + print(plan.filename) + + print(drlFileOut) + print(drlNpthFileOut) sys.exit(0) diff --git a/src/ee/tools/mkzip.py b/src/ee/tools/mkzip.py new file mode 100644 index 0000000..f816451 --- /dev/null +++ b/src/ee/tools/mkzip.py @@ -0,0 +1,24 @@ +import argparse +import zipfile + +import ee.tools + +parser = argparse.ArgumentParser() +ee.tools.add_default_argparse_group(parser) + +parser.add_argument("--include", + required=True, + metavar="FILE") + +parser.add_argument("--zip", + required=True, + metavar="FILE") + +args = parser.parse_args() +ee.tools.process_default_argparse_group(args) + +with zipfile.ZipFile(args.zip, "w") as zf: + with open(args.include, "r") as files: + for file in files.readlines(): + file = file[0:-1] + zf.write(file) diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py index 98e6599..a26a474 100644 --- a/src/ee/tools/ninja.py +++ b/src/ee/tools/ninja.py @@ -29,8 +29,8 @@ def ninja_path_filter(s: Union[Path, str, List[str]]) -> str: raise Exception("Unsupported argument type: {}".format(type(s))) -def parent_dir_filter(s: Union[str, Path]) -> Path: - return Path(s).parent +def parent_dir_filter(s: Union[str, Path]) -> str: + return str(Path(s).parent) def basename_filter(s: Union[str, Path]) -> str: diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2 index 5c94d3e..d742791 100644 --- a/src/ee/tools/templates/build.ninja.j2 +++ b/src/ee/tools/templates/build.ninja.j2 @@ -12,13 +12,10 @@ pcb = {{ pcb | ninja_path }} {%- set log=log if log is defined else "--log=warn" %} rule kicad-gerber - description = kicad-gerber - command = $ee kicad-gerber $ - --output-dir $gerber_dir $ - --pcb $pcb -# mkdir -p $( -# (cd $(GERBER_DIR); zip tmp.zip $(foreach GBR,$(GERBERS),$(notdir $(GBR)))) -# mv $(GERBER_DIR)/tmp.zip $@ + command = $ee kicad-gerber --pcb $in --output-dir $dir --index $out + +rule mkzip + command = $ee mkzip --include $in --zip $out rule kicad-make-bom command = $ee kicad-make-bom {{ log }} --sch $sch --out $out --uuid $uuid @@ -75,9 +72,14 @@ rule part-from-excel command = $ee part-from-excel {{ log }} --in $in --out $out --sheet "$sheet" {% if gerber_zip is defined %} +{%- set idx=(gerber_zip | parent_dir) + '/.idx' %} +build {{ idx }}: kicad-gerber $pcb + dir = {{ gerber_zip | parent_dir }} + +build {{ gerber_zip }}: mkzip {{ idx }} + build gerbers: phony {{ gerber_zip }} -build {{ gerber_zip }}: kicad-gerber $pcb - gerber_dir = {{ gerber_zip | parent_dir }} +default gerbers {%- endif %} {% if sch is defined -%} |