summaryrefslogtreecommitdiff
path: root/pywal/export.py
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-30 09:54:10 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-30 09:54:10 +1000
commit615321de942ac4d75af72ba126ac5b69da203a72 (patch)
treefd13cb143ac508fb36bdbbb14729e0dc8be9d014 /pywal/export.py
parent453d0cfa39e3b02ab6be6131b37050b3e6eca539 (diff)
general: Rename export_colors to export.
Diffstat (limited to 'pywal/export.py')
-rwxr-xr-xpywal/export.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/pywal/export.py b/pywal/export.py
new file mode 100755
index 0000000..29e0067
--- /dev/null
+++ b/pywal/export.py
@@ -0,0 +1,47 @@
+"""
+Export colors in various formats.
+"""
+import os
+
+from pywal.settings import CACHE_DIR
+from pywal import util
+
+
+def template(colors, input_file, output_dir):
+ """Read template file, substitute markers and
+ save the file elsewhere."""
+ # Get the template name.
+ template_file = os.path.basename(input_file)
+
+ # Import the template.
+ with open(input_file) as file:
+ template_data = file.readlines()
+
+ # Format the markers.
+ template_data = "".join(template_data).format(**colors)
+
+ # Export the template.
+ output_file = output_dir / template_file
+ util.save_file(template_data, output_file)
+
+ print(f"export: Exported {template_file}.")
+
+
+def export_all_templates(colors, template_dir=None, output_dir=CACHE_DIR):
+ """Export all template files."""
+
+ # Add the template dir to module path.
+ template_dir = template_dir or \
+ os.path.join(os.path.dirname(__file__), "templates")
+
+ # Merge all colors (specials and normals) into one dict so we can access
+ # their values simpler.
+ all_colors = {**colors["special"], **colors["colors"]}
+
+ # Turn all those colors into util.Color instances for accessing the
+ # .hex and .rgb formats
+ all_colors = {k: util.Color(v) for k, v in all_colors.items()}
+
+ # pylint: disable=W0106
+ [template(all_colors, file.path, output_dir)
+ for file in os.scandir(template_dir)]