summaryrefslogtreecommitdiff
path: root/pywal/export_colors.py
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-29 19:52:43 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-29 19:52:43 +1000
commit5e5908a01360ba36bd1c7ab3223dfef3dfedd02a (patch)
tree142f53d798ad123707acc564cb05e373be33ea60 /pywal/export_colors.py
parent4ec8c16d0afce5ae9245eec25ca234ba11841df1 (diff)
export: Make function more general for the test.
Diffstat (limited to 'pywal/export_colors.py')
-rwxr-xr-xpywal/export_colors.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/pywal/export_colors.py b/pywal/export_colors.py
index 4282124..b3c4025 100755
--- a/pywal/export_colors.py
+++ b/pywal/export_colors.py
@@ -8,24 +8,24 @@ from pywal.settings import CACHE_DIR, TEMPLATE_DIR
from pywal import util
-def template(colors, input_file):
+def template(colors, input_file, output_dir):
"""Read template file, substitute markers and
save the file elsewhere."""
- template_file = pathlib.Path(TEMPLATE_DIR).joinpath(input_file)
- export_file = pathlib.Path(CACHE_DIR).joinpath(input_file)
+ # Get the template name.
+ template_file = os.path.basename(input_file)
# Import the template.
- with open(template_file) as file:
+ with open(input_file) as file:
template_data = file.readlines()
# Format the markers.
template_data = "".join(template_data).format(**colors)
# Export the template.
- with open(export_file, "w") as file:
- file.write(template_data)
+ output_file = output_dir / template_file
+ util.save_file(template_data, output_file)
- print(f"export: Exported {input_file}.")
+ print(f"export: Exported {template_file}.")
def export_all_templates(colors):
@@ -43,10 +43,11 @@ def export_all_templates(colors):
colors_rgb = {k: util.hex_to_rgb(v) for k, v in colors["colors"].items()}
# pylint: disable=W0106
- [template(colors["colors"], file.name)
+ [template(colors["colors"], file.path, CACHE_DIR)
for file in os.scandir(TEMPLATE_DIR)
- if file not in exclude]
+ if file.name not in exclude]
# Call 'putty' manually since it needs RGB
# colors.
- template(colors_rgb, "colors-putty.reg")
+ putty_file = TEMPLATE_DIR / pathlib.Path("colors-putty.reg")
+ template(colors_rgb, putty_file, CACHE_DIR)