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