general: Remove all pathlib usage

This commit is contained in:
Dylan Araps 2017-08-10 09:23:50 +10:00
parent b1abb37f8c
commit c61960722d
3 changed files with 12 additions and 13 deletions

View file

@ -16,7 +16,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(str(img_dir))
images = [img for img in os.scandir(img_dir)
if img.name.endswith(file_types) and img.name != current_wall]
if not images:

View file

@ -35,14 +35,14 @@ class Color:
def read_file(input_file):
"""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()
return data
def read_file_json(input_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)
return data
@ -51,17 +51,17 @@ 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(str(input_file), "r") as file:
with open(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(str(export_file)))
create_dir(os.path.dirname(export_file))
try:
with open(str(export_file), "w") as file:
with open(export_file, "w") as file:
file.write(data)
except PermissionError:
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):
"""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)

View file

@ -1,7 +1,6 @@
"""Test util functions."""
import unittest
import os
import pathlib
from pywal import util
@ -35,16 +34,16 @@ class TestUtil(unittest.TestCase):
def test_save_file(self):
"""> Save colors to a file."""
tmp_file = pathlib.Path("/tmp/test_file")
tmp_file = "/tmp/test_file"
util.save_file("Hello, world", tmp_file)
result = tmp_file.is_file()
result = os.path.isfile(tmp_file)
self.assertTrue(result)
def test_save_file_json(self):
"""> 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)
result = tmp_file.is_file()
result = os.path.isfile(tmp_file)
self.assertTrue(result)
def test_create_dir(self):