Commit b0b000f2 authored by sumpfralle's avatar sumpfralle

added support for filename "-" as "read from stdin"


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@476 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 08a02f47
...@@ -51,12 +51,19 @@ def parse_toolpath_settings(filename): ...@@ -51,12 +51,19 @@ def parse_toolpath_settings(filename):
keywords = {} keywords = {}
in_meta_zone = False in_meta_zone = False
meta_content = [] meta_content = []
if filename == "-":
# read from stdin, if the input filename is "-"
infile = sys.stdin
close_file = False
else:
# open the file
try: try:
infile = open(filename,"r") infile = open(filename,"r")
except IOError, err_msg: except IOError, err_msg:
log.warn("ToolpathSettingsParser: Failed to read file (%s): %s" % \ log.warn("ToolpathSettingsParser: Failed to read file (%s): %s" % \
(filename, err_msg)) (filename, err_msg))
return None return None
close_file = True
for line in infile.readlines(): for line in infile.readlines():
match = re.match(REGEX_META_KEYWORDS, line) match = re.match(REGEX_META_KEYWORDS, line)
if match: if match:
...@@ -71,6 +78,8 @@ def parse_toolpath_settings(filename): ...@@ -71,6 +78,8 @@ def parse_toolpath_settings(filename):
if re.match(REGEX_SETTINGS_START, line): if re.match(REGEX_SETTINGS_START, line):
in_meta_zone = True in_meta_zone = True
meta_content.append([]) meta_content.append([])
if close_file:
# only close the file if it was opened before (e.g. not stdin)
infile.close() infile.close()
return keywords, [os.linesep.join(one_block) for one_block in meta_content] return keywords, [os.linesep.join(one_block) for one_block in meta_content]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment