mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-01-30 02:05:45 +01:00
Removing polyglot getcwd and getenv
This commit is contained in:
@@ -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':
|
||||
|
||||
Reference in New Issue
Block a user