mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Fix container tests on windows
This commit is contained in:
parent
510a6bac6e
commit
c306458357
@ -8,6 +8,8 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import os, unittest, shutil
|
import os, unittest, shutil
|
||||||
|
|
||||||
|
from calibre import CurrentDir
|
||||||
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||||
from calibre.utils.logging import DevNull
|
from calibre.utils.logging import DevNull
|
||||||
import calibre.ebooks.oeb.polish.container as pc
|
import calibre.ebooks.oeb.polish.container as pc
|
||||||
@ -35,24 +37,33 @@ def build_book(src, dest, args=()):
|
|||||||
from calibre.ebooks.conversion.cli import main
|
from calibre.ebooks.conversion.cli import main
|
||||||
main(['ebook-convert', src, dest] + list(args))
|
main(['ebook-convert', src, dest] + list(args))
|
||||||
|
|
||||||
|
def add_resources(raw, rmap):
|
||||||
|
for placeholder, path in rmap.iteritems():
|
||||||
|
fname = os.path.basename(path)
|
||||||
|
shutil.copy2(path, '.')
|
||||||
|
raw = raw.replace(placeholder, fname)
|
||||||
|
return raw
|
||||||
|
|
||||||
def get_simple_book(fmt='epub'):
|
def get_simple_book(fmt='epub'):
|
||||||
cache = get_cache()
|
cache = get_cache()
|
||||||
ans = os.path.join(cache, 'simple.'+fmt)
|
ans = os.path.join(cache, 'simple.'+fmt)
|
||||||
src = os.path.join(os.path.dirname(__file__), 'simple.html')
|
src = os.path.join(os.path.dirname(__file__), 'simple.html')
|
||||||
if needs_recompile(ans, src):
|
if needs_recompile(ans, src):
|
||||||
x = src.replace('simple.html', 'index.html')
|
with TemporaryDirectory('bpt') as tdir:
|
||||||
raw = open(src, 'rb').read().decode('utf-8')
|
with CurrentDir(tdir):
|
||||||
raw = raw.replace('LMONOI', P('fonts/liberation/LiberationMono-Italic.ttf'))
|
raw = open(src, 'rb').read().decode('utf-8')
|
||||||
raw = raw.replace('LMONO', P('fonts/liberation/LiberationMono-Regular.ttf'))
|
raw = add_resources(raw, {
|
||||||
raw = raw.replace('IMAGE1', I('marked.png'))
|
'LMONOI': P('fonts/liberation/LiberationMono-Italic.ttf'),
|
||||||
raw = raw.replace('IMAGE2', I('textures/light_wood.png'))
|
'LMONOR': P('fonts/liberation/LiberationMono-Regular.ttf'),
|
||||||
try:
|
'IMAGE1': I('marked.png'),
|
||||||
with open(x, 'wb') as f:
|
'IMAGE2': I('textures/light_wood.png'),
|
||||||
f.write(raw.encode('utf-8'))
|
})
|
||||||
build_book(x, ans, args=['--level1-toc=//h:h2', '--language=en', '--authors=Kovid Goyal',
|
shutil.copy2(I('lt.png'), '.')
|
||||||
'--cover=' + I('lt.png')])
|
x = 'index.html'
|
||||||
finally:
|
with open(x, 'wb') as f:
|
||||||
os.remove(x)
|
f.write(raw.encode('utf-8'))
|
||||||
|
build_book(x, ans, args=[
|
||||||
|
'--level1-toc=//h:h2', '--language=en', '--authors=Kovid Goyal', '--cover=lt.png'])
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def get_split_book(fmt='epub'):
|
def get_split_book(fmt='epub'):
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Liberation Mono";
|
font-family: "Liberation Mono";
|
||||||
src: url(LMONO);
|
src: url(LMONOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user