mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont rely on external tar to compress dictionaries
This commit is contained in:
parent
5f46b06dc9
commit
8081805208
@ -8,7 +8,7 @@ import hashlib
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import tarfile
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
@ -72,6 +72,17 @@ def process_dictionaries(src, output_dir):
|
|||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
|
|
||||||
|
def compress_tar(buf, outf):
|
||||||
|
buf.seek(0)
|
||||||
|
try:
|
||||||
|
from calibre_lzma.xz import compress
|
||||||
|
except ImportError:
|
||||||
|
import lzma
|
||||||
|
outf.write(lzma.compress(buf.getvalue(), preset=9 | lzma.PRESET_EXTREME))
|
||||||
|
else:
|
||||||
|
compress(buf, outf)
|
||||||
|
|
||||||
|
|
||||||
class Hyphenation(Command):
|
class Hyphenation(Command):
|
||||||
|
|
||||||
description = 'Download the hyphenation dictionaries'
|
description = 'Download the hyphenation dictionaries'
|
||||||
@ -103,9 +114,12 @@ class Hyphenation(Command):
|
|||||||
with open(os.path.join(output_dir, dic), 'rb') as f:
|
with open(os.path.join(output_dir, dic), 'rb') as f:
|
||||||
m.update(f.read())
|
m.update(f.read())
|
||||||
hsh = type('')(m.hexdigest())
|
hsh = type('')(m.hexdigest())
|
||||||
subprocess.check_call([
|
buf = BytesIO()
|
||||||
'tar', '-cJf', os.path.join(self.hyphenation_dir, 'dictionaries.tar.xz')] + dics
|
with tarfile.TarFile(fileobj=buf, mode='w') as tf:
|
||||||
, env={'XZ_OPT': '-9e -T0'}, cwd=output_dir)
|
for dic in dics:
|
||||||
shutil.copy(self.j(output_dir, 'locales.json'), self.hyphenation_dir)
|
tf.add(os.path.join(output_dir, dic), dic)
|
||||||
|
with open(os.path.join(self.hyphenation_dir, 'dictionaries.tar.xz'), 'wb') as f:
|
||||||
|
compress_tar(buf, f)
|
||||||
with open(os.path.join(self.hyphenation_dir, 'sha1sum'), 'w') as f:
|
with open(os.path.join(self.hyphenation_dir, 'sha1sum'), 'w') as f:
|
||||||
f.write(hsh)
|
f.write(hsh)
|
||||||
|
shutil.copy(os.path.join(output_dir, 'locales.json'), self.hyphenation_dir)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user