mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-04-09 17:50:20 +02:00
general: Make pywal compatible with python 3.5
This commit is contained in:
parent
d9a0865277
commit
d98be353ec
@ -84,14 +84,14 @@ def process_args(args):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if args.v:
|
if args.v:
|
||||||
print(f"wal {__version__}")
|
print("wal %s" % __version__)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if args.q:
|
if args.q:
|
||||||
sys.stdout = sys.stderr = open(os.devnull, "w")
|
sys.stdout = sys.stderr = open(os.devnull, "w")
|
||||||
|
|
||||||
if args.c:
|
if args.c:
|
||||||
shutil.rmtree(CACHE_DIR / "schemes", ignore_errors=True)
|
shutil.rmtree(str(CACHE_DIR / "schemes"), ignore_errors=True)
|
||||||
|
|
||||||
if args.r:
|
if args.r:
|
||||||
reload.colors(args.t)
|
reload.colors(args.t)
|
||||||
|
@ -73,7 +73,7 @@ def sort_colors(img, colors):
|
|||||||
colors_special.update({"cursor": raw_colors[15]})
|
colors_special.update({"cursor": raw_colors[15]})
|
||||||
|
|
||||||
for index, color in enumerate(raw_colors):
|
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["special"] = colors_special
|
||||||
colors["colors"] = colors_hex
|
colors["colors"] = colors_hex
|
||||||
|
@ -45,7 +45,7 @@ def every(colors, output_dir=CACHE_DIR):
|
|||||||
all_colors = flatten_colors(colors)
|
all_colors = flatten_colors(colors)
|
||||||
output_dir = pathlib.Path(output_dir)
|
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)
|
template(all_colors, file.path, output_dir / file.name)
|
||||||
|
|
||||||
print("export: Exported all files.")
|
print("export: Exported all files.")
|
||||||
@ -61,6 +61,6 @@ def color(colors, export_type, output_file=None):
|
|||||||
|
|
||||||
if template_file.is_file():
|
if template_file.is_file():
|
||||||
template(all_colors, template_file, output_file)
|
template(all_colors, template_file, output_file)
|
||||||
print(f"export: Exported {export_type}.")
|
print("export: Exported %s." % export_type)
|
||||||
else:
|
else:
|
||||||
print(f"[!] warning: template '{export_type}' doesn't exist.")
|
print("warning: template '%s' doesn't exist." % export_type)
|
||||||
|
@ -17,7 +17,7 @@ def get_random_image(img_dir):
|
|||||||
current_wall = os.path.basename(current_wall)
|
current_wall = os.path.basename(current_wall)
|
||||||
|
|
||||||
file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif")
|
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 img.name.endswith(file_types) and img.name != current_wall]
|
||||||
|
|
||||||
if not images:
|
if not images:
|
||||||
|
@ -15,7 +15,7 @@ def xrdb(xrdb_file=None):
|
|||||||
xrdb_file = xrdb_file or CACHE_DIR / "colors.Xresources"
|
xrdb_file = xrdb_file or CACHE_DIR / "colors.Xresources"
|
||||||
|
|
||||||
if shutil.which("xrdb"):
|
if shutil.which("xrdb"):
|
||||||
subprocess.Popen(["xrdb", "-merge", xrdb_file],
|
subprocess.Popen(["xrdb", "-merge", str(xrdb_file)],
|
||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.DEVNULL).wait()
|
stderr=subprocess.DEVNULL).wait()
|
||||||
|
|
||||||
@ -27,13 +27,13 @@ def gtk():
|
|||||||
|
|
||||||
if theme_path.is_dir():
|
if theme_path.is_dir():
|
||||||
if gtk2_file.is_file():
|
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.
|
# Here we call a Python 2 script to reload the GTK themes.
|
||||||
# This is done because the Python 3 GTK/Gdk libraries don't
|
# This is done because the Python 3 GTK/Gdk libraries don't
|
||||||
# provide a way of doing this.
|
# provide a way of doing this.
|
||||||
if shutil.which("python2"):
|
if shutil.which("python2"):
|
||||||
util.disown(["python2", MODULE_DIR / "scripts" / "gtk_reload.py"])
|
util.disown(["python2", str(MODULE_DIR / "scripts" / "gtk_reload.py")])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("warning: GTK2 reload support requires Python 2.")
|
print("warning: GTK2 reload support requires Python 2.")
|
||||||
|
@ -12,30 +12,30 @@ def set_special(index, color, iterm_name="h"):
|
|||||||
alpha = util.Color.alpha_num
|
alpha = util.Color.alpha_num
|
||||||
|
|
||||||
if OS == "Darwin":
|
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:
|
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):
|
def set_color(index, color):
|
||||||
"""Convert a hex color to a text color sequence."""
|
"""Convert a hex color to a text color sequence."""
|
||||||
if OS == "Darwin":
|
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):
|
def set_iterm_tab_color(color):
|
||||||
"""Set iTerm2 tab/window color"""
|
"""Set iTerm2 tab/window color"""
|
||||||
red, green, blue = util.hex_to_rgb(color)
|
red, green, blue = util.hex_to_rgb(color)
|
||||||
return [
|
return """
|
||||||
f"\033]6;1;bg;red;brightness;{red}\a",
|
\033]6;1;bg;red;brightness;%s\a
|
||||||
f"\033]6;1;bg;green;brightness;{green}\a",
|
\033]6;1;bg;green;brightness;%s\a
|
||||||
f"\033]6;1;bg;blue;brightness;{blue}\a",
|
\033]6;1;bg;blue;brightness;%s\a
|
||||||
]
|
""" % (red, green, blue)
|
||||||
|
|
||||||
|
|
||||||
def create_sequences(colors, vte):
|
def create_sequences(colors, vte):
|
||||||
|
@ -21,7 +21,7 @@ class Color:
|
|||||||
def rgb(self):
|
def rgb(self):
|
||||||
"""Convert a hex color to rgb."""
|
"""Convert a hex color to rgb."""
|
||||||
red, green, blue = hex_to_rgb(self.hex_color)
|
red, green, blue = hex_to_rgb(self.hex_color)
|
||||||
return f"{red},{green},{blue}"
|
return "%s,%s,%s" % (red, green, blue)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def xrgba(self):
|
def xrgba(self):
|
||||||
@ -31,19 +31,19 @@ class Color:
|
|||||||
@property
|
@property
|
||||||
def alpha(self):
|
def alpha(self):
|
||||||
"""Add URxvt alpha value to color."""
|
"""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):
|
def read_file(input_file):
|
||||||
"""Read data from a file and trim newlines."""
|
"""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()
|
data = file.read().splitlines()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def read_file_json(input_file):
|
def read_file_json(input_file):
|
||||||
"""Read data from a json 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)
|
data = json.load(json_file)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -52,27 +52,27 @@ def read_file_json(input_file):
|
|||||||
def read_file_raw(input_file):
|
def read_file_raw(input_file):
|
||||||
"""Read data from a file as is, don't strip
|
"""Read data from a file as is, don't strip
|
||||||
newlines or other special characters.."""
|
newlines or other special characters.."""
|
||||||
with open(input_file, "r") as file:
|
with open(str(input_file), "r") as file:
|
||||||
data = file.readlines()
|
data = file.readlines()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def save_file(data, export_file):
|
def save_file(data, export_file):
|
||||||
"""Write data to a file."""
|
"""Write data to a file."""
|
||||||
create_dir(os.path.dirname(export_file))
|
create_dir(export_file.parent)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(export_file, "w") as file:
|
with open(str(export_file), "w") as file:
|
||||||
file.write(data)
|
file.write(data)
|
||||||
except PermissionError:
|
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):
|
def save_file_json(data, export_file):
|
||||||
"""Write data to a json 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)
|
json.dump(data, file, indent=4)
|
||||||
|
|
||||||
|
|
||||||
@ -88,13 +88,13 @@ def hex_to_rgb(color):
|
|||||||
|
|
||||||
def hex_to_xrgba(color):
|
def hex_to_xrgba(color):
|
||||||
"""Convert a hex color to xrdb rgba."""
|
"""Convert a hex color to xrdb rgba."""
|
||||||
col = color.lower()
|
col = color.lower().strip("#")
|
||||||
return f"{col[1]}{col[2]}/{col[3]}{col[4]}/{col[5]}{col[6]}/ff"
|
return "%s%s/%s%s/%s%s/ff" % (*col,)
|
||||||
|
|
||||||
|
|
||||||
def rgb_to_hex(color):
|
def rgb_to_hex(color):
|
||||||
"""Convert an rgb color to hex."""
|
"""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):
|
def darken_color(color, amount):
|
||||||
|
@ -84,7 +84,7 @@ def set_desktop_wallpaper(desktop, img):
|
|||||||
def set_mac_wallpaper(img):
|
def set_mac_wallpaper(img):
|
||||||
"""Set the wallpaper on macOS."""
|
"""Set the wallpaper on macOS."""
|
||||||
db_file = HOME / "Library/Application Support/Dock/desktoppicture.db"
|
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.
|
# Kill the dock to fix issues with cached wallpapers.
|
||||||
# macOS caches wallpapers and if a wallpaper is set that shares
|
# macOS caches wallpapers and if a wallpaper is set that shares
|
||||||
|
@ -43,7 +43,7 @@ class TestExportColors(unittest.TestCase):
|
|||||||
|
|
||||||
def test_invalid_template(self):
|
def test_invalid_template(self):
|
||||||
"""> Test template validation."""
|
"""> 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
|
# Since this function prints a message on fail we redirect
|
||||||
# it's output so that we can read it.
|
# it's output so that we can read it.
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from pywal import __main__
|
from pywal import __main__
|
||||||
from pywal import reload
|
from pywal import reload
|
||||||
from pywal.settings import CACHE_DIR
|
from pywal.settings import CACHE_DIR
|
||||||
@ -14,7 +16,7 @@ class TestMain(unittest.TestCase):
|
|||||||
"""> Test arg parsing (-c)"""
|
"""> Test arg parsing (-c)"""
|
||||||
args = __main__.get_args(["-c"])
|
args = __main__.get_args(["-c"])
|
||||||
__main__.process_args(args)
|
__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):
|
def test_args_e(self):
|
||||||
"""> Test arg parsing (-e)"""
|
"""> Test arg parsing (-e)"""
|
||||||
|
@ -32,7 +32,8 @@ class Testsequences(unittest.TestCase):
|
|||||||
def test_set_iterm_tab_color(self):
|
def test_set_iterm_tab_color(self):
|
||||||
"""> Create iterm tab color sequences"""
|
"""> Create iterm tab color sequences"""
|
||||||
result = sequences.set_iterm_tab_color(COLORS["special"]["background"])
|
result = sequences.set_iterm_tab_color(COLORS["special"]["background"])
|
||||||
self.assertEqual(len(result), 3)
|
print(result)
|
||||||
|
self.assertEqual(len(result), 104)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -49,10 +49,9 @@ class TestUtil(unittest.TestCase):
|
|||||||
|
|
||||||
def test_create_dir(self):
|
def test_create_dir(self):
|
||||||
"""> Create a directory."""
|
"""> Create a directory."""
|
||||||
tmp_dir = pathlib.Path("/tmp/test_dir")
|
tmp_dir = "/tmp/test_dir"
|
||||||
util.create_dir(tmp_dir)
|
util.create_dir(tmp_dir)
|
||||||
result = tmp_dir.is_dir()
|
self.assertTrue(os.path.isdir(tmp_dir))
|
||||||
self.assertTrue(result)
|
|
||||||
os.rmdir(tmp_dir)
|
os.rmdir(tmp_dir)
|
||||||
|
|
||||||
def test_hex_to_rgb_black(self):
|
def test_hex_to_rgb_black(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user