summaryrefslogtreecommitdiff
path: root/gerber/common.py
diff options
context:
space:
mode:
authorGarret Fick <garret@fickworkshop.com>2016-11-11 15:54:42 +0800
committerGitHub <noreply@github.com>2016-11-11 15:54:42 +0800
commit1e868763a1c4030bedd51553468cbe25f272bef9 (patch)
tree59cef68f1449a5be8d2a9a8ed352e3d9974a3edb /gerber/common.py
parent5af19af190c1fb0f0c5be029d46d63e657dde4d9 (diff)
parent60d08dc8ad72f5bb0a14d4821451d7dce20b9639 (diff)
downloadgerbonara-1e868763a1c4030bedd51553468cbe25f272bef9.tar.gz
gerbonara-1e868763a1c4030bedd51553468cbe25f272bef9.tar.bz2
gerbonara-1e868763a1c4030bedd51553468cbe25f272bef9.zip
Merge pull request #5 from hamiltonkibbe/merge-curtacircuitos
Merge curtacircuitos
Diffstat (limited to 'gerber/common.py')
-rw-r--r--gerber/common.py33
1 files changed, 15 insertions, 18 deletions
diff --git a/gerber/common.py b/gerber/common.py
index cf137dd..f496809 100644
--- a/gerber/common.py
+++ b/gerber/common.py
@@ -33,42 +33,39 @@ def read(filename):
Returns
-------
file : CncFile subclass
- CncFile object representing the file, either GerberFile or
- ExcellonFile. Returns None if file is not an Excellon or Gerber file.
+ CncFile object representing the file, either GerberFile, ExcellonFile,
+ or IPCNetlist. Returns None if file is not of the proper type.
"""
with open(filename, 'rU') as f:
data = f.read()
- fmt = detect_file_format(data)
- if fmt == 'rs274x':
- return rs274x.read(filename)
- elif fmt == 'excellon':
- return excellon.read(filename)
- elif fmt == 'ipc_d_356':
- return ipc356.read(filename)
- else:
- raise ParseError('Unable to detect file format')
+ return loads(data, filename)
-def loads(data):
+def loads(data, filename=None):
""" Read gerber or excellon file contents from a string and return a
representative object.
Parameters
----------
data : string
- gerber or excellon file contents as a string.
+ Source file contents as a string.
+
+ filename : string, optional
+ String containing the filename of the data source.
Returns
-------
file : CncFile subclass
- CncFile object representing the file, either GerberFile or
- ExcellonFile. Returns None if file is not an Excellon or Gerber file.
+ CncFile object representing the data, either GerberFile, ExcellonFile,
+ or IPCNetlist. Returns None if data is not of the proper type.
"""
fmt = detect_file_format(data)
if fmt == 'rs274x':
- return rs274x.loads(data)
+ return rs274x.loads(data, filename=filename)
elif fmt == 'excellon':
- return excellon.loads(data)
+ return excellon.loads(data, filename=filename)
+ elif fmt == 'ipc_d_356':
+ return ipc356.loads(data, filename=filename)
else:
- raise TypeError('Unable to detect file format')
+ raise ParseError('Unable to detect file format')