mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-05-30 06:28:53 +02:00
general: Remove all pathlib usage
This commit is contained in:
parent
b1abb37f8c
commit
c61960722d
@ -16,7 +16,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(str(img_dir))
|
images = [img for img in os.scandir(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:
|
||||||
|
@ -35,14 +35,14 @@ class 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(str(input_file), "r") as file:
|
with open(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(str(input_file), "r") as json_file:
|
with open(input_file, "r") as json_file:
|
||||||
data = json.load(json_file)
|
data = json.load(json_file)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -51,17 +51,17 @@ 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(str(input_file), "r") as file:
|
with open(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(str(export_file)))
|
create_dir(os.path.dirname(export_file))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(str(export_file), "w") as file:
|
with open(export_file, "w") as file:
|
||||||
file.write(data)
|
file.write(data)
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
print("warning: Couldn't write to %s." % export_file)
|
print("warning: Couldn't write to %s." % export_file)
|
||||||
@ -69,9 +69,9 @@ def save_file(data, 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(str(export_file)))
|
create_dir(os.path.dirname(export_file))
|
||||||
|
|
||||||
with open(str(export_file), "w") as file:
|
with open(export_file, "w") as file:
|
||||||
json.dump(data, file, indent=4)
|
json.dump(data, file, indent=4)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Test util functions."""
|
"""Test util functions."""
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
import pathlib
|
|
||||||
|
|
||||||
from pywal import util
|
from pywal import util
|
||||||
|
|
||||||
@ -35,16 +34,16 @@ class TestUtil(unittest.TestCase):
|
|||||||
|
|
||||||
def test_save_file(self):
|
def test_save_file(self):
|
||||||
"""> Save colors to a file."""
|
"""> Save colors to a file."""
|
||||||
tmp_file = pathlib.Path("/tmp/test_file")
|
tmp_file = "/tmp/test_file"
|
||||||
util.save_file("Hello, world", tmp_file)
|
util.save_file("Hello, world", tmp_file)
|
||||||
result = tmp_file.is_file()
|
result = os.path.isfile(tmp_file)
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
def test_save_file_json(self):
|
def test_save_file_json(self):
|
||||||
"""> Save colors to a file."""
|
"""> Save colors to a file."""
|
||||||
tmp_file = pathlib.Path("/tmp/test_file.json")
|
tmp_file = "/tmp/test_file.json"
|
||||||
util.save_file_json(COLORS, tmp_file)
|
util.save_file_json(COLORS, tmp_file)
|
||||||
result = tmp_file.is_file()
|
result = os.path.isfile(tmp_file)
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
def test_create_dir(self):
|
def test_create_dir(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user