mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix hyphenation dicts being re-extracted unnecessarily
This commit is contained in:
parent
44923e9e45
commit
b5ae91b6a6
@ -53,19 +53,29 @@ def dictionary_name_for_locale(loc):
|
|||||||
return lmap[k]
|
return lmap[k]
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize=2)
|
||||||
|
def expected_hash():
|
||||||
|
return P('hyphenation/sha1sum', data=True, allow_user_override=False)
|
||||||
|
|
||||||
|
|
||||||
def extract_dicts(cache_path):
|
def extract_dicts(cache_path):
|
||||||
|
dict_tarball = P('hyphenation/dictionaries.tar.xz', allow_user_override=False)
|
||||||
with TemporaryDirectory(dir=cache_path) as tdir:
|
with TemporaryDirectory(dir=cache_path) as tdir:
|
||||||
try:
|
try:
|
||||||
from calibre_lzma.xz import decompress
|
from calibre_lzma.xz import decompress
|
||||||
except ImportError:
|
except ImportError:
|
||||||
tf = tarfile.open(P('hyphenation/dictionaries.tar.xz'))
|
tf = tarfile.open(dict_tarball)
|
||||||
else:
|
else:
|
||||||
buf = BytesIO()
|
buf = BytesIO()
|
||||||
decompress(P('hyphenation/dictionaries.tar.xz', data=True), outfile=buf)
|
with lopen(dict_tarball, 'rb') as f:
|
||||||
|
data = f.read()
|
||||||
|
decompress(data, outfile=buf)
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
tf = tarfile.TarFile(fileobj=buf)
|
tf = tarfile.TarFile(fileobj=buf)
|
||||||
with tf:
|
with tf:
|
||||||
tf.extractall(tdir)
|
tf.extractall(tdir)
|
||||||
|
with open(os.path.join(tdir, 'sha1sum'), 'wb') as f:
|
||||||
|
f.write(expected_hash())
|
||||||
dest = os.path.join(cache_path, 'f')
|
dest = os.path.join(cache_path, 'f')
|
||||||
with TemporaryDirectory(dir=cache_path) as trash:
|
with TemporaryDirectory(dir=cache_path) as trash:
|
||||||
try:
|
try:
|
||||||
@ -80,10 +90,10 @@ def extract_dicts(cache_path):
|
|||||||
def is_cache_up_to_date(cache_path):
|
def is_cache_up_to_date(cache_path):
|
||||||
if getattr(is_cache_up_to_date, 'updated', False):
|
if getattr(is_cache_up_to_date, 'updated', False):
|
||||||
return True
|
return True
|
||||||
hsh = P('hyphenation/sha1sum', data=True, allow_user_override=False)
|
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(cache_path, 'f', 'sha1sum'), 'rb') as f:
|
with open(os.path.join(cache_path, 'f', 'sha1sum'), 'rb') as f:
|
||||||
if f.read() == hsh:
|
actual_hash = f.read()
|
||||||
|
if actual_hash == expected_hash():
|
||||||
is_cache_up_to_date.updated = True
|
is_cache_up_to_date.updated = True
|
||||||
return True
|
return True
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user