Add a simple open wrapper for the bom python plugins to handle directory creation
This commit is contained in:
parent
0f67c7ed25
commit
50c1a91d44
|
@ -21,6 +21,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
# Import the KiCad python helper module and the csv formatter
|
# Import the KiCad python helper module and the csv formatter
|
||||||
import kicad_netlist_reader
|
import kicad_netlist_reader
|
||||||
|
import kicad_utils
|
||||||
import csv
|
import csv
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ net = kicad_netlist_reader.netlist(sys.argv[1])
|
||||||
# Open a file to write to, if the file cannot be opened output to stdout
|
# Open a file to write to, if the file cannot be opened output to stdout
|
||||||
# instead
|
# instead
|
||||||
try:
|
try:
|
||||||
f = open(sys.argv[2], 'w')
|
f = kicad_utils.open_file_write(sys.argv[2], 'w')
|
||||||
except IOError:
|
except IOError:
|
||||||
e = "Can't open output file for writing: " + sys.argv[2]
|
e = "Can't open output file for writing: " + sys.argv[2]
|
||||||
print( __file__, ":", e, sys.stderr )
|
print( __file__, ":", e, sys.stderr )
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
# Import the KiCad python helper module and the csv formatter
|
# Import the KiCad python helper module and the csv formatter
|
||||||
import kicad_netlist_reader
|
import kicad_netlist_reader
|
||||||
|
import kicad_utils
|
||||||
import csv
|
import csv
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ net = kicad_netlist_reader.netlist(sys.argv[1])
|
||||||
# Open a file to write to, if the file cannot be opened output to stdout
|
# Open a file to write to, if the file cannot be opened output to stdout
|
||||||
# instead
|
# instead
|
||||||
try:
|
try:
|
||||||
f = open(sys.argv[2], 'w')
|
f = kicad_utils.open_file_write(sys.argv[2], 'w')
|
||||||
except IOError:
|
except IOError:
|
||||||
e = "Can't open output file for writing: " + sys.argv[2]
|
e = "Can't open output file for writing: " + sys.argv[2]
|
||||||
print(__file__, ":", e, sys.stderr)
|
print(__file__, ":", e, sys.stderr)
|
||||||
|
|
|
@ -19,6 +19,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
# Import the KiCad python helper module
|
# Import the KiCad python helper module
|
||||||
import kicad_netlist_reader
|
import kicad_netlist_reader
|
||||||
|
import kicad_utils
|
||||||
import csv
|
import csv
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ net = kicad_netlist_reader.netlist(sys.argv[1])
|
||||||
# Open a file to write to, if the file cannot be opened output to stdout
|
# Open a file to write to, if the file cannot be opened output to stdout
|
||||||
# instead
|
# instead
|
||||||
try:
|
try:
|
||||||
f = open(sys.argv[2], 'w')
|
f = kicad_utils.open_file_write(sys.argv[2], 'w')
|
||||||
except IOError:
|
except IOError:
|
||||||
e = "Can't open output file for writing: " + sys.argv[2]
|
e = "Can't open output file for writing: " + sys.argv[2]
|
||||||
print( __file__, ":", e, sys.stderr )
|
print( __file__, ":", e, sys.stderr )
|
||||||
|
|
|
@ -20,6 +20,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
# Import the KiCad python helper module and the csv formatter
|
# Import the KiCad python helper module and the csv formatter
|
||||||
import kicad_netlist_reader
|
import kicad_netlist_reader
|
||||||
|
import kicad_utils
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Start with a basic html template
|
# Start with a basic html template
|
||||||
|
@ -49,7 +50,7 @@ net = kicad_netlist_reader.netlist(sys.argv[1])
|
||||||
# Open a file to write to, if the file cannot be opened output to stdout
|
# Open a file to write to, if the file cannot be opened output to stdout
|
||||||
# instead
|
# instead
|
||||||
try:
|
try:
|
||||||
f = open(sys.argv[2], 'wb')
|
f = kicad_utils.open_file_write(sys.argv[2], 'wb')
|
||||||
except IOError:
|
except IOError:
|
||||||
e = "Can't open output file for writing: " + sys.argv[2]
|
e = "Can't open output file for writing: " + sys.argv[2]
|
||||||
print(__file__, ":", e, file=sys.stderr)
|
print(__file__, ":", e, file=sys.stderr)
|
||||||
|
|
|
@ -20,6 +20,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
# Import the KiCad python helper module and the csv formatter
|
# Import the KiCad python helper module and the csv formatter
|
||||||
import kicad_netlist_reader
|
import kicad_netlist_reader
|
||||||
|
import kicad_utils
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ net = kicad_netlist_reader.netlist(sys.argv[1])
|
||||||
# Open a file to write to, if the file cannot be opened output to stdout
|
# Open a file to write to, if the file cannot be opened output to stdout
|
||||||
# instead
|
# instead
|
||||||
try:
|
try:
|
||||||
f = open(sys.argv[2], 'wb')
|
f = kicad_utils.open_file_write(sys.argv[2], 'wb')
|
||||||
except IOError:
|
except IOError:
|
||||||
e = "Can't open output file for writing: " + sys.argv[2]
|
e = "Can't open output file for writing: " + sys.argv[2]
|
||||||
print(__file__, ":", e, file=sys.stderr)
|
print(__file__, ":", e, file=sys.stderr)
|
||||||
|
|
|
@ -17,6 +17,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
# Import the KiCad python helper module and the csv formatter
|
# Import the KiCad python helper module and the csv formatter
|
||||||
import kicad_netlist_reader
|
import kicad_netlist_reader
|
||||||
|
import kicad_utils
|
||||||
import csv
|
import csv
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ net = kicad_netlist_reader.netlist(sys.argv[1])
|
||||||
# Open a file to write to, if the file cannot be opened output to stdout
|
# Open a file to write to, if the file cannot be opened output to stdout
|
||||||
# instead
|
# instead
|
||||||
try:
|
try:
|
||||||
f = open(sys.argv[2], 'w')
|
f = kicad_utils.open_file_write(sys.argv[2], 'w')
|
||||||
except IOError:
|
except IOError:
|
||||||
e = "Can't open output file for writing: " + sys.argv[2]
|
e = "Can't open output file for writing: " + sys.argv[2]
|
||||||
print(__file__, ":", e, sys.stderr)
|
print(__file__, ":", e, sys.stderr)
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#
|
||||||
|
# KiCad python module for some helper functions
|
||||||
|
#
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
def open_file_write(path, mode):
|
||||||
|
''' Open "path" for writing, creating any parent directories as needed.
|
||||||
|
'''
|
||||||
|
dir_path = os.path.dirname(path)
|
||||||
|
|
||||||
|
if not os.path.isdir(dir_path):
|
||||||
|
os.makedirs(dir_path)
|
||||||
|
|
||||||
|
return open(path, mode)
|
Loading…
Reference in New Issue