mirror of
https://github.com/dylanaraps/pywal.git
synced 2024-11-25 09:23:08 +01: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)
|
||||
|
||||
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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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.")
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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)"""
|
||||
|
@ -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__":
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user