mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use the stdlib tempfile module instead of ptempfile
This commit is contained in:
parent
cf5755f6a2
commit
3dc7dad1b1
@ -7,12 +7,12 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
import os, shutil
|
||||||
from urllib import urlretrieve
|
from urllib import urlretrieve
|
||||||
from zipfile import ZipFile, ZIP_STORED, ZipInfo
|
from zipfile import ZipFile, ZIP_STORED, ZipInfo
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
|
from tempfile import mkdtemp, SpooledTemporaryFile
|
||||||
|
|
||||||
from lzma.xz import compress
|
|
||||||
|
|
||||||
from setup import Command
|
from setup import Command
|
||||||
|
|
||||||
@ -41,22 +41,23 @@ class MathJax(Command):
|
|||||||
zf.writestr(zi, raw)
|
zf.writestr(zi, raw)
|
||||||
|
|
||||||
def add_tree(self, zf, base, prefix, ignore=lambda n:False):
|
def add_tree(self, zf, base, prefix, ignore=lambda n:False):
|
||||||
from calibre import walk
|
for dirpath, dirnames, filenames in os.walk(base):
|
||||||
for f in walk(base):
|
for fname in filenames:
|
||||||
name = prefix + '/' + os.path.relpath(f, base).replace(os.sep, '/')
|
f = os.path.join(dirpath, fname)
|
||||||
if not ignore(name):
|
name = prefix + '/' + os.path.relpath(f, base).replace(os.sep, '/')
|
||||||
self.add_file(zf, f, name)
|
if not ignore(name):
|
||||||
|
self.add_file(zf, f, name)
|
||||||
|
|
||||||
def ignore_fonts(self, name):
|
def ignore_fonts(self, name):
|
||||||
return '/fonts/' in name and self.FONT_FAMILY not in name
|
return '/fonts/' in name and self.FONT_FAMILY not in name
|
||||||
|
|
||||||
def run(self, opts):
|
def run(self, opts):
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from lzma.xz import compress
|
||||||
self.h = sha1()
|
self.h = sha1()
|
||||||
with TemporaryDirectory() as tdir:
|
tdir = mkdtemp('calibre-mathjax-build')
|
||||||
|
try:
|
||||||
src = opts.path_to_mathjax or self.download_mathjax_release(tdir)
|
src = opts.path_to_mathjax or self.download_mathjax_release(tdir)
|
||||||
self.info('Compressing MathJax...')
|
self.info('Compressing MathJax...')
|
||||||
from calibre.ptempfile import SpooledTemporaryFile
|
|
||||||
t = SpooledTemporaryFile()
|
t = SpooledTemporaryFile()
|
||||||
with ZipFile(t, 'w', ZIP_STORED) as zf:
|
with ZipFile(t, 'w', ZIP_STORED) as zf:
|
||||||
self.add_file(zf, self.j(src, 'unpacked', 'MathJax.js'), 'MathJax.js')
|
self.add_file(zf, self.j(src, 'unpacked', 'MathJax.js'), 'MathJax.js')
|
||||||
@ -70,3 +71,5 @@ class MathJax(Command):
|
|||||||
compress(t, f, level=9)
|
compress(t, f, level=9)
|
||||||
with open(self.j(self.RESOURCES, 'content-server', 'mathjax.version'), 'wb') as f:
|
with open(self.j(self.RESOURCES, 'content-server', 'mathjax.version'), 'wb') as f:
|
||||||
f.write(zf.comment)
|
f.write(zf.comment)
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(tdir)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user