diff --git a/pywal/__main__.py b/pywal/__main__.py index 69908fe..0935916 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -14,7 +14,7 @@ import os import shutil import sys -from .settings import __version__, __cache_dir__ +from .settings import __version__, CACHE_DIR from . import colors from . import export from . import image @@ -85,7 +85,7 @@ def process_args(args): sys.stdout = sys.stderr = open(os.devnull, "w") if args.c: - shutil.rmtree(__cache_dir__ / "schemes", ignore_errors=True) + shutil.rmtree(CACHE_DIR / "schemes", ignore_errors=True) if args.r: reload.colors(args.t) diff --git a/pywal/colors.py b/pywal/colors.py index 18a237a..c939215 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -5,7 +5,7 @@ import re import shutil import subprocess -from .settings import __cache_dir__, __color_count__ +from .settings import CACHE_DIR, COLOR_COUNT from . import util @@ -72,8 +72,8 @@ def sort_colors(img, colors): return colors -def get(img, cache_dir=__cache_dir__, - color_count=__color_count__, notify=False): +def get(img, cache_dir=CACHE_DIR, + color_count=COLOR_COUNT, notify=False): """Get the colorscheme.""" # _home_dylan_img_jpg.json cache_file = cache_dir / "schemes" / \ diff --git a/pywal/export.py b/pywal/export.py index 316de7b..f727466 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -4,13 +4,10 @@ Export colors in various formats. import os import pathlib -from .settings import __cache_dir__ +from .settings import CACHE_DIR, MODULE_DIR from . import util -TEMPLATE_DIR = pathlib.Path(__file__).parent / "templates" - - def template(colors, input_file, output_file=None): """Read template file, substitute markers and save the file elsewhere.""" @@ -42,12 +39,12 @@ def get_export_type(export_type): }.get(export_type, export_type) -def every(colors, output_dir=__cache_dir__): +def every(colors, output_dir=CACHE_DIR): """Export all template files.""" all_colors = flatten_colors(colors) output_dir = pathlib.Path(output_dir) - for file in os.scandir(TEMPLATE_DIR): + for file in os.scandir(MODULE_DIR / "templates"): template(all_colors, file.path, output_dir / file.name) print(f"export: Exported all files.") @@ -58,8 +55,8 @@ def color(colors, export_type, output_file=None): all_colors = flatten_colors(colors) template_name = get_export_type(export_type) - template_file = TEMPLATE_DIR / template_name - output_file = output_file or __cache_dir__ / template_name + template_file = MODULE_DIR / "templates" / template_name + output_file = output_file or CACHE_DIR / template_name if template_file.is_file(): template(all_colors, template_file, output_file) diff --git a/pywal/image.py b/pywal/image.py index eec05f6..7c51ae0 100644 --- a/pywal/image.py +++ b/pywal/image.py @@ -5,7 +5,7 @@ import os import pathlib import random -from .settings import __cache_dir__ +from .settings import CACHE_DIR from . import util from . import wallpaper @@ -26,7 +26,7 @@ def get_random_image(img_dir): return str(img_dir / random.choice(images).name) -def get(img, cache_dir=__cache_dir__): +def get(img, cache_dir=CACHE_DIR): """Validate image input.""" image = pathlib.Path(img) diff --git a/pywal/reload.py b/pywal/reload.py index 36c3770..2c18559 100644 --- a/pywal/reload.py +++ b/pywal/reload.py @@ -1,18 +1,17 @@ """ Reload programs. """ -import pathlib import re import shutil import subprocess -from .settings import __cache_dir__ +from .settings import CACHE_DIR, HOME, MODULE_DIR from . import util def xrdb(xrdb_file=None): """Merge the colors into the X db so new terminals use them.""" - xrdb_file = xrdb_file or __cache_dir__ / "colors.Xresources" + xrdb_file = xrdb_file or CACHE_DIR / "colors.Xresources" if shutil.which("xrdb"): subprocess.call(["xrdb", "-merge", xrdb_file], @@ -22,9 +21,8 @@ def xrdb(xrdb_file=None): def gtk(): """Move gtkrc files to the correct location.""" - home = pathlib.Path.home() - theme_path = home / ".themes" / "Flatabulous-wal" - gtk2_file = __cache_dir__ / "colors-gtk2.rc" + theme_path = HOME / ".themes" / "Flatabulous-wal" + gtk2_file = CACHE_DIR / "colors-gtk2.rc" if theme_path.is_dir(): if gtk2_file.is_file(): @@ -34,8 +32,7 @@ def gtk(): # This is done because the Python 3 GTK/Gdk libraries don't # provide a way of doing this. if shutil.which("python2"): - module_dir = pathlib.Path(__file__).parent - util.disown("python2", module_dir / "scripts" / "gtk_reload.py") + util.disown("python2", MODULE_DIR / "scripts" / "gtk_reload.py") def i3(): @@ -52,14 +49,14 @@ def polybar(): def env(xrdb_file=None): """Reload environment.""" - xrdb(xrdb_file) gtk() + xrdb(xrdb_file) i3() polybar() print("reload: Reloaded environment.") -def colors(vte, cache_dir=__cache_dir__): +def colors(vte, cache_dir=CACHE_DIR): """Reload the current scheme.""" sequence_file = cache_dir / "sequences" diff --git a/pywal/sequences.py b/pywal/sequences.py index 4f14234..4e1457d 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -3,7 +3,7 @@ Send sequences to all open terminals. """ import os -from .settings import __cache_dir__ +from .settings import CACHE_DIR from . import util @@ -22,7 +22,7 @@ def set_color(index, color): return f"\033]4;{index};{color}\007" -def send(colors, vte, cache_dir=__cache_dir__): +def send(colors, vte, cache_dir=CACHE_DIR): """Send colors to all open terminals.""" # Colors 0-15. sequences = [set_color(num, color) diff --git a/pywal/settings.py b/pywal/settings.py index 431d8b0..626f83a 100644 --- a/pywal/settings.py +++ b/pywal/settings.py @@ -11,6 +11,11 @@ Created by Dylan Araps. import pathlib + __version__ = "0.5.0" -__cache_dir__ = pathlib.Path.home() / ".cache/wal/" -__color_count__ = 16 + + +HOME = pathlib.Path.home() +CACHE_DIR = HOME / ".cache/wal/" +MODULE_DIR = pathlib.Path(__file__).parent +COLOR_COUNT = 16 diff --git a/pywal/wallpaper.py b/pywal/wallpaper.py index 836a2c6..f9d6c1e 100644 --- a/pywal/wallpaper.py +++ b/pywal/wallpaper.py @@ -3,7 +3,7 @@ import os import shutil import subprocess -from .settings import __cache_dir__ +from .settings import CACHE_DIR from . import util @@ -97,7 +97,7 @@ def change(img): print("wallpaper: Set the new wallpaper") -def get(cache_dir=__cache_dir__): +def get(cache_dir=CACHE_DIR): """Get the current wallpaper.""" current_wall = cache_dir / "wal" diff --git a/tests/test_main.py b/tests/test_main.py index ad0f6fe..4dbe580 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,7 +2,7 @@ import unittest from pywal import __main__ -from pywal.settings import __cache_dir__ +from pywal.settings import CACHE_DIR class TestMain(unittest.TestCase): @@ -12,7 +12,7 @@ class TestMain(unittest.TestCase): """> Test arg parsing (-c)""" args = __main__.get_args(["-c"]) __main__.process_args(args) - self.assertFalse((__cache_dir__ / "schemes").is_dir()) + self.assertFalse((CACHE_DIR / "schemes").is_dir()) if __name__ == "__main__":