diff --git a/pywal/__main__.py b/pywal/__main__.py index dbca515..412a6d4 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -84,14 +84,14 @@ def process_args(args): sys.exit(1) if args.v: - print(f"wal {__version__}") + print("wal %s" % __version__) sys.exit(0) if args.q: sys.stdout = sys.stderr = open(os.devnull, "w") if args.c: - shutil.rmtree(CACHE_DIR / "schemes", ignore_errors=True) + shutil.rmtree(str(CACHE_DIR / "schemes"), ignore_errors=True) if args.r: reload.colors(args.t) diff --git a/pywal/colors.py b/pywal/colors.py index 2483acd..7a1a991 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -73,7 +73,7 @@ def sort_colors(img, colors): colors_special.update({"cursor": raw_colors[15]}) for index, color in enumerate(raw_colors): - colors_hex.update({f"color{index}": color}) + colors_hex.update({"color%s" % index: color}) colors["special"] = colors_special colors["colors"] = colors_hex diff --git a/pywal/export.py b/pywal/export.py index 748e3a9..d621672 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -45,7 +45,7 @@ def every(colors, output_dir=CACHE_DIR): all_colors = flatten_colors(colors) output_dir = pathlib.Path(output_dir) - for file in os.scandir(MODULE_DIR / "templates"): + for file in os.scandir(str(MODULE_DIR / "templates")): template(all_colors, file.path, output_dir / file.name) print("export: Exported all files.") @@ -61,6 +61,6 @@ def color(colors, export_type, output_file=None): if template_file.is_file(): template(all_colors, template_file, output_file) - print(f"export: Exported {export_type}.") + print("export: Exported %s." % export_type) else: - print(f"[!] warning: template '{export_type}' doesn't exist.") + print("warning: template '%s' doesn't exist." % export_type) diff --git a/pywal/image.py b/pywal/image.py index 787bb80..e55a0b1 100644 --- a/pywal/image.py +++ b/pywal/image.py @@ -17,7 +17,7 @@ def get_random_image(img_dir): current_wall = os.path.basename(current_wall) file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif") - images = [img for img in os.scandir(img_dir) + images = [img for img in os.scandir(str(img_dir)) if img.name.endswith(file_types) and img.name != current_wall] if not images: diff --git a/pywal/reload.py b/pywal/reload.py index f284966..11d048f 100644 --- a/pywal/reload.py +++ b/pywal/reload.py @@ -15,7 +15,7 @@ def xrdb(xrdb_file=None): xrdb_file = xrdb_file or CACHE_DIR / "colors.Xresources" if shutil.which("xrdb"): - subprocess.Popen(["xrdb", "-merge", xrdb_file], + subprocess.Popen(["xrdb", "-merge", str(xrdb_file)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).wait() @@ -27,13 +27,13 @@ def gtk(): if theme_path.is_dir(): if gtk2_file.is_file(): - shutil.copy(gtk2_file, theme_path / "gtk-2.0") + shutil.copy(str(gtk2_file), str(theme_path / "gtk-2.0")) # Here we call a Python 2 script to reload the GTK themes. # This is done because the Python 3 GTK/Gdk libraries don't # provide a way of doing this. if shutil.which("python2"): - util.disown(["python2", MODULE_DIR / "scripts" / "gtk_reload.py"]) + util.disown(["python2", str(MODULE_DIR / "scripts" / "gtk_reload.py")]) else: print("warning: GTK2 reload support requires Python 2.") diff --git a/pywal/sequences.py b/pywal/sequences.py index b94bd93..87339d9 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -12,30 +12,30 @@ def set_special(index, color, iterm_name="h"): alpha = util.Color.alpha_num if OS == "Darwin": - return f"\033]P{iterm_name}{color.strip('#')}\033\\" + return "\033[P%s%s\033\\" % (iterm_name, color.strip("#")) if index in [11, 708] and alpha != 100: - return f"\033]{index};[{alpha}]{color}\007" + return "\033]%s;[%s]%s\007" % (index, alpha, color) - return f"\033]{index};{color}\007" + return "\033]%s;%s\007" % (index, color) def set_color(index, color): """Convert a hex color to a text color sequence.""" if OS == "Darwin": - return f"\033]P{index:x}{color.strip('#')}\033\\" + return "\033]P%x%s\033\\" % (index, color.strip("#")) - return f"\033]4;{index};{color}\007" + return "\033]4;%s;%s\007" % (index, color) def set_iterm_tab_color(color): """Set iTerm2 tab/window color""" red, green, blue = util.hex_to_rgb(color) - return [ - f"\033]6;1;bg;red;brightness;{red}\a", - f"\033]6;1;bg;green;brightness;{green}\a", - f"\033]6;1;bg;blue;brightness;{blue}\a", - ] + return """ + \033]6;1;bg;red;brightness;%s\a + \033]6;1;bg;green;brightness;%s\a + \033]6;1;bg;blue;brightness;%s\a + """ % (red, green, blue) def create_sequences(colors, vte): diff --git a/pywal/util.py b/pywal/util.py index 9931958..411d459 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -21,7 +21,7 @@ class Color: def rgb(self): """Convert a hex color to rgb.""" red, green, blue = hex_to_rgb(self.hex_color) - return f"{red},{green},{blue}" + return "%s,%s,%s" % (red, green, blue) @property def xrgba(self): @@ -31,19 +31,19 @@ class Color: @property def alpha(self): """Add URxvt alpha value to color.""" - return f"[{self.alpha_num}]{self.hex_color}" + return "[%s]%s" % (self.alpha_num, self.hex_color) def read_file(input_file): """Read data from a file and trim newlines.""" - with open(input_file, "r") as file: + with open(str(input_file), "r") as file: data = file.read().splitlines() return data def read_file_json(input_file): """Read data from a json file.""" - with open(input_file, "r") as json_file: + with open(str(input_file), "r") as json_file: data = json.load(json_file) return data @@ -52,27 +52,27 @@ def read_file_json(input_file): def read_file_raw(input_file): """Read data from a file as is, don't strip newlines or other special characters..""" - with open(input_file, "r") as file: + with open(str(input_file), "r") as file: data = file.readlines() return data def save_file(data, export_file): """Write data to a file.""" - create_dir(os.path.dirname(export_file)) + create_dir(export_file.parent) try: - with open(export_file, "w") as file: + with open(str(export_file), "w") as file: file.write(data) except PermissionError: - print(f"[!] warning: Couldn't write to {export_file}.") + print("warning: Couldn't write to %s." % export_file) def save_file_json(data, export_file): """Write data to a json file.""" - create_dir(os.path.dirname(export_file)) + create_dir(export_file.parent) - with open(export_file, "w") as file: + with open(str(export_file), "w") as file: json.dump(data, file, indent=4) @@ -88,13 +88,13 @@ def hex_to_rgb(color): def hex_to_xrgba(color): """Convert a hex color to xrdb rgba.""" - col = color.lower() - return f"{col[1]}{col[2]}/{col[3]}{col[4]}/{col[5]}{col[6]}/ff" + col = color.lower().strip("#") + return "%s%s/%s%s/%s%s/ff" % (*col,) def rgb_to_hex(color): """Convert an rgb color to hex.""" - return f"#{color[0]:02x}{color[1]:02x}{color[2]:02x}" + return "#%02x%02x%02x" % (*color,) def darken_color(color, amount): diff --git a/pywal/wallpaper.py b/pywal/wallpaper.py index f1ce1dd..79234be 100644 --- a/pywal/wallpaper.py +++ b/pywal/wallpaper.py @@ -84,7 +84,7 @@ def set_desktop_wallpaper(desktop, img): def set_mac_wallpaper(img): """Set the wallpaper on macOS.""" db_file = HOME / "Library/Application Support/Dock/desktoppicture.db" - subprocess.call(["sqlite3", db_file, f"update data set value = '{img}'"]) + subprocess.call(["sqlite3", db_file, "update data set value = '%s'" % img]) # Kill the dock to fix issues with cached wallpapers. # macOS caches wallpapers and if a wallpaper is set that shares diff --git a/tests/test_export.py b/tests/test_export.py index 2323c69..e2838fe 100755 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -43,7 +43,7 @@ class TestExportColors(unittest.TestCase): def test_invalid_template(self): """> Test template validation.""" - error_msg = "[!] warning: template 'dummy' doesn't exist." + error_msg = "warning: template 'dummy' doesn't exist." # Since this function prints a message on fail we redirect # it's output so that we can read it. diff --git a/tests/test_main.py b/tests/test_main.py index 9262c8f..7f1a1bb 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,6 +2,8 @@ import unittest from unittest.mock import MagicMock +import os + from pywal import __main__ from pywal import reload from pywal.settings import CACHE_DIR @@ -14,7 +16,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(os.path.isdir(str(CACHE_DIR / "schemes"))) def test_args_e(self): """> Test arg parsing (-e)""" diff --git a/tests/test_sequences.py b/tests/test_sequences.py index 66f4084..392abc7 100755 --- a/tests/test_sequences.py +++ b/tests/test_sequences.py @@ -32,7 +32,8 @@ class Testsequences(unittest.TestCase): def test_set_iterm_tab_color(self): """> Create iterm tab color sequences""" result = sequences.set_iterm_tab_color(COLORS["special"]["background"]) - self.assertEqual(len(result), 3) + print(result) + self.assertEqual(len(result), 104) if __name__ == "__main__": diff --git a/tests/test_util.py b/tests/test_util.py index bc551ef..aae0356 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -49,10 +49,9 @@ class TestUtil(unittest.TestCase): def test_create_dir(self): """> Create a directory.""" - tmp_dir = pathlib.Path("/tmp/test_dir") + tmp_dir = "/tmp/test_dir" util.create_dir(tmp_dir) - result = tmp_dir.is_dir() - self.assertTrue(result) + self.assertTrue(os.path.isdir(tmp_dir)) os.rmdir(tmp_dir) def test_hex_to_rgb_black(self):