summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordgrisham <dgrisham@mines.edu>2018-09-27 10:15:21 -0600
committerdgrisham <dgrisham@mines.edu>2018-09-27 10:18:28 -0600
commit499b1c4ff5b90a754384a5ca91b770d062d76db8 (patch)
tree1a3d7f67ca0180ce013f28a06f57b2c2567fbfd3
parent33c82904527db34965225b6bd3940ade51915dae (diff)
feat: hash file for cache filename
rebase me
-rw-r--r--pywal/colors.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/pywal/colors.py b/pywal/colors.py
index a87ee4c..b0cfbe6 100644
--- a/pywal/colors.py
+++ b/pywal/colors.py
@@ -6,6 +6,7 @@ import os
import random
import re
import sys
+import hashlib
from . import theme
from . import util
@@ -86,12 +87,19 @@ def saturate_colors(colors, amount):
def cache_fname(img, backend, light, cache_dir, sat=""):
"""Create the cache file name."""
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,)]
+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):
"""Figure out which backend to use."""
if backend == "random":