summaryrefslogtreecommitdiff
path: root/gerber/utils.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2015-10-10 16:51:21 -0400
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2015-10-10 16:51:21 -0400
commitdd63b169f177389602e17bc6ced53bd0f1ba0de3 (patch)
tree12be6d968c97be78c3910b2c84b048211e88c7e2 /gerber/utils.py
parentb81c9d4bf96845ced3495eb158ec3a3c9e4dce3d (diff)
downloadgerbonara-dd63b169f177389602e17bc6ced53bd0f1ba0de3.tar.gz
gerbonara-dd63b169f177389602e17bc6ced53bd0f1ba0de3.tar.bz2
gerbonara-dd63b169f177389602e17bc6ced53bd0f1ba0de3.zip
Allow files to be read from strings per #37
Adds a loads() method to the top level module which generates a GerberFile or ExcellonFile from a string
Diffstat (limited to 'gerber/utils.py')
-rw-r--r--gerber/utils.py20
1 files changed, 5 insertions, 15 deletions
diff --git a/gerber/utils.py b/gerber/utils.py
index df26516..1c0af52 100644
--- a/gerber/utils.py
+++ b/gerber/utils.py
@@ -201,30 +201,20 @@ def decimal_string(value, precision=6, padding=False):
return int(floatstr)
-def detect_file_format(filename):
+def detect_file_format(data):
""" Determine format of a file
Parameters
----------
- filename : string
- Filename of the file to read.
+ data : string
+ string containing file data.
Returns
-------
format : string
- File format. either 'excellon' or 'rs274x'
+ File format. 'excellon' or 'rs274x' or 'unknown'
"""
-
- # Read the first 20 lines (if possible)
- lines = []
- with open(filename, 'r') as f:
- try:
- for i in range(20):
- lines.append(f.readline())
- except StopIteration:
- pass
-
- # Look for
+ lines = data.split('\n')
for line in lines:
if 'M48' in line:
return 'excellon'