mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-05-20 16:20:53 +02:00
feat: hash file for cache filename
rebase me
This commit is contained in:
parent
33c8290452
commit
499b1c4ff5
@ -6,6 +6,7 @@ import os
|
|||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import hashlib
|
||||||
|
|
||||||
from . import theme
|
from . import theme
|
||||||
from . import util
|
from . import util
|
||||||
@ -86,12 +87,19 @@ def saturate_colors(colors, amount):
|
|||||||
def cache_fname(img, backend, light, cache_dir, sat=""):
|
def cache_fname(img, backend, light, cache_dir, sat=""):
|
||||||
"""Create the cache file name."""
|
"""Create the cache file name."""
|
||||||
color_type = "light" if light else "dark"
|
color_type = "light" if light else "dark"
|
||||||
file_name = re.sub("[/|\\|.]", "_", img)
|
file_hash = hashf(img)
|
||||||
|
|
||||||
file_parts = [file_name, color_type, backend, sat, __cache_version__]
|
file_parts = [file_hash, color_type, backend, sat, __cache_version__]
|
||||||
return [cache_dir, "schemes", "%s_%s_%s_%s_%s.json" % (*file_parts,)]
|
return [cache_dir, "schemes", "%s_%s_%s_%s_%s.json" % (*file_parts,)]
|
||||||
|
|
||||||
|
|
||||||
|
def hashf(fpath):
|
||||||
|
return hashlib.md5(file_bytes(open(fpath, 'rb'))).hexdigest()
|
||||||
|
|
||||||
|
def file_bytes(fpath):
|
||||||
|
with fpath:
|
||||||
|
return fpath.read()
|
||||||
|
|
||||||
def get_backend(backend):
|
def get_backend(backend):
|
||||||
"""Figure out which backend to use."""
|
"""Figure out which backend to use."""
|
||||||
if backend == "random":
|
if backend == "random":
|
||||||
|
Loading…
Reference in New Issue
Block a user