From 9febca7da6a730b3b3ca3a54129a9f88e5c44d14 Mon Sep 17 00:00:00 2001 From: opiopan Date: Thu, 21 Mar 2019 22:00:32 +0900 Subject: initial commit --- gerberex/common.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 gerberex/common.py (limited to 'gerberex/common.py') diff --git a/gerberex/common.py b/gerberex/common.py new file mode 100644 index 0000000..4a85bd4 --- /dev/null +++ b/gerberex/common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright 2019 Hiroshi Murayama + +import os +from gerber.common import loads as loads_org +from gerber.exceptions import ParseError +from gerber.utils import detect_file_format +import gerber.rs274x +import gerber.ipc356 +import gerberex.rs274x +import gerberex.excellon +import gerberex.dxf + +def read(filename, format=None): + with open(filename, 'rU') as f: + data = f.read() + return loads(data, filename, format=format) + + +def loads(data, filename=None, format=None): + if os.path.splitext(filename if filename else '')[1].lower() == '.dxf': + return gerberex.dxf.loads(data, filename) + + fmt = detect_file_format(data) + if fmt == 'rs274x': + file = gerber.rs274x.loads(data, filename=filename) + return gerberex.rs274x.GerberFile.from_gerber_file(file) + elif fmt == 'excellon': + return gerberex.excellon.loads(data, filename=filename, format=format) + elif fmt == 'ipc_d_356': + return ipc356.loads(data, filename=filename) + else: + raise ParseError('Unable to detect file format') -- cgit