mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-01-03 09:14:11 +01:00
Removing polyglot getcwd and getenv
This commit is contained in:
@@ -5,7 +5,7 @@ import locale
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from ebook_converter.polyglot.builtins import environ_item, hasenv, getenv, as_unicode, native_string_type
|
from ebook_converter.polyglot.builtins import environ_item, hasenv, as_unicode, native_string_type
|
||||||
|
|
||||||
__appname__ = 'calibre'
|
__appname__ = 'calibre'
|
||||||
numeric_version = (4, 12, 0)
|
numeric_version = (4, 12, 0)
|
||||||
@@ -111,7 +111,7 @@ def _get_cache_dir():
|
|||||||
raise
|
raise
|
||||||
if isportable:
|
if isportable:
|
||||||
return confcache
|
return confcache
|
||||||
ccd = getenv('CALIBRE_CACHE_DIRECTORY')
|
ccd = os.getenv('CALIBRE_CACHE_DIRECTORY')
|
||||||
if ccd is not None:
|
if ccd is not None:
|
||||||
ans = os.path.abspath(ccd)
|
ans = os.path.abspath(ccd)
|
||||||
try:
|
try:
|
||||||
@@ -130,7 +130,7 @@ def _get_cache_dir():
|
|||||||
elif isosx:
|
elif isosx:
|
||||||
candidate = os.path.join(os.path.expanduser('~/Library/Caches'), __appname__)
|
candidate = os.path.join(os.path.expanduser('~/Library/Caches'), __appname__)
|
||||||
else:
|
else:
|
||||||
candidate = getenv('XDG_CACHE_HOME', '~/.cache')
|
candidate = os.getenv('XDG_CACHE_HOME', '~/.cache')
|
||||||
candidate = os.path.join(os.path.expanduser(candidate),
|
candidate = os.path.join(os.path.expanduser(candidate),
|
||||||
__appname__)
|
__appname__)
|
||||||
if isinstance(candidate, bytes):
|
if isinstance(candidate, bytes):
|
||||||
@@ -250,7 +250,7 @@ if plugins is None:
|
|||||||
|
|
||||||
CONFIG_DIR_MODE = 0o700
|
CONFIG_DIR_MODE = 0o700
|
||||||
|
|
||||||
cconfd = getenv('CALIBRE_CONFIG_DIRECTORY')
|
cconfd = os.getenv('CALIBRE_CONFIG_DIRECTORY')
|
||||||
if cconfd is not None:
|
if cconfd is not None:
|
||||||
config_dir = os.path.abspath(cconfd)
|
config_dir = os.path.abspath(cconfd)
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
@@ -266,7 +266,7 @@ elif iswindows:
|
|||||||
elif isosx:
|
elif isosx:
|
||||||
config_dir = os.path.expanduser('~/Library/Preferences/calibre')
|
config_dir = os.path.expanduser('~/Library/Preferences/calibre')
|
||||||
else:
|
else:
|
||||||
bdir = os.path.abspath(os.path.expanduser(getenv('XDG_CONFIG_HOME', '~/.config')))
|
bdir = os.path.abspath(os.path.expanduser(os.getenv('XDG_CONFIG_HOME', '~/.config')))
|
||||||
config_dir = os.path.join(bdir, 'calibre')
|
config_dir = os.path.join(bdir, 'calibre')
|
||||||
try:
|
try:
|
||||||
os.makedirs(config_dir, mode=CONFIG_DIR_MODE)
|
os.makedirs(config_dir, mode=CONFIG_DIR_MODE)
|
||||||
@@ -289,7 +289,7 @@ else:
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
dv = getenv('CALIBRE_DEVELOP_FROM')
|
dv = os.getenv('CALIBRE_DEVELOP_FROM')
|
||||||
is_running_from_develop = bool(getattr(sys, 'frozen', False) and dv and os.path.abspath(dv) in sys.path)
|
is_running_from_develop = bool(getattr(sys, 'frozen', False) and dv and os.path.abspath(dv) in sys.path)
|
||||||
del dv
|
del dv
|
||||||
|
|
||||||
@@ -313,7 +313,7 @@ def get_version():
|
|||||||
def get_portable_base():
|
def get_portable_base():
|
||||||
'Return path to the directory that contains calibre-portable.exe or None'
|
'Return path to the directory that contains calibre-portable.exe or None'
|
||||||
if isportable:
|
if isportable:
|
||||||
return os.path.dirname(os.path.dirname(getenv('CALIBRE_PORTABLE_BUILD')))
|
return os.path.dirname(os.path.dirname(os.getenv('CALIBRE_PORTABLE_BUILD')))
|
||||||
|
|
||||||
|
|
||||||
def get_windows_username():
|
def get_windows_username():
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -22,6 +23,6 @@ class AZW4Input(InputFormatPlugin):
|
|||||||
|
|
||||||
header = PdbHeaderReader(stream)
|
header = PdbHeaderReader(stream)
|
||||||
reader = Reader(header, stream, log, options)
|
reader = Reader(header, stream, log, options)
|
||||||
opf = reader.extract_content(getcwd())
|
opf = reader.extract_content(os.getcwd())
|
||||||
|
|
||||||
return opf
|
return opf
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import shutil, textwrap, codecs, os
|
|||||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
from ebook_converter import CurrentDir
|
from ebook_converter import CurrentDir
|
||||||
from ebook_converter.ptempfile import PersistentTemporaryDirectory
|
from ebook_converter.ptempfile import PersistentTemporaryDirectory
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -194,7 +193,7 @@ class ComicInput(InputFormatPlugin):
|
|||||||
|
|
||||||
mi = MetaInformation(os.path.basename(stream.name).rpartition('.')[0],
|
mi = MetaInformation(os.path.basename(stream.name).rpartition('.')[0],
|
||||||
[_('Unknown')])
|
[_('Unknown')])
|
||||||
opf = OPFCreator(getcwd(), mi)
|
opf = OPFCreator(os.getcwd(), mi)
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
def href(x):
|
def href(x):
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import os
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
@@ -38,7 +37,7 @@ class DJVUInput(InputFormatPlugin):
|
|||||||
for opt in html_input.options:
|
for opt in html_input.options:
|
||||||
setattr(options, opt.option.name, opt.recommended_value)
|
setattr(options, opt.option.name, opt.recommended_value)
|
||||||
options.input_encoding = 'utf-8'
|
options.input_encoding = 'utf-8'
|
||||||
base = getcwd()
|
base = os.getcwd()
|
||||||
htmlfile = os.path.join(base, 'index.html')
|
htmlfile = os.path.join(base, 'index.html')
|
||||||
c = 0
|
c = 0
|
||||||
while os.path.exists(htmlfile):
|
while os.path.exists(htmlfile):
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import os, re, posixpath
|
|||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
|
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
@@ -245,7 +244,7 @@ class EPUBInput(InputFormatPlugin):
|
|||||||
path = attr(r, 'full-path')
|
path = attr(r, 'full-path')
|
||||||
if not path:
|
if not path:
|
||||||
continue
|
continue
|
||||||
path = os.path.join(getcwd(), *path.split('/'))
|
path = os.path.join(os.getcwd(), *path.split('/'))
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
return path
|
return path
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -259,7 +258,7 @@ class EPUBInput(InputFormatPlugin):
|
|||||||
from ebook_converter.ebooks.metadata.opf2 import OPF
|
from ebook_converter.ebooks.metadata.opf2 import OPF
|
||||||
try:
|
try:
|
||||||
zf = ZipFile(stream)
|
zf = ZipFile(stream)
|
||||||
zf.extractall(getcwd())
|
zf.extractall(os.getcwd())
|
||||||
except:
|
except:
|
||||||
log.exception('EPUB appears to be invalid ZIP file, trying a'
|
log.exception('EPUB appears to be invalid ZIP file, trying a'
|
||||||
' more forgiving ZIP parser')
|
' more forgiving ZIP parser')
|
||||||
@@ -279,7 +278,7 @@ class EPUBInput(InputFormatPlugin):
|
|||||||
if opf is None:
|
if opf is None:
|
||||||
raise ValueError('%s is not a valid EPUB file (could not find opf)'%path)
|
raise ValueError('%s is not a valid EPUB file (could not find opf)'%path)
|
||||||
|
|
||||||
opf = os.path.relpath(opf, getcwd())
|
opf = os.path.relpath(opf, os.getcwd())
|
||||||
parts = os.path.split(opf)
|
parts = os.path.split(opf)
|
||||||
opf = OPF(opf, os.path.dirname(os.path.abspath(opf)))
|
opf = OPF(opf, os.path.dirname(os.path.abspath(opf)))
|
||||||
|
|
||||||
@@ -404,7 +403,7 @@ class EPUBInput(InputFormatPlugin):
|
|||||||
|
|
||||||
with NamedTemporaryFile(suffix='.ncx', dir=os.path.dirname(nav_path), delete=False) as f:
|
with NamedTemporaryFile(suffix='.ncx', dir=os.path.dirname(nav_path), delete=False) as f:
|
||||||
f.write(etree.tostring(ncx, encoding='utf-8'))
|
f.write(etree.tostring(ncx, encoding='utf-8'))
|
||||||
ncx_href = os.path.relpath(f.name, getcwd()).replace(os.sep, '/')
|
ncx_href = os.path.relpath(f.name, os.getcwd()).replace(os.sep, '/')
|
||||||
ncx_id = opf.create_manifest_item(ncx_href, NCX_MIME, append=True).get('id')
|
ncx_id = opf.create_manifest_item(ncx_href, NCX_MIME, append=True).get('id')
|
||||||
for spine in opf.root.xpath('//*[local-name()="spine"]'):
|
for spine in opf.root.xpath('//*[local-name()="spine"]'):
|
||||||
spine.set('toc', ncx_id)
|
spine.set('toc', ncx_id)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import pkg_resources
|
|||||||
|
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
from ebook_converter import guess_type
|
from ebook_converter import guess_type
|
||||||
from ebook_converter.polyglot.builtins import iteritems, getcwd
|
from ebook_converter.polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -147,7 +147,7 @@ class FB2Input(InputFormatPlugin):
|
|||||||
cpath = os.path.abspath(href)
|
cpath = os.path.abspath(href)
|
||||||
break
|
break
|
||||||
|
|
||||||
opf = OPFCreator(getcwd(), mi)
|
opf = OPFCreator(os.getcwd(), mi)
|
||||||
entries = [(f2, guess_type(f2)[0]) for f2 in os.listdir(u'.')]
|
entries = [(f2, guess_type(f2)[0]) for f2 in os.listdir(u'.')]
|
||||||
opf.create_manifest(entries)
|
opf.create_manifest(entries)
|
||||||
opf.create_spine(['index.xhtml'])
|
opf.create_spine(['index.xhtml'])
|
||||||
@@ -155,7 +155,7 @@ class FB2Input(InputFormatPlugin):
|
|||||||
opf.guide.set_cover(cpath)
|
opf.guide.set_cover(cpath)
|
||||||
with open('metadata.opf', 'wb') as f:
|
with open('metadata.opf', 'wb') as f:
|
||||||
opf.render(f)
|
opf.render(f)
|
||||||
return os.path.join(getcwd(), 'metadata.opf')
|
return os.path.join(os.getcwd(), 'metadata.opf')
|
||||||
|
|
||||||
def extract_embedded_content(self, doc):
|
def extract_embedded_content(self, doc):
|
||||||
from ebook_converter.ebooks.fb2 import base64_decode
|
from ebook_converter.ebooks.fb2 import base64_decode
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from ebook_converter.customize.conversion import (InputFormatPlugin,
|
|||||||
from ebook_converter.utils.localization import get_lang
|
from ebook_converter.utils.localization import get_lang
|
||||||
from ebook_converter.utils.filenames import ascii_filename
|
from ebook_converter.utils.filenames import ascii_filename
|
||||||
from ebook_converter.utils.imghdr import what
|
from ebook_converter.utils.imghdr import what
|
||||||
from ebook_converter.polyglot.builtins import getcwd, as_unicode
|
from ebook_converter.polyglot.builtins import as_unicode
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -63,7 +63,7 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
def convert(self, stream, opts, file_ext, log,
|
def convert(self, stream, opts, file_ext, log,
|
||||||
accelerators):
|
accelerators):
|
||||||
self._is_case_sensitive = None
|
self._is_case_sensitive = None
|
||||||
basedir = getcwd()
|
basedir = os.getcwd()
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
|
|
||||||
fname = None
|
fname = None
|
||||||
@@ -220,7 +220,7 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
continue
|
continue
|
||||||
toc.add(title, item.href)
|
toc.add(title, item.href)
|
||||||
|
|
||||||
oeb.container = DirContainer(getcwd(), oeb.log, ignore_opf=True)
|
oeb.container = DirContainer(os.getcwd(), oeb.log, ignore_opf=True)
|
||||||
return oeb
|
return oeb
|
||||||
|
|
||||||
def link_to_local_path(self, link_, base=None):
|
def link_to_local_path(self, link_, base=None):
|
||||||
@@ -232,7 +232,7 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
self.log.warn('Failed to decode link %r. Ignoring'%link_)
|
self.log.warn('Failed to decode link %r. Ignoring'%link_)
|
||||||
return None, None
|
return None, None
|
||||||
try:
|
try:
|
||||||
l = Link(link_, base if base else getcwd())
|
l = Link(link_, base if base else os.getcwd())
|
||||||
except:
|
except:
|
||||||
self.log.exception('Failed to process link: %r'%link_)
|
self.log.exception('Failed to process link: %r'%link_)
|
||||||
return None, None
|
return None, None
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import os
|
|||||||
|
|
||||||
from ebook_converter import guess_type
|
from ebook_converter import guess_type
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
@@ -84,7 +83,7 @@ class HTMLZInput(InputFormatPlugin):
|
|||||||
for opt in html_input.options:
|
for opt in html_input.options:
|
||||||
setattr(options, opt.option.name, opt.recommended_value)
|
setattr(options, opt.option.name, opt.recommended_value)
|
||||||
options.input_encoding = 'utf-8'
|
options.input_encoding = 'utf-8'
|
||||||
base = getcwd()
|
base = os.getcwd()
|
||||||
htmlfile = os.path.join(base, u'index.html')
|
htmlfile = os.path.join(base, u'index.html')
|
||||||
c = 0
|
c = 0
|
||||||
while os.path.exists(htmlfile):
|
while os.path.exists(htmlfile):
|
||||||
@@ -115,12 +114,12 @@ class HTMLZInput(InputFormatPlugin):
|
|||||||
opf = x
|
opf = x
|
||||||
break
|
break
|
||||||
if opf:
|
if opf:
|
||||||
opf = OPF(opf, basedir=getcwd())
|
opf = OPF(opf, basedir=os.getcwd())
|
||||||
cover_path = opf.raster_cover or opf.cover
|
cover_path = opf.raster_cover or opf.cover
|
||||||
# Set the cover.
|
# Set the cover.
|
||||||
if cover_path:
|
if cover_path:
|
||||||
cdata = None
|
cdata = None
|
||||||
with open(os.path.join(getcwd(), cover_path), 'rb') as cf:
|
with open(os.path.join(os.getcwd(), cover_path), 'rb') as cf:
|
||||||
cdata = cf.read()
|
cdata = cf.read()
|
||||||
cover_name = os.path.basename(cover_path)
|
cover_name = os.path.basename(cover_path)
|
||||||
id, href = oeb.manifest.generate('cover', cover_name)
|
id, href = oeb.manifest.generate('cover', cover_name)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -30,6 +31,6 @@ class PDBInput(InputFormatPlugin):
|
|||||||
log.debug('Detected ebook format as: %s with identity: %s' % (IDENTITY_TO_NAME[header.ident], header.ident))
|
log.debug('Detected ebook format as: %s with identity: %s' % (IDENTITY_TO_NAME[header.ident], header.ident))
|
||||||
|
|
||||||
reader = Reader(header, stream, log, options)
|
reader = Reader(header, stream, log, options)
|
||||||
opf = reader.extract_content(getcwd())
|
opf = reader.extract_content(os.getcwd())
|
||||||
|
|
||||||
return opf
|
return opf
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
from ebook_converter.polyglot.builtins import as_bytes, getcwd
|
from ebook_converter.polyglot.builtins import as_bytes
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
@@ -33,11 +33,11 @@ class PDFInput(InputFormatPlugin):
|
|||||||
from ebook_converter.utils.cleantext import clean_ascii_chars
|
from ebook_converter.utils.cleantext import clean_ascii_chars
|
||||||
from ebook_converter.ebooks.pdf.reflow import PDFDocument
|
from ebook_converter.ebooks.pdf.reflow import PDFDocument
|
||||||
|
|
||||||
pdftohtml(getcwd(), stream.name, self.opts.no_images, as_xml=True)
|
pdftohtml(os.getcwd(), stream.name, self.opts.no_images, as_xml=True)
|
||||||
with lopen('index.xml', 'rb') as f:
|
with lopen('index.xml', 'rb') as f:
|
||||||
xml = clean_ascii_chars(f.read())
|
xml = clean_ascii_chars(f.read())
|
||||||
PDFDocument(xml, self.opts, self.log)
|
PDFDocument(xml, self.opts, self.log)
|
||||||
return os.path.join(getcwd(), 'metadata.opf')
|
return os.path.join(os.getcwd(), 'metadata.opf')
|
||||||
|
|
||||||
def convert(self, stream, options, file_ext, log, accelerators):
|
def convert(self, stream, options, file_ext, log, accelerators):
|
||||||
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
||||||
@@ -48,16 +48,16 @@ class PDFInput(InputFormatPlugin):
|
|||||||
self.opts, self.log = options, log
|
self.opts, self.log = options, log
|
||||||
if options.new_pdf_engine:
|
if options.new_pdf_engine:
|
||||||
return self.convert_new(stream, accelerators)
|
return self.convert_new(stream, accelerators)
|
||||||
pdftohtml(getcwd(), stream.name, options.no_images)
|
pdftohtml(os.getcwd(), stream.name, options.no_images)
|
||||||
|
|
||||||
from ebook_converter.ebooks.metadata.meta import get_metadata
|
from ebook_converter.ebooks.metadata.meta import get_metadata
|
||||||
log.debug('Retrieving document metadata...')
|
log.debug('Retrieving document metadata...')
|
||||||
mi = get_metadata(stream, 'pdf')
|
mi = get_metadata(stream, 'pdf')
|
||||||
opf = OPFCreator(getcwd(), mi)
|
opf = OPFCreator(os.getcwd(), mi)
|
||||||
|
|
||||||
manifest = [('index.html', None)]
|
manifest = [('index.html', None)]
|
||||||
|
|
||||||
images = os.listdir(getcwd())
|
images = os.listdir(os.getcwd())
|
||||||
images.remove('index.html')
|
images.remove('index.html')
|
||||||
for i in images:
|
for i in images:
|
||||||
manifest.append((i, None))
|
manifest.append((i, None))
|
||||||
@@ -76,4 +76,4 @@ class PDFInput(InputFormatPlugin):
|
|||||||
f.seek(0)
|
f.seek(0)
|
||||||
f.write(raw)
|
f.write(raw)
|
||||||
|
|
||||||
return os.path.join(getcwd(), 'metadata.opf')
|
return os.path.join(os.getcwd(), 'metadata.opf')
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import shutil
|
|||||||
|
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||||
from ebook_converter.ptempfile import TemporaryDirectory
|
from ebook_converter.ptempfile import TemporaryDirectory
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -74,10 +73,10 @@ class PMLInput(InputFormatPlugin):
|
|||||||
if not imgs:
|
if not imgs:
|
||||||
imgs = glob.glob(os.path.join(os.path.join(tdir, 'images'), '*.png'))
|
imgs = glob.glob(os.path.join(os.path.join(tdir, 'images'), '*.png'))
|
||||||
if imgs:
|
if imgs:
|
||||||
os.makedirs(os.path.join(getcwd(), 'images'))
|
os.makedirs(os.path.join(os.getcwd(), 'images'))
|
||||||
for img in imgs:
|
for img in imgs:
|
||||||
pimg_name = os.path.basename(img)
|
pimg_name = os.path.basename(img)
|
||||||
pimg_path = os.path.join(getcwd(), 'images', pimg_name)
|
pimg_path = os.path.join(os.getcwd(), 'images', pimg_name)
|
||||||
|
|
||||||
images.append('images/' + pimg_name)
|
images.append('images/' + pimg_name)
|
||||||
|
|
||||||
@@ -105,7 +104,7 @@ class PMLInput(InputFormatPlugin):
|
|||||||
pmls = glob.glob(os.path.join(tdir, '*.pml'))
|
pmls = glob.glob(os.path.join(tdir, '*.pml'))
|
||||||
for pml in pmls:
|
for pml in pmls:
|
||||||
html_name = os.path.splitext(os.path.basename(pml))[0]+'.html'
|
html_name = os.path.splitext(os.path.basename(pml))[0]+'.html'
|
||||||
html_path = os.path.join(getcwd(), html_name)
|
html_path = os.path.join(os.getcwd(), html_name)
|
||||||
|
|
||||||
pages.append(html_name)
|
pages.append(html_name)
|
||||||
log.debug('Processing PML item %s...' % pml)
|
log.debug('Processing PML item %s...' % pml)
|
||||||
@@ -131,7 +130,7 @@ class PMLInput(InputFormatPlugin):
|
|||||||
mi = get_metadata(stream, 'pml')
|
mi = get_metadata(stream, 'pml')
|
||||||
if 'images/cover.png' in images:
|
if 'images/cover.png' in images:
|
||||||
mi.cover = 'images/cover.png'
|
mi.cover = 'images/cover.png'
|
||||||
opf = OPFCreator(getcwd(), mi)
|
opf = OPFCreator(os.getcwd(), mi)
|
||||||
log.debug('Generating manifest...')
|
log.debug('Generating manifest...')
|
||||||
opf.create_manifest(manifest_items)
|
opf.create_manifest(manifest_items)
|
||||||
opf.create_spine(pages)
|
opf.create_spine(pages)
|
||||||
@@ -140,7 +139,7 @@ class PMLInput(InputFormatPlugin):
|
|||||||
with lopen('toc.ncx', 'wb') as tocfile:
|
with lopen('toc.ncx', 'wb') as tocfile:
|
||||||
opf.render(opffile, tocfile, 'toc.ncx')
|
opf.render(opffile, tocfile, 'toc.ncx')
|
||||||
|
|
||||||
return os.path.join(getcwd(), 'metadata.opf')
|
return os.path.join(os.getcwd(), 'metadata.opf')
|
||||||
|
|
||||||
def postprocess_book(self, oeb, opts, log):
|
def postprocess_book(self, oeb, opts, log):
|
||||||
from ebook_converter.ebooks.oeb.base import XHTML, barename
|
from ebook_converter.ebooks.oeb.base import XHTML, barename
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
@@ -20,6 +21,6 @@ class RBInput(InputFormatPlugin):
|
|||||||
from ebook_converter.ebooks.rb.reader import Reader
|
from ebook_converter.ebooks.rb.reader import Reader
|
||||||
|
|
||||||
reader = Reader(stream, log, options.input_encoding)
|
reader = Reader(stream, log, options.input_encoding)
|
||||||
opf = reader.extract_content(getcwd())
|
opf = reader.extract_content(os.getcwd())
|
||||||
|
|
||||||
return opf
|
return opf
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import os, glob, re, textwrap
|
|||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
from ebook_converter.polyglot.builtins import iteritems, getcwd, as_bytes
|
from ebook_converter.polyglot.builtins import iteritems, as_bytes
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
@@ -306,7 +306,7 @@ class RTFInput(InputFormatPlugin):
|
|||||||
mi.title = _('Unknown')
|
mi.title = _('Unknown')
|
||||||
if not mi.authors:
|
if not mi.authors:
|
||||||
mi.authors = [_('Unknown')]
|
mi.authors = [_('Unknown')]
|
||||||
opf = OPFCreator(getcwd(), mi)
|
opf = OPFCreator(os.getcwd(), mi)
|
||||||
opf.create_manifest([(u'index.xhtml', None)])
|
opf.create_manifest([(u'index.xhtml', None)])
|
||||||
opf.create_spine([u'index.xhtml'])
|
opf.create_spine([u'index.xhtml'])
|
||||||
opf.render(open(u'metadata.opf', 'wb'))
|
opf.render(open(u'metadata.opf', 'wb'))
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import os
|
|||||||
|
|
||||||
from ebook_converter import _ent_pat, walk, xml_entity_to_unicode
|
from ebook_converter import _ent_pat, walk, xml_entity_to_unicode
|
||||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
@@ -141,7 +140,7 @@ class TXTInput(InputFormatPlugin):
|
|||||||
txt = b''
|
txt = b''
|
||||||
log.debug('Reading text from file...')
|
log.debug('Reading text from file...')
|
||||||
length = 0
|
length = 0
|
||||||
base_dir = self.output_dir = getcwd()
|
base_dir = self.output_dir = os.getcwd()
|
||||||
|
|
||||||
# Extract content from zip archive.
|
# Extract content from zip archive.
|
||||||
if file_ext == 'txtz':
|
if file_ext == 'txtz':
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ from ebook_converter.ebooks.docx.fields import Fields
|
|||||||
from ebook_converter.ebooks.docx.settings import Settings
|
from ebook_converter.ebooks.docx.settings import Settings
|
||||||
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
||||||
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
|
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, getcwd
|
from ebook_converter.polyglot.builtins import iteritems, itervalues
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -65,7 +65,7 @@ class Convert(object):
|
|||||||
self.notes_text = notes_text or _('Notes')
|
self.notes_text = notes_text or _('Notes')
|
||||||
self.notes_nopb = notes_nopb
|
self.notes_nopb = notes_nopb
|
||||||
self.nosupsub = nosupsub
|
self.nosupsub = nosupsub
|
||||||
self.dest_dir = dest_dir or getcwd()
|
self.dest_dir = dest_dir or os.getcwd()
|
||||||
self.mi = self.docx.metadata
|
self.mi = self.docx.metadata
|
||||||
self.body = BODY()
|
self.body = BODY()
|
||||||
self.theme = Theme(self.namespace)
|
self.theme = Theme(self.namespace)
|
||||||
@@ -828,7 +828,7 @@ if __name__ == '__main__':
|
|||||||
import shutil
|
import shutil
|
||||||
from ebook_converter.utils.logging import default_log
|
from ebook_converter.utils.logging import default_log
|
||||||
default_log.filter_level = default_log.DEBUG
|
default_log.filter_level = default_log.DEBUG
|
||||||
dest_dir = os.path.join(getcwd(), 'docx_input')
|
dest_dir = os.path.join(os.getcwd(), 'docx_input')
|
||||||
if os.path.exists(dest_dir):
|
if os.path.exists(dest_dir):
|
||||||
shutil.rmtree(dest_dir)
|
shutil.rmtree(dest_dir)
|
||||||
os.mkdir(dest_dir)
|
os.mkdir(dest_dir)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ from ebook_converter.ebooks.lrf.pylrs.pylrs import (
|
|||||||
RuledLine, Span, Sub, Sup, TextBlock
|
RuledLine, Span, Sub, Sup, TextBlock
|
||||||
)
|
)
|
||||||
from ebook_converter.ptempfile import PersistentTemporaryFile
|
from ebook_converter.ptempfile import PersistentTemporaryFile
|
||||||
from ebook_converter.polyglot.builtins import getcwd, itervalues
|
from ebook_converter.polyglot.builtins import itervalues
|
||||||
from ebook_converter.polyglot.urllib import unquote
|
from ebook_converter.polyglot.urllib import unquote
|
||||||
|
|
||||||
from PIL import Image as PILImage
|
from PIL import Image as PILImage
|
||||||
@@ -1888,7 +1888,7 @@ def process_file(path, options, logger):
|
|||||||
if not oname:
|
if not oname:
|
||||||
suffix = '.lrs' if options.lrs else '.lrf'
|
suffix = '.lrs' if options.lrs else '.lrf'
|
||||||
name = os.path.splitext(os.path.basename(path))[0] + suffix
|
name = os.path.splitext(os.path.basename(path))[0] + suffix
|
||||||
oname = os.path.join(getcwd(), name)
|
oname = os.path.join(os.getcwd(), name)
|
||||||
oname = os.path.abspath(os.path.expanduser(oname))
|
oname = os.path.abspath(os.path.expanduser(oname))
|
||||||
conv.writeto(oname, lrs=options.lrs)
|
conv.writeto(oname, lrs=options.lrs)
|
||||||
conv.cleanup()
|
conv.cleanup()
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import urllib.parse
|
|||||||
|
|
||||||
from ebook_converter import relpath, guess_type, prints, force_unicode
|
from ebook_converter import relpath, guess_type, prints, force_unicode
|
||||||
from ebook_converter.utils.config_base import tweaks
|
from ebook_converter.utils.config_base import tweaks
|
||||||
from ebook_converter.polyglot.builtins import getcwd, iteritems, itervalues, as_unicode
|
from ebook_converter.polyglot.builtins import iteritems, itervalues, as_unicode
|
||||||
from ebook_converter.polyglot.urllib import unquote
|
from ebook_converter.polyglot.urllib import unquote
|
||||||
|
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ class Resource(object):
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, href_or_path, basedir=getcwd(), is_path=True):
|
def __init__(self, href_or_path, basedir=os.getcwd(), is_path=True):
|
||||||
self._href = None
|
self._href = None
|
||||||
self._basedir = basedir
|
self._basedir = basedir
|
||||||
self.path = None
|
self.path = None
|
||||||
@@ -267,7 +267,7 @@ class Resource(object):
|
|||||||
if self._basedir:
|
if self._basedir:
|
||||||
basedir = self._basedir
|
basedir = self._basedir
|
||||||
else:
|
else:
|
||||||
basedir = getcwd()
|
basedir = os.getcwd()
|
||||||
if self.path is None:
|
if self.path is None:
|
||||||
return self._href
|
return self._href
|
||||||
f = self.fragment.encode('utf-8') if isinstance(self.fragment, str) else self.fragment
|
f = self.fragment.encode('utf-8') if isinstance(self.fragment, str) else self.fragment
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from ebook_converter.ebooks.metadata.opf2 import OPF
|
|||||||
from ebook_converter import isbytestring
|
from ebook_converter import isbytestring
|
||||||
from ebook_converter.customize.ui import get_file_type_metadata, set_file_type_metadata
|
from ebook_converter.customize.ui import get_file_type_metadata, set_file_type_metadata
|
||||||
from ebook_converter.ebooks.metadata import MetaInformation, string_to_authors
|
from ebook_converter.ebooks.metadata import MetaInformation, string_to_authors
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -201,7 +200,7 @@ def metadata_from_filename(name, pat=None, fallback_pat=None):
|
|||||||
def opf_metadata(opfpath):
|
def opf_metadata(opfpath):
|
||||||
if hasattr(opfpath, 'read'):
|
if hasattr(opfpath, 'read'):
|
||||||
f = opfpath
|
f = opfpath
|
||||||
opfpath = getattr(f, 'name', getcwd())
|
opfpath = getattr(f, 'name', os.getcwd())
|
||||||
else:
|
else:
|
||||||
f = open(opfpath, 'rb')
|
f = open(opfpath, 'rb')
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from ebook_converter import prints, guess_type
|
|||||||
from ebook_converter.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
from ebook_converter.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
||||||
from ebook_converter.utils.config import tweaks
|
from ebook_converter.utils.config import tweaks
|
||||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||||
from ebook_converter.polyglot.builtins import iteritems, getcwd
|
from ebook_converter.polyglot.builtins import iteritems
|
||||||
from ebook_converter.polyglot.urllib import unquote
|
from ebook_converter.polyglot.urllib import unquote
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ class Resource(object): # {{{
|
|||||||
:method:`href`
|
:method:`href`
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, href_or_path, basedir=getcwd(), is_path=True):
|
def __init__(self, href_or_path, basedir=os.getcwd(), is_path=True):
|
||||||
self.orig = href_or_path
|
self.orig = href_or_path
|
||||||
self._href = None
|
self._href = None
|
||||||
self._basedir = basedir
|
self._basedir = basedir
|
||||||
@@ -109,7 +109,7 @@ class Resource(object): # {{{
|
|||||||
if self._basedir:
|
if self._basedir:
|
||||||
basedir = self._basedir
|
basedir = self._basedir
|
||||||
else:
|
else:
|
||||||
basedir = getcwd()
|
basedir = os.getcwd()
|
||||||
if self.path is None:
|
if self.path is None:
|
||||||
return self._href
|
return self._href
|
||||||
frag = ('#' + self.fragment) if self.fragment else ''
|
frag = ('#' + self.fragment) if self.fragment else ''
|
||||||
@@ -400,7 +400,7 @@ class Guide(ResourceCollection): # {{{
|
|||||||
return ans + '/>'
|
return ans + '/>'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_opf_guide(references, base_dir=getcwd()):
|
def from_opf_guide(references, base_dir=os.getcwd()):
|
||||||
coll = Guide()
|
coll = Guide()
|
||||||
for ref in references:
|
for ref in references:
|
||||||
try:
|
try:
|
||||||
@@ -589,7 +589,7 @@ class OPF(object): # {{{
|
|||||||
author_link_map = MetadataField('author_link_map', is_dc=False,
|
author_link_map = MetadataField('author_link_map', is_dc=False,
|
||||||
formatter=json.loads, renderer=dump_dict)
|
formatter=json.loads, renderer=dump_dict)
|
||||||
|
|
||||||
def __init__(self, stream, basedir=getcwd(), unquote_urls=True,
|
def __init__(self, stream, basedir=os.getcwd(), unquote_urls=True,
|
||||||
populate_spine=True, try_to_guess_cover=True, preparsed_opf=None, read_toc=True):
|
populate_spine=True, try_to_guess_cover=True, preparsed_opf=None, read_toc=True):
|
||||||
self.try_to_guess_cover = try_to_guess_cover
|
self.try_to_guess_cover = try_to_guess_cover
|
||||||
self.basedir = self.base_dir = basedir
|
self.basedir = self.base_dir = basedir
|
||||||
@@ -1756,7 +1756,7 @@ b'''\
|
|||||||
</package>
|
</package>
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
self.opf = OPF(self.stream, getcwd())
|
self.opf = OPF(self.stream, os.getcwd())
|
||||||
|
|
||||||
def testReading(self, opf=None):
|
def testReading(self, opf=None):
|
||||||
if opf is None:
|
if opf is None:
|
||||||
@@ -1787,11 +1787,11 @@ b'''\
|
|||||||
self.opf.render()
|
self.opf.render()
|
||||||
|
|
||||||
def testCreator(self):
|
def testCreator(self):
|
||||||
opf = OPFCreator(getcwd(), self.opf)
|
opf = OPFCreator(os.getcwd(), self.opf)
|
||||||
buf = io.BytesIO()
|
buf = io.BytesIO()
|
||||||
opf.render(buf)
|
opf.render(buf)
|
||||||
raw = buf.getvalue()
|
raw = buf.getvalue()
|
||||||
self.testReading(opf=OPF(io.BytesIO(raw), getcwd()))
|
self.testReading(opf=OPF(io.BytesIO(raw), os.getcwd()))
|
||||||
|
|
||||||
def testSmartUpdate(self):
|
def testSmartUpdate(self):
|
||||||
self.opf.smart_update(MetaInformation(self.opf))
|
self.opf.smart_update(MetaInformation(self.opf))
|
||||||
@@ -1818,7 +1818,7 @@ def test_user_metadata():
|
|||||||
}
|
}
|
||||||
mi.set_all_user_metadata(um)
|
mi.set_all_user_metadata(um)
|
||||||
raw = metadata_to_opf(mi)
|
raw = metadata_to_opf(mi)
|
||||||
opfc = OPFCreator(getcwd(), other=mi)
|
opfc = OPFCreator(os.getcwd(), other=mi)
|
||||||
out = io.BytesIO()
|
out = io.BytesIO()
|
||||||
opfc.render(out)
|
opfc.render(out)
|
||||||
raw2 = out.getvalue()
|
raw2 = out.getvalue()
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ from ebook_converter.constants import __appname__, __version__
|
|||||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||||
from ebook_converter.polyglot.builtins import getcwd
|
|
||||||
from ebook_converter.polyglot.urllib import unquote
|
from ebook_converter.polyglot.urllib import unquote
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +48,7 @@ def parse_html_toc(data):
|
|||||||
class TOC(list):
|
class TOC(list):
|
||||||
|
|
||||||
def __init__(self, href=None, fragment=None, text=None, parent=None,
|
def __init__(self, href=None, fragment=None, text=None, parent=None,
|
||||||
play_order=0, base_path=getcwd(), type='unknown', author=None,
|
play_order=0, base_path=os.getcwd(), type='unknown', author=None,
|
||||||
description=None, toc_thumbnail=None):
|
description=None, toc_thumbnail=None):
|
||||||
self.href = href
|
self.href = href
|
||||||
self.fragment = fragment
|
self.fragment = fragment
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from ebook_converter.ebooks.metadata.toc import TOC
|
|||||||
from ebook_converter.ebooks.mobi.utils import read_font_record
|
from ebook_converter.ebooks.mobi.utils import read_font_record
|
||||||
from ebook_converter.ebooks.oeb.parse_utils import parse_html
|
from ebook_converter.ebooks.oeb.parse_utils import parse_html
|
||||||
from ebook_converter.ebooks.oeb.base import XPath, XHTML, xml2text
|
from ebook_converter.ebooks.oeb.base import XPath, XHTML, xml2text
|
||||||
from ebook_converter.polyglot.builtins import getcwd, as_unicode
|
from ebook_converter.polyglot.builtins import as_unicode
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -356,7 +356,7 @@ class Mobi8Reader(object):
|
|||||||
if isinstance(idtext, bytes):
|
if isinstance(idtext, bytes):
|
||||||
idtext = idtext.decode(self.header.codec)
|
idtext = idtext.decode(self.header.codec)
|
||||||
linktgt += '#' + idtext
|
linktgt += '#' + idtext
|
||||||
g = Guide.Reference(linktgt, getcwd())
|
g = Guide.Reference(linktgt, os.getcwd())
|
||||||
g.title, g.type = ref_title, ref_type
|
g.title, g.type = ref_title, ref_type
|
||||||
if g.title == 'start' or g.type == 'text':
|
if g.title == 'start' or g.type == 'text':
|
||||||
has_start = True
|
has_start = True
|
||||||
@@ -370,7 +370,7 @@ class Mobi8Reader(object):
|
|||||||
linktgt = fi.filename
|
linktgt = fi.filename
|
||||||
if idtext:
|
if idtext:
|
||||||
linktgt += '#' + idtext
|
linktgt += '#' + idtext
|
||||||
g = Guide.Reference('%s/%s'%(fi.type, linktgt), getcwd())
|
g = Guide.Reference('%s/%s'%(fi.type, linktgt), os.getcwd())
|
||||||
g.title, g.type = 'start', 'text'
|
g.title, g.type = 'start', 'text'
|
||||||
guide.append(g)
|
guide.append(g)
|
||||||
|
|
||||||
@@ -484,7 +484,7 @@ class Mobi8Reader(object):
|
|||||||
except:
|
except:
|
||||||
self.log.exception('Failed to read inline ToC')
|
self.log.exception('Failed to read inline ToC')
|
||||||
|
|
||||||
opf = OPFCreator(getcwd(), mi)
|
opf = OPFCreator(os.getcwd(), mi)
|
||||||
opf.guide = guide
|
opf.guide = guide
|
||||||
|
|
||||||
def exclude(path):
|
def exclude(path):
|
||||||
@@ -504,7 +504,7 @@ class Mobi8Reader(object):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
opf.create_manifest_from_files_in([getcwd()], exclude=exclude)
|
opf.create_manifest_from_files_in([os.getcwd()], exclude=exclude)
|
||||||
for entry in opf.manifest:
|
for entry in opf.manifest:
|
||||||
if entry.mime_type == 'text/html':
|
if entry.mime_type == 'text/html':
|
||||||
entry.mime_type = 'application/xhtml+xml'
|
entry.mime_type = 'application/xhtml+xml'
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
from ebook_converter import replace_entities
|
from ebook_converter import replace_entities
|
||||||
from ebook_converter.ebooks.metadata.toc import TOC
|
from ebook_converter.ebooks.metadata.toc import TOC
|
||||||
from ebook_converter.ebooks.mobi.reader.headers import NULL_INDEX
|
from ebook_converter.ebooks.mobi.reader.headers import NULL_INDEX
|
||||||
from ebook_converter.ebooks.mobi.reader.index import read_index
|
from ebook_converter.ebooks.mobi.reader.index import read_index
|
||||||
from ebook_converter.polyglot.builtins import iteritems, getcwd
|
from ebook_converter.polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -78,7 +80,7 @@ def read_ncx(sections, index, codec):
|
|||||||
|
|
||||||
|
|
||||||
def build_toc(index_entries):
|
def build_toc(index_entries):
|
||||||
ans = TOC(base_path=getcwd())
|
ans = TOC(base_path=os.getcwd())
|
||||||
levels = {x['hlvl'] for x in index_entries}
|
levels = {x['hlvl'] for x in index_entries}
|
||||||
num_map = {-1: ans}
|
num_map = {-1: ans}
|
||||||
level_map = {l:[x for x in index_entries if x['hlvl'] == l] for l in
|
level_map = {l:[x for x in index_entries if x['hlvl'] == l] for l in
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from odf.namespaces import TEXTNS as odTEXTNS
|
|||||||
from ebook_converter import CurrentDir, walk
|
from ebook_converter import CurrentDir, walk
|
||||||
from ebook_converter.ebooks.oeb.base import _css_logger
|
from ebook_converter.ebooks.oeb.base import _css_logger
|
||||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||||
from ebook_converter.polyglot.builtins import getcwd, as_bytes
|
from ebook_converter.polyglot.builtins import as_bytes
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -300,9 +300,9 @@ class Extract(ODF2XHTML):
|
|||||||
f.write(as_bytes(html))
|
f.write(as_bytes(html))
|
||||||
zf = ZipFile(stream, 'r')
|
zf = ZipFile(stream, 'r')
|
||||||
self.extract_pictures(zf)
|
self.extract_pictures(zf)
|
||||||
opf = OPFCreator(os.path.abspath(getcwd()), mi)
|
opf = OPFCreator(os.path.abspath(os.getcwd()), mi)
|
||||||
opf.create_manifest([(os.path.abspath(f2), None) for f2 in
|
opf.create_manifest([(os.path.abspath(f2), None) for f2 in
|
||||||
walk(getcwd())])
|
walk(os.getcwd())])
|
||||||
opf.create_spine([os.path.abspath('index.xhtml')])
|
opf.create_spine([os.path.abspath('index.xhtml')])
|
||||||
with open('metadata.opf', 'wb') as f:
|
with open('metadata.opf', 'wb') as f:
|
||||||
opf.render(f)
|
opf.render(f)
|
||||||
|
|||||||
@@ -11,9 +11,8 @@
|
|||||||
# #
|
# #
|
||||||
#########################################################################
|
#########################################################################
|
||||||
import sys, os
|
import sys, os
|
||||||
from ebook_converter.polyglot.builtins import raw_input
|
|
||||||
from . import open_for_read, open_for_write
|
from . import open_for_read, open_for_write
|
||||||
# , codecs
|
|
||||||
|
|
||||||
|
|
||||||
class Output:
|
class Output:
|
||||||
@@ -83,7 +82,7 @@ class Output:
|
|||||||
msg += ('Type "o" to overwrite.\n'
|
msg += ('Type "o" to overwrite.\n'
|
||||||
'Type any other key to print to standard output.\n')
|
'Type any other key to print to standard output.\n')
|
||||||
sys.stderr.write(msg)
|
sys.stderr.write(msg)
|
||||||
user_response = raw_input()
|
user_response = input()
|
||||||
if user_response == 'o':
|
if user_response == 'o':
|
||||||
with open_for_read(self.__file) as read_obj:
|
with open_for_read(self.__file) as read_obj:
|
||||||
with open_for_write(self.output_file) as write_obj:
|
with open_for_write(self.output_file) as write_obj:
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ iterkeys = iter
|
|||||||
|
|
||||||
|
|
||||||
def hasenv(x):
|
def hasenv(x):
|
||||||
return getenv(x) is not None
|
return os.getenv(x) is not None
|
||||||
|
|
||||||
|
|
||||||
def as_bytes(x, encoding='utf-8'):
|
def as_bytes(x, encoding='utf-8'):
|
||||||
@@ -42,11 +42,6 @@ def reraise(tp, value, tb=None):
|
|||||||
tb = None
|
tb = None
|
||||||
|
|
||||||
|
|
||||||
raw_input = input
|
|
||||||
getcwd = os.getcwd
|
|
||||||
getenv = os.getenv
|
|
||||||
|
|
||||||
|
|
||||||
def error_message(exc):
|
def error_message(exc):
|
||||||
args = getattr(exc, 'args', None)
|
args = getattr(exc, 'args', None)
|
||||||
if args and isinstance(args[0], str):
|
if args and isinstance(args[0], str):
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ Provides platform independent temporary files that persist even after
|
|||||||
being closed.
|
being closed.
|
||||||
"""
|
"""
|
||||||
import tempfile, os, atexit
|
import tempfile, os, atexit
|
||||||
from ebook_converter.polyglot.builtins import getenv
|
|
||||||
|
|
||||||
from ebook_converter.constants import (__version__, __appname__, filesystem_encoding,
|
from ebook_converter.constants import (__version__, __appname__, filesystem_encoding,
|
||||||
iswindows, get_windows_temp_path, isosx, ispy3)
|
iswindows, get_windows_temp_path, isosx, ispy3)
|
||||||
@@ -101,7 +100,7 @@ def base_dir():
|
|||||||
else:
|
else:
|
||||||
base = os.environ.get('CALIBRE_TEMP_DIR', None)
|
base = os.environ.get('CALIBRE_TEMP_DIR', None)
|
||||||
if base is not None and iswindows:
|
if base is not None and iswindows:
|
||||||
base = getenv('CALIBRE_TEMP_DIR')
|
base = os.getenv('CALIBRE_TEMP_DIR')
|
||||||
prefix = app_prefix('tmp_')
|
prefix = app_prefix('tmp_')
|
||||||
if base is None:
|
if base is None:
|
||||||
if iswindows:
|
if iswindows:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from ebook_converter.constants import isosx, isfrozen, filesystem_encoding, ispy
|
|||||||
from ebook_converter.utils.config import prefs
|
from ebook_converter.utils.config import prefs
|
||||||
from ebook_converter.ptempfile import PersistentTemporaryFile, base_dir
|
from ebook_converter.ptempfile import PersistentTemporaryFile, base_dir
|
||||||
from ebook_converter.utils.serialize import msgpack_dumps
|
from ebook_converter.utils.serialize import msgpack_dumps
|
||||||
from ebook_converter.polyglot.builtins import iteritems, environ_item, native_string_type, getcwd
|
from ebook_converter.polyglot.builtins import iteritems, environ_item, native_string_type
|
||||||
from ebook_converter.polyglot.binary import as_hex_unicode
|
from ebook_converter.polyglot.binary import as_hex_unicode
|
||||||
try:
|
try:
|
||||||
import win32process
|
import win32process
|
||||||
@@ -183,7 +183,7 @@ class Worker(object):
|
|||||||
exe = self.gui_executable if self.gui else self.executable
|
exe = self.gui_executable if self.gui else self.executable
|
||||||
env = self.env
|
env = self.env
|
||||||
try:
|
try:
|
||||||
origwd = cwd or os.path.abspath(getcwd())
|
origwd = cwd or os.path.abspath(os.getcwd())
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
# cwd no longer exists
|
# cwd no longer exists
|
||||||
origwd = cwd or os.path.expanduser('~')
|
origwd = cwd or os.path.expanduser('~')
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from struct import calcsize, unpack, pack
|
|||||||
from collections import namedtuple, OrderedDict
|
from collections import namedtuple, OrderedDict
|
||||||
from tempfile import SpooledTemporaryFile
|
from tempfile import SpooledTemporaryFile
|
||||||
|
|
||||||
from ebook_converter.polyglot.builtins import itervalues, getcwd
|
from ebook_converter.polyglot.builtins import itervalues
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -243,7 +243,7 @@ def extractall(path_or_stream, path=None):
|
|||||||
f = open(f, 'rb')
|
f = open(f, 'rb')
|
||||||
close_at_end = True
|
close_at_end = True
|
||||||
if path is None:
|
if path is None:
|
||||||
path = getcwd()
|
path = os.getcwd()
|
||||||
pos = f.tell()
|
pos = f.tell()
|
||||||
try:
|
try:
|
||||||
_extractall(f, path)
|
_extractall(f, path)
|
||||||
@@ -290,7 +290,7 @@ class LocalZipFile(object):
|
|||||||
|
|
||||||
def extractall(self, path=None):
|
def extractall(self, path=None):
|
||||||
self.stream.seek(0)
|
self.stream.seek(0)
|
||||||
_extractall(self.stream, path=(path or getcwd()))
|
_extractall(self.stream, path=(path or os.getcwd()))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from tempfile import SpooledTemporaryFile
|
|||||||
from ebook_converter import sanitize_file_name
|
from ebook_converter import sanitize_file_name
|
||||||
from ebook_converter.constants import filesystem_encoding
|
from ebook_converter.constants import filesystem_encoding
|
||||||
from ebook_converter.ebooks.chardet import detect
|
from ebook_converter.ebooks.chardet import detect
|
||||||
from ebook_converter.polyglot.builtins import getcwd, as_bytes
|
from ebook_converter.polyglot.builtins import as_bytes
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import zlib # We may need its compression method
|
import zlib # We may need its compression method
|
||||||
@@ -1085,7 +1085,7 @@ class ZipFile:
|
|||||||
member = self.getinfo(member)
|
member = self.getinfo(member)
|
||||||
|
|
||||||
if path is None:
|
if path is None:
|
||||||
path = getcwd()
|
path = os.getcwd()
|
||||||
|
|
||||||
return self._extract_member(member, path, pwd)
|
return self._extract_member(member, path, pwd)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user