mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-05-19 15:50:50 +02:00
Added image checksum to colorschemes
This commit is contained in:
parent
16e0aadbf5
commit
bbce8e638b
@ -30,6 +30,7 @@ def normalize_img_path(img: str):
|
||||
def colors_to_dict(colors, img):
|
||||
"""Convert list of colors to pywal format."""
|
||||
return {
|
||||
"checksum": util.get_img_checksum(img),
|
||||
"wallpaper": normalize_img_path(img),
|
||||
"alpha": util.Color.alpha_num,
|
||||
|
||||
@ -132,7 +133,7 @@ def get(img, light=False, backend="wal", cache_dir=CACHE_DIR, sat=""):
|
||||
cache_name = cache_fname(img, backend, light, cache_dir, sat)
|
||||
cache_file = os.path.join(*cache_name)
|
||||
|
||||
if os.path.isfile(cache_file):
|
||||
if os.path.isfile(cache_file) and theme.parse(cache_file)["checksum"] == util.get_img_checksum(img):
|
||||
colors = theme.file(cache_file)
|
||||
colors["alpha"] = util.Color.alpha_num
|
||||
logging.info("Found cached colorscheme.")
|
||||
|
@ -78,6 +78,9 @@ def parse(theme_file):
|
||||
"""Parse the theme file."""
|
||||
data = util.read_file_json(theme_file)
|
||||
|
||||
if "checksum" not in data:
|
||||
data["checksum"] = "None"
|
||||
|
||||
if "wallpaper" not in data:
|
||||
data["wallpaper"] = "None"
|
||||
|
||||
|
@ -10,6 +10,7 @@ import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from hashlib import md5
|
||||
|
||||
|
||||
class Color:
|
||||
@ -141,6 +142,13 @@ def save_file_json(data, export_file):
|
||||
with open(export_file, "w") as file:
|
||||
json.dump(data, file, indent=4)
|
||||
|
||||
def get_img_checksum(img):
|
||||
checksum = md5()
|
||||
with open(img, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(4096), b""):
|
||||
checksum.update(chunk)
|
||||
return checksum.hexdigest()
|
||||
|
||||
|
||||
def create_dir(directory):
|
||||
"""Alias to create the cache dir."""
|
||||
|
Loading…
Reference in New Issue
Block a user