summaryrefslogtreecommitdiff
path: root/gerber/common.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2016-11-05 21:11:09 -0400
committerGitHub <noreply@github.com>2016-11-05 21:11:09 -0400
commitd2fe4441662435e55f2dc481bf94a2729b9d6a48 (patch)
treedd60a0b21e1d1ca7258b9f978ce973354d96062c /gerber/common.py
parent318a81382e074a5897489299a58e029815d23492 (diff)
parent5af19af190c1fb0f0c5be029d46d63e657dde4d9 (diff)
downloadgerbonara-d2fe4441662435e55f2dc481bf94a2729b9d6a48.tar.gz
gerbonara-d2fe4441662435e55f2dc481bf94a2729b9d6a48.tar.bz2
gerbonara-d2fe4441662435e55f2dc481bf94a2729b9d6a48.zip
Merge pull request #3 from garretfick/merge-curtacircuitos
Merge curtacircuitos
Diffstat (limited to 'gerber/common.py')
-rw-r--r--gerber/common.py42
1 files changed, 37 insertions, 5 deletions
diff --git a/gerber/common.py b/gerber/common.py
index 6e8c862..cf137dd 100644
--- a/gerber/common.py
+++ b/gerber/common.py
@@ -15,6 +15,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from . import rs274x
+from . import excellon
+from . import ipc356
+from .exceptions import ParseError
+from .utils import detect_file_format
+
def read(filename):
""" Read a gerber or excellon file and return a representative object.
@@ -30,13 +36,39 @@ def read(filename):
CncFile object representing the file, either GerberFile or
ExcellonFile. Returns None if file is not an Excellon or Gerber file.
"""
- import rs274x
- import excellon
- from utils import detect_file_format
- fmt = detect_file_format(filename)
+ 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')
+
+
+def loads(data):
+ """ 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.
+
+ Returns
+ -------
+ file : CncFile subclass
+ CncFile object representing the file, either GerberFile or
+ ExcellonFile. Returns None if file is not an Excellon or Gerber file.
+ """
+
+ fmt = detect_file_format(data)
+ if fmt == 'rs274x':
+ return rs274x.loads(data)
+ elif fmt == 'excellon':
+ return excellon.loads(data)
else:
- return None
+ raise TypeError('Unable to detect file format')