mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
setup: port over the hyphenation dictionary code to ReVendor()
This makes it automatically support being passed an alternative url, or an extracted directory.
This commit is contained in:
parent
a66e562b08
commit
11d6b27ec7
@ -10,11 +10,8 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import tarfile
|
import tarfile
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from zipfile import ZipFile
|
|
||||||
|
|
||||||
from setup import Command, download_securely
|
from setup.revendor import ReVendor
|
||||||
|
|
||||||
URL = 'https://github.com/LibreOffice/dictionaries/archive/master.zip'
|
|
||||||
|
|
||||||
|
|
||||||
def locales_from_dicts(dicts):
|
def locales_from_dicts(dicts):
|
||||||
@ -83,30 +80,19 @@ def compress_tar(buf, outf):
|
|||||||
compress(buf, outf)
|
compress(buf, outf)
|
||||||
|
|
||||||
|
|
||||||
class Hyphenation(Command):
|
class Hyphenation(ReVendor):
|
||||||
|
|
||||||
description = 'Download the hyphenation dictionaries'
|
description = 'Download the hyphenation dictionaries'
|
||||||
|
NAME = 'hyphenation'
|
||||||
def add_options(self, parser):
|
TAR_NAME = 'hyphenation dictionaries'
|
||||||
pass
|
VERSION = 'master'
|
||||||
# parser.add_option('--path-to-mathjax', help='Path to the MathJax source code')
|
DOWNLOAD_URL = 'https://github.com/LibreOffice/dictionaries/archive/%s.tar.gz' % VERSION
|
||||||
|
|
||||||
@property
|
|
||||||
def hyphenation_dir(self):
|
|
||||||
return self.j(self.RESOURCES, 'hyphenation')
|
|
||||||
|
|
||||||
def clean(self):
|
|
||||||
if os.path.exists(self.hyphenation_dir):
|
|
||||||
shutil.rmtree(self.hyphenation_dir)
|
|
||||||
|
|
||||||
def run(self, opts):
|
def run(self, opts):
|
||||||
self.clean()
|
self.clean()
|
||||||
os.makedirs(self.hyphenation_dir)
|
os.makedirs(self.vendored_dir)
|
||||||
self.info('Downloading hyphenation dictionaries...')
|
with self.temp_dir() as dl_src, self.temp_dir() as output_dir:
|
||||||
with self.temp_dir() as src, ZipFile(BytesIO(download_securely(URL))) as zf, self.temp_dir() as output_dir:
|
src = opts.path_to_hyphenation or self.download_vendor_release(dl_src, opts.hyphenation_url)
|
||||||
zf.extractall(src)
|
|
||||||
if len(os.listdir(src)) == 1:
|
|
||||||
src = os.path.join(src, os.listdir(src)[0])
|
|
||||||
process_dictionaries(src, output_dir)
|
process_dictionaries(src, output_dir)
|
||||||
dics = sorted(x for x in os.listdir(output_dir) if x.endswith('.dic'))
|
dics = sorted(x for x in os.listdir(output_dir) if x.endswith('.dic'))
|
||||||
m = hashlib.sha1()
|
m = hashlib.sha1()
|
||||||
@ -123,8 +109,8 @@ class Hyphenation(Command):
|
|||||||
tinfo.uid = tinfo.gid = 1000
|
tinfo.uid = tinfo.gid = 1000
|
||||||
tinfo.uname = tinfo.gname = 'kovid'
|
tinfo.uname = tinfo.gname = 'kovid'
|
||||||
tf.addfile(tinfo, df)
|
tf.addfile(tinfo, df)
|
||||||
with open(os.path.join(self.hyphenation_dir, 'dictionaries.tar.xz'), 'wb') as f:
|
with open(os.path.join(self.vendored_dir, 'dictionaries.tar.xz'), 'wb') as f:
|
||||||
compress_tar(buf, f)
|
compress_tar(buf, f)
|
||||||
with open(os.path.join(self.hyphenation_dir, 'sha1sum'), 'w') as f:
|
with open(os.path.join(self.vendored_dir, 'sha1sum'), 'w') as f:
|
||||||
f.write(hsh)
|
f.write(hsh)
|
||||||
shutil.copy(os.path.join(output_dir, 'locales.json'), self.hyphenation_dir)
|
shutil.copy(os.path.join(output_dir, 'locales.json'), self.vendored_dir)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user