From 27dff31cbd11f5cb397887f74152452e182333eb Mon Sep 17 00:00:00 2001 From: Loic Coyle Date: Sun, 9 Feb 2020 21:33:51 +0100 Subject: fix template issue --- pywal/export.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'pywal') diff --git a/pywal/export.py b/pywal/export.py index 0c71a76..b9a95e8 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -25,7 +25,7 @@ def template(colors, input_file, output_file=None): # Color to be modified copied into new one new_color = util.Color(colors[cname].hex_color) # Execute each function to be done - for func in filter(None, funcs.split(")")): + for func in filter(None, re.split("\)|\.", funcs)): # Get function name and arguments func = func.split("(") fname = func[0] @@ -47,11 +47,18 @@ def template(colors, input_file, output_file=None): if func[0] != '.': replace_str += "." replace_str += "(".join(func) + ")" + else: + # if it is an attribute i.e. rgb + replace_str += '.' + fname + new_color = function + + if not isinstance(new_color, str): + new_color = new_color.strip # If the color was changed, replace with a unique identifier. if new_color is not colors[cname]: - template_data[i] = l.replace( - replace_str, "color" + new_color.strip) - colors["color" + new_color.strip] = new_color + new_color_clean = new_color.replace('[', '_').replace(']', '_') + template_data[i] = l.replace(replace_str, "color" + new_color_clean) + colors["color" + new_color_clean] = new_color try: template_data = "".join(template_data).format(**colors) except ValueError: -- cgit v1.2.3 From cecc28cc5288fb80a178e456cf2e93d77f5dbd71 Mon Sep 17 00:00:00 2001 From: Loic Coyle Date: Mon, 4 May 2020 20:26:07 +0200 Subject: add pylint disable, r-string, line length, change isinstance --- pywal/export.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'pywal') diff --git a/pywal/export.py b/pywal/export.py index b9a95e8..928fbc3 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -12,6 +12,7 @@ from .settings import CACHE_DIR, CONF_DIR, MODULE_DIR def template(colors, input_file, output_file=None): """Read template file, substitute markers and save the file elsewhere.""" + # pylint: disable-msg=too-many-locals template_data = util.read_file_raw(input_file) for i, l in enumerate(template_data): for match in re.finditer(r"(?<=(?