Commit 08a02f47 authored by sumpfralle's avatar sumpfralle

added docstring

fixed some code-style warnings


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@475 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 230a0770
......@@ -22,27 +22,42 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Gui.Settings
import pycam.Gui.Project
import pycam.Utils.log
import re
import os
import sys
COMMENT_CHARACTERS = r";#"
REGEX_META_KEYWORDS = r"[%s]?%s (.*): (.*)$" % (COMMENT_CHARACTERS, pycam.Gui.Project.ProjectGui.META_DATA_PREFIX)
REGEX_SETTINGS_START = r"[%s]?%s$" % (COMMENT_CHARACTERS, pycam.Gui.Settings.ToolpathSettings.META_MARKER_START)
REGEX_SETTINGS_END = r"[%s]?%s$" % (COMMENT_CHARACTERS, pycam.Gui.Settings.ToolpathSettings.META_MARKER_END)
REGEX_META_KEYWORDS = r"[%s]?%s (.*): (.*)$" % (COMMENT_CHARACTERS,
pycam.Gui.Project.ProjectGui.META_DATA_PREFIX)
REGEX_SETTINGS_START = r"[%s]?%s$" % (COMMENT_CHARACTERS,
pycam.Gui.Settings.ToolpathSettings.META_MARKER_START)
REGEX_SETTINGS_END = r"[%s]?%s$" % (COMMENT_CHARACTERS,
pycam.Gui.Settings.ToolpathSettings.META_MARKER_END)
log = pycam.Utils.log.get_logger()
def parseToolpathSettings(filename):
def parse_toolpath_settings(filename):
""" parse potential PyCAM settings from a given file
This is mainly useful to retrieve task settings from a GCode file.
@value filename: the name of the file to be read
@type filename: str
@returns: a dictionary (of all setting names and values) and the content
of the 'comment' section (as a single string)
@rtype: tuple(dict, str)
"""
keywords = {}
in_meta_zone = False
meta_content = []
try:
f = open(filename,"r")
infile = open(filename,"r")
except IOError, err_msg:
log.warn("ToolpathSettingsParser: Failed to read file (%s): %s" % \
(filename, err_msg))
return None
for line in f.readlines():
for line in infile.readlines():
match = re.match(REGEX_META_KEYWORDS, line)
if match:
keywords[match.groups()[0]] = match.groups()[1].strip()
......@@ -56,8 +71,10 @@ def parseToolpathSettings(filename):
if re.match(REGEX_SETTINGS_START, line):
in_meta_zone = True
meta_content.append([])
infile.close()
return keywords, [os.linesep.join(one_block) for one_block in meta_content]
if __name__ == "__main__":
print "\n#########################\n".join(parseToolpathSettings(sys.argv[1])[1])
# for testing: output the parsed content of the given file (first argument)
print "\n#################\n".join(parse_toolpath_settings(sys.argv[1])[1])
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