diff options
Diffstat (limited to 'pywal/export.py')
| -rw-r--r-- | pywal/export.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/pywal/export.py b/pywal/export.py index f7b9de8..4c0649f 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -19,29 +19,35 @@ def template(colors, input_file, output_file=None): for match in matches: # Get the color, and the functions associated with it color, _, funcs = match.group(2).partition(".") - #Check that functions are needed for this color + # Check that functions are needed for this color if len(funcs) != 0: - #Build up a string which will be replaced when the color is done processing + # Build up a string which will be replaced when the color is done processing replace_str = color - #The modified color + # The modified color new_color = colors[color] - #Execute each function to be done - for func in filter(None,funcs.split(")")): - ### Get function name and arguments + # Execute each function to be done + for func in filter(None, funcs.split(")")): + # Get function name and arguments func_split = func.split("(") args = [] - if len(func_split) > 1: args = func_split[1].split(",") + if len(func_split) > 1: + args = func_split[1].split(",") fname = func_split[0] - if fname[0] == '.': fname = fname[1:] + if fname[0] == '.': + fname = fname[1:] + if not hasattr(new_color, fname): + logging.error( + "Syntax error in template file '%s' on line '%s'", input_file, i) f = getattr(new_color, fname) # If the function is callable, call it if callable(f): new_color = f(*args) - #add to the string that will replace the function calls with the generated function. - if func[0] != '.': replace_str += "." + # add to the string that will replace the function calls with the generated function. + if func[0] != '.': + replace_str += "." replace_str += func + ")" - #If the color was changed, replace the template with a unique identifier for the new color. + # If the color was changed, replace the template with a unique identifier for the new color. if not new_color is colors[color]: cname = "color" + new_color.strip template_data[i] = line.replace(replace_str, cname) |
