summaryrefslogtreecommitdiff
path: root/pywal/util.py
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-08-09 11:22:51 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-08-09 11:22:51 +1000
commitd98be353ecd5deff97804312ec798fb227adfbc1 (patch)
tree84491474f6e0648dea3a7689f0626a4809492007 /pywal/util.py
parentd9a0865277dfdfe7951b9b429d5af1f2be27d66c (diff)
general: Make pywal compatible with python 3.5
Diffstat (limited to 'pywal/util.py')
-rw-r--r--pywal/util.py26
1 files changed, 13 insertions, 13 deletions
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):