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 = []
try: if filename == "-":
infile = open(filename,"r") # read from stdin, if the input filename is "-"
except IOError, err_msg: infile = sys.stdin
log.warn("ToolpathSettingsParser: Failed to read file (%s): %s" % \ close_file = False
(filename, err_msg)) else:
return None # open the file
try:
infile = open(filename,"r")
except IOError, err_msg:
log.warn("ToolpathSettingsParser: Failed to read file (%s): %s" % \
(filename, err_msg))
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,7 +78,9 @@ def parse_toolpath_settings(filename): ...@@ -71,7 +78,9 @@ 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([])
infile.close() if close_file:
# only close the file if it was opened before (e.g. not stdin)
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]
if __name__ == "__main__": if __name__ == "__main__":
......
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