mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont depend on calibre in polyglot
This commit is contained in:
parent
bd118e6139
commit
a08bdbeb4e
@ -45,7 +45,7 @@ def build_manual(language, base):
|
|||||||
onlinedir = sb(t='online')
|
onlinedir = sb(t='online')
|
||||||
epubdir = sb('myepub', 'epub')
|
epubdir = sb('myepub', 'epub')
|
||||||
latexdir = sb('mylatex', 'latex')
|
latexdir = sb('mylatex', 'latex')
|
||||||
pwd = os.getcwdu()
|
pwd = os.getcwd()
|
||||||
os.chdir(latexdir)
|
os.chdir(latexdir)
|
||||||
|
|
||||||
def run_cmd(cmd):
|
def run_cmd(cmd):
|
||||||
|
@ -183,7 +183,7 @@ class AppleDaily(BasicNewsRecipe):
|
|||||||
if mp is not None and os.access(mp, os.R_OK):
|
if mp is not None and os.access(mp, os.R_OK):
|
||||||
from calibre.ebooks.metadata.opf2 import Guide
|
from calibre.ebooks.metadata.opf2 import Guide
|
||||||
ref = Guide.Reference(os.path.basename(
|
ref = Guide.Reference(os.path.basename(
|
||||||
self.masthead_path), os.getcwdu())
|
self.masthead_path), os.getcwd())
|
||||||
ref.type = 'masthead'
|
ref.type = 'masthead'
|
||||||
ref.title = 'Masthead Image'
|
ref.title = 'Masthead Image'
|
||||||
opf.guide.append(ref)
|
opf.guide.append(ref)
|
||||||
|
@ -1062,7 +1062,7 @@ class MPRecipe(BasicNewsRecipe):
|
|||||||
if mp is not None and os.access(mp, os.R_OK):
|
if mp is not None and os.access(mp, os.R_OK):
|
||||||
from calibre.ebooks.metadata.opf2 import Guide
|
from calibre.ebooks.metadata.opf2 import Guide
|
||||||
ref = Guide.Reference(os.path.basename(
|
ref = Guide.Reference(os.path.basename(
|
||||||
self.masthead_path), os.getcwdu())
|
self.masthead_path), os.getcwd())
|
||||||
ref.type = 'masthead'
|
ref.type = 'masthead'
|
||||||
ref.title = 'Masthead Image'
|
ref.title = 'Masthead Image'
|
||||||
opf.guide.append(ref)
|
opf.guide.append(ref)
|
||||||
|
@ -900,7 +900,7 @@ class MPRecipe(BasicNewsRecipe):
|
|||||||
if mp is not None and os.access(mp, os.R_OK):
|
if mp is not None and os.access(mp, os.R_OK):
|
||||||
from calibre.ebooks.metadata.opf2 import Guide
|
from calibre.ebooks.metadata.opf2 import Guide
|
||||||
ref = Guide.Reference(os.path.basename(
|
ref = Guide.Reference(os.path.basename(
|
||||||
self.masthead_path), os.getcwdu())
|
self.masthead_path), os.getcwd())
|
||||||
ref.type = 'masthead'
|
ref.type = 'masthead'
|
||||||
ref.title = 'Masthead Image'
|
ref.title = 'Masthead Image'
|
||||||
opf.guide.append(ref)
|
opf.guide.append(ref)
|
||||||
|
@ -900,7 +900,7 @@ class MPRecipe(BasicNewsRecipe):
|
|||||||
if mp is not None and os.access(mp, os.R_OK):
|
if mp is not None and os.access(mp, os.R_OK):
|
||||||
from calibre.ebooks.metadata.opf2 import Guide
|
from calibre.ebooks.metadata.opf2 import Guide
|
||||||
ref = Guide.Reference(os.path.basename(
|
ref = Guide.Reference(os.path.basename(
|
||||||
self.masthead_path), os.getcwdu())
|
self.masthead_path), os.getcwd())
|
||||||
ref.type = 'masthead'
|
ref.type = 'masthead'
|
||||||
ref.title = 'Masthead Image'
|
ref.title = 'Masthead Image'
|
||||||
opf.guide.append(ref)
|
opf.guide.append(ref)
|
||||||
|
@ -412,7 +412,7 @@ class STHKRecipe(BasicNewsRecipe):
|
|||||||
if mp is not None and os.access(mp, os.R_OK):
|
if mp is not None and os.access(mp, os.R_OK):
|
||||||
from calibre.ebooks.metadata.opf2 import Guide
|
from calibre.ebooks.metadata.opf2 import Guide
|
||||||
ref = Guide.Reference(os.path.basename(
|
ref = Guide.Reference(os.path.basename(
|
||||||
self.masthead_path), os.getcwdu())
|
self.masthead_path), os.getcwd())
|
||||||
ref.type = 'masthead'
|
ref.type = 'masthead'
|
||||||
ref.title = 'Masthead Image'
|
ref.title = 'Masthead Image'
|
||||||
opf.guide.append(ref)
|
opf.guide.append(ref)
|
||||||
|
@ -24,8 +24,6 @@ sys.path.insert(0, SRC)
|
|||||||
sys.resources_location = os.path.join(os.path.dirname(SRC), 'resources')
|
sys.resources_location = os.path.join(os.path.dirname(SRC), 'resources')
|
||||||
sys.extensions_location = os.path.abspath(os.environ.get('CALIBRE_SETUP_EXTENSIONS_PATH', os.path.join(SRC, 'calibre', 'plugins')))
|
sys.extensions_location = os.path.abspath(os.environ.get('CALIBRE_SETUP_EXTENSIONS_PATH', os.path.join(SRC, 'calibre', 'plugins')))
|
||||||
sys.running_from_setup = True
|
sys.running_from_setup = True
|
||||||
if not hasattr(os, 'getcwdu'):
|
|
||||||
os.getcwdu = os.getcwd
|
|
||||||
|
|
||||||
__version__ = __appname__ = modules = functions = basenames = scripts = None
|
__version__ = __appname__ = modules = functions = basenames = scripts = None
|
||||||
|
|
||||||
|
@ -502,7 +502,7 @@ class Build(Command):
|
|||||||
proname = '%s.pro' % sip['target']
|
proname = '%s.pro' % sip['target']
|
||||||
with open(os.path.join(src_dir, proname), 'wb') as f:
|
with open(os.path.join(src_dir, proname), 'wb') as f:
|
||||||
f.write(pro.encode('utf-8'))
|
f.write(pro.encode('utf-8'))
|
||||||
cwd = os.getcwdu()
|
cwd = os.getcwd()
|
||||||
qmc = []
|
qmc = []
|
||||||
if iswindows:
|
if iswindows:
|
||||||
qmc += ['-spec', qmakespec]
|
qmc += ['-spec', qmakespec]
|
||||||
|
@ -220,7 +220,7 @@ class Manual(Command):
|
|||||||
subprocess.check_call(jobs[0][0])
|
subprocess.check_call(jobs[0][0])
|
||||||
if not parallel_build(jobs[1:], self.info):
|
if not parallel_build(jobs[1:], self.info):
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
cwd = os.getcwdu()
|
cwd = os.getcwd()
|
||||||
try:
|
try:
|
||||||
os.chdir(self.j(tdir, 'en', 'html'))
|
os.chdir(self.j(tdir, 'en', 'html'))
|
||||||
for x in os.listdir(tdir):
|
for x in os.listdir(tdir):
|
||||||
@ -311,7 +311,7 @@ class ManPages(Command):
|
|||||||
subprocess.check_call(jobs[0][0])
|
subprocess.check_call(jobs[0][0])
|
||||||
if not parallel_build(jobs[1:], self.info, verbose=False):
|
if not parallel_build(jobs[1:], self.info, verbose=False):
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
cwd = os.getcwdu()
|
cwd = os.getcwd()
|
||||||
os.chdir(dest)
|
os.chdir(dest)
|
||||||
try:
|
try:
|
||||||
for x in tuple(os.listdir('.')):
|
for x in tuple(os.listdir('.')):
|
||||||
|
@ -5,21 +5,15 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import sys, os, re, time, random, warnings
|
import sys, os, re, time, random, warnings
|
||||||
from polyglot.builtins import (builtins, codepoint_to_chr, iteritems,
|
from polyglot.builtins import (builtins, codepoint_to_chr, iteritems,
|
||||||
itervalues, unicode_type, range, filter)
|
itervalues, unicode_type, range, filter, hasenv)
|
||||||
builtins.__dict__['dynamic_property'] = lambda func: func(None)
|
builtins.__dict__['dynamic_property'] = lambda func: func(None)
|
||||||
from math import floor
|
from math import floor
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
if 'CALIBRE_SHOW_DEPRECATION_WARNINGS' not in os.environ:
|
if not hasenv('CALIBRE_SHOW_DEPRECATION_WARNINGS'):
|
||||||
warnings.simplefilter('ignore', DeprecationWarning)
|
warnings.simplefilter('ignore', DeprecationWarning)
|
||||||
try:
|
try:
|
||||||
os.getcwdu()
|
os.getcwd()
|
||||||
except AttributeError:
|
|
||||||
os.getcwdu = os.getcwd
|
|
||||||
try:
|
|
||||||
os.getcwd()
|
|
||||||
except EnvironmentError:
|
|
||||||
os.chdir(os.path.expanduser('~'))
|
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
os.chdir(os.path.expanduser('~'))
|
os.chdir(os.path.expanduser('~'))
|
||||||
|
|
||||||
@ -446,7 +440,7 @@ class CurrentDir(object):
|
|||||||
self.cwd = None
|
self.cwd = None
|
||||||
|
|
||||||
def __enter__(self, *args):
|
def __enter__(self, *args):
|
||||||
self.cwd = os.getcwdu()
|
self.cwd = os.getcwd()
|
||||||
os.chdir(self.path)
|
os.chdir(self.path)
|
||||||
return self.cwd
|
return self.cwd
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
from polyglot.builtins import map, unicode_type, hasenv, getenv, environ_item
|
from polyglot.builtins import map, unicode_type, environ_item, hasenv, getenv
|
||||||
import sys, locale, codecs, os, importlib, collections
|
import sys, locale, codecs, os, importlib, collections
|
||||||
|
|
||||||
__appname__ = 'calibre'
|
__appname__ = 'calibre'
|
||||||
@ -300,12 +300,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(get_unicode_windows_env_var('CALIBRE_PORTABLE_BUILD')))
|
return os.path.dirname(os.path.dirname(getenv('CALIBRE_PORTABLE_BUILD')))
|
||||||
|
|
||||||
|
|
||||||
def get_unicode_windows_env_var(name):
|
|
||||||
getenv = plugins['winutil'][0].getenv
|
|
||||||
return getenv(unicode_type(name))
|
|
||||||
|
|
||||||
|
|
||||||
def get_windows_username():
|
def get_windows_username():
|
||||||
|
@ -11,7 +11,7 @@ from calibre.ebooks.metadata.book.base import field_from_string
|
|||||||
from calibre.ebooks.metadata.book.serialize import read_cover
|
from calibre.ebooks.metadata.book.serialize import read_cover
|
||||||
from calibre.ebooks.metadata.opf import get_metadata
|
from calibre.ebooks.metadata.opf import get_metadata
|
||||||
from calibre.srv.changes import metadata
|
from calibre.srv.changes import metadata
|
||||||
from polyglot.builtins import iteritems, unicode_type
|
from polyglot.builtins import iteritems, unicode_type, getcwd
|
||||||
|
|
||||||
readonly = False
|
readonly = False
|
||||||
version = 0 # change this if you change signature of implementation()
|
version = 0 # change this if you change signature of implementation()
|
||||||
@ -148,7 +148,7 @@ def main(opts, args, dbctx):
|
|||||||
with lopen(opf, 'rb') as stream:
|
with lopen(opf, 'rb') as stream:
|
||||||
mi = get_metadata(stream)[0]
|
mi = get_metadata(stream)[0]
|
||||||
if mi.cover:
|
if mi.cover:
|
||||||
mi.cover = os.path.join(os.path.dirname(opf), os.path.relpath(mi.cover, os.getcwdu()))
|
mi.cover = os.path.join(os.path.dirname(opf), os.path.relpath(mi.cover, getcwd()))
|
||||||
final_mi = dbctx.run('set_metadata', 'opf', book_id, read_cover(mi))
|
final_mi = dbctx.run('set_metadata', 'opf', book_id, read_cover(mi))
|
||||||
if not final_mi:
|
if not final_mi:
|
||||||
raise SystemExit(_('No book with id: %s in the database') % book_id)
|
raise SystemExit(_('No book with id: %s in the database') % book_id)
|
||||||
|
@ -4,12 +4,11 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, getcwd
|
||||||
|
|
||||||
readonly = True
|
readonly = True
|
||||||
version = 0 # change this if you change signature of implementation()
|
version = 0 # change this if you change signature of implementation()
|
||||||
@ -50,7 +49,7 @@ def main(opts, args, dbctx):
|
|||||||
if mi is None:
|
if mi is None:
|
||||||
raise SystemExit('Id #%d is not present in database.' % id)
|
raise SystemExit('Id #%d is not present in database.' % id)
|
||||||
if opts.as_opf:
|
if opts.as_opf:
|
||||||
mi = OPFCreator(os.getcwdu(), mi)
|
mi = OPFCreator(getcwd(), mi)
|
||||||
mi.render(sys.stdout)
|
mi.render(sys.stdout)
|
||||||
else:
|
else:
|
||||||
prints(unicode_type(mi))
|
prints(unicode_type(mi))
|
||||||
|
@ -11,7 +11,7 @@ import sys, os, functools
|
|||||||
from calibre.utils.config import OptionParser
|
from calibre.utils.config import OptionParser
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from polyglot.builtins import exec_path, raw_input, unicode_type
|
from polyglot.builtins import exec_path, raw_input, unicode_type, getcwd
|
||||||
|
|
||||||
|
|
||||||
def get_debug_executable():
|
def get_debug_executable():
|
||||||
@ -174,7 +174,7 @@ def add_simple_plugin(path_to_plugin):
|
|||||||
tdir = tempfile.mkdtemp()
|
tdir = tempfile.mkdtemp()
|
||||||
open(os.path.join(tdir, 'custom_plugin.py'),
|
open(os.path.join(tdir, 'custom_plugin.py'),
|
||||||
'wb').write(open(path_to_plugin, 'rb').read())
|
'wb').write(open(path_to_plugin, 'rb').read())
|
||||||
odir = os.getcwdu()
|
odir = getcwd()
|
||||||
os.chdir(tdir)
|
os.chdir(tdir)
|
||||||
zf = zipfile.ZipFile('plugin.zip', 'w')
|
zf = zipfile.ZipFile('plugin.zip', 'w')
|
||||||
zf.write('custom_plugin.py')
|
zf.write('custom_plugin.py')
|
||||||
|
@ -29,7 +29,7 @@ from calibre.ebooks.docx.fields import Fields
|
|||||||
from calibre.ebooks.docx.settings import Settings
|
from calibre.ebooks.docx.settings import Settings
|
||||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||||
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
|
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||||
from polyglot.builtins import iteritems, itervalues, filter
|
from polyglot.builtins import iteritems, itervalues, filter, getcwd
|
||||||
|
|
||||||
|
|
||||||
NBSP = '\xa0'
|
NBSP = '\xa0'
|
||||||
@ -70,7 +70,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 os.getcwdu()
|
self.dest_dir = dest_dir or 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)
|
||||||
@ -831,7 +831,7 @@ if __name__ == '__main__':
|
|||||||
import shutil
|
import shutil
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
default_log.filter_level = default_log.DEBUG
|
default_log.filter_level = default_log.DEBUG
|
||||||
dest_dir = os.path.join(os.getcwdu(), 'docx_input')
|
dest_dir = os.path.join(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)
|
||||||
|
@ -19,7 +19,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 polyglot.builtins import itervalues
|
from polyglot.builtins import itervalues, getcwd
|
||||||
|
|
||||||
HEADER_SIG = 0x04034b50
|
HEADER_SIG = 0x04034b50
|
||||||
HEADER_BYTE_SIG = pack(b'<L', HEADER_SIG)
|
HEADER_BYTE_SIG = pack(b'<L', HEADER_SIG)
|
||||||
@ -227,7 +227,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 = os.getcwdu()
|
path = getcwd()
|
||||||
pos = f.tell()
|
pos = f.tell()
|
||||||
try:
|
try:
|
||||||
_extractall(f, path)
|
_extractall(f, path)
|
||||||
@ -275,7 +275,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 os.getcwdu()))
|
_extractall(self.stream, path=(path or getcwd()))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
@ -16,7 +16,7 @@ from itertools import islice
|
|||||||
from calibre import detect_ncpus as cpu_count, as_unicode
|
from calibre import detect_ncpus as cpu_count, as_unicode
|
||||||
from calibre.constants import plugins, filesystem_encoding
|
from calibre.constants import plugins, filesystem_encoding
|
||||||
from calibre.utils.icu import primary_sort_key, primary_find, primary_collator
|
from calibre.utils.icu import primary_sort_key, primary_find, primary_collator
|
||||||
from polyglot.builtins import iteritems, itervalues, map, unicode_type, range, zip, raw_input, filter
|
from polyglot.builtins import iteritems, itervalues, map, unicode_type, range, zip, raw_input, filter, getcwd
|
||||||
from polyglot.queue import Queue
|
from polyglot.queue import Queue
|
||||||
|
|
||||||
DEFAULT_LEVEL1 = '/'
|
DEFAULT_LEVEL1 = '/'
|
||||||
@ -347,8 +347,8 @@ def main(basedir=None, query=None):
|
|||||||
from calibre.utils.terminal import ColoredStream
|
from calibre.utils.terminal import ColoredStream
|
||||||
if basedir is None:
|
if basedir is None:
|
||||||
try:
|
try:
|
||||||
basedir = input_unicode('Enter directory to scan [%s]: ' % os.getcwdu()
|
basedir = input_unicode('Enter directory to scan [%s]: ' % getcwd()
|
||||||
).strip() or os.getcwdu()
|
).strip() or getcwd()
|
||||||
except (EOFError, KeyboardInterrupt):
|
except (EOFError, KeyboardInterrupt):
|
||||||
return
|
return
|
||||||
m = FilesystemMatcher(basedir)
|
m = FilesystemMatcher(basedir)
|
||||||
|
@ -22,7 +22,7 @@ from calibre.utils.filenames import atomic_rename
|
|||||||
from calibre.utils.terminal import ANSIStream
|
from calibre.utils.terminal import ANSIStream
|
||||||
from duktape import Context, JSError, to_python
|
from duktape import Context, JSError, to_python
|
||||||
from lzma.xz import compress, decompress
|
from lzma.xz import compress, decompress
|
||||||
from polyglot.builtins import itervalues, range, exec_path, raw_input, error_message, filter
|
from polyglot.builtins import itervalues, range, exec_path, raw_input, error_message, filter, getcwd
|
||||||
from polyglot.queue import Empty, Queue
|
from polyglot.queue import Empty, Queue
|
||||||
|
|
||||||
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
||||||
@ -107,7 +107,7 @@ def compile_pyj(data, filename='<stdin>', beautify=True, private_scope=True, lib
|
|||||||
'private_scope':private_scope,
|
'private_scope':private_scope,
|
||||||
'omit_baselib': omit_baselib,
|
'omit_baselib': omit_baselib,
|
||||||
'libdir': libdir or default_lib_dir(),
|
'libdir': libdir or default_lib_dir(),
|
||||||
'basedir': os.getcwdu() if not filename or filename == '<stdin>' else os.path.dirname(filename),
|
'basedir': getcwd() if not filename or filename == '<stdin>' else os.path.dirname(filename),
|
||||||
'filename': filename,
|
'filename': filename,
|
||||||
}
|
}
|
||||||
c.g.rs_source_code = data
|
c.g.rs_source_code = data
|
||||||
|
@ -17,7 +17,7 @@ from threading import Lock, local
|
|||||||
|
|
||||||
from polyglot import socketserver
|
from polyglot import socketserver
|
||||||
from polyglot.http_server import HTTPServer, SimpleHTTPRequestHandler
|
from polyglot.http_server import HTTPServer, SimpleHTTPRequestHandler
|
||||||
from polyglot.builtins import error_message
|
from polyglot.builtins import error_message, getcwd
|
||||||
|
|
||||||
# Compiler {{{
|
# Compiler {{{
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ def serve(resources={}, port=8000, host='0.0.0.0'):
|
|||||||
Handler.special_resources = resources
|
Handler.special_resources = resources
|
||||||
Handler.compiler = compile_coffeescript
|
Handler.compiler = compile_coffeescript
|
||||||
httpd = Server((host, port), Handler)
|
httpd = Server((host, port), Handler)
|
||||||
print('serving %s at %s:%d with PID=%d'%(os.getcwdu(), host, port, os.getpid()))
|
print('serving %s at %s:%d with PID=%d'%(getcwd(), host, port, os.getpid()))
|
||||||
try:
|
try:
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
@ -19,7 +19,7 @@ from calibre.utils.tdir_in_cache import (
|
|||||||
clean_tdirs_in, is_tdir_locked, retry_lock_tdir, tdir_in_cache, tdirs_in,
|
clean_tdirs_in, is_tdir_locked, retry_lock_tdir, tdir_in_cache, tdirs_in,
|
||||||
unlock_file
|
unlock_file
|
||||||
)
|
)
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems, getcwd
|
||||||
|
|
||||||
|
|
||||||
def FastFailEF(name):
|
def FastFailEF(name):
|
||||||
@ -177,13 +177,13 @@ def other3():
|
|||||||
|
|
||||||
|
|
||||||
def other4():
|
def other4():
|
||||||
cache_dir.ans = os.getcwdu()
|
cache_dir.ans = getcwd()
|
||||||
tdir_in_cache('t')
|
tdir_in_cache('t')
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
|
|
||||||
|
|
||||||
def other5():
|
def other5():
|
||||||
cache_dir.ans = os.getcwdu()
|
cache_dir.ans = getcwd()
|
||||||
if not os.path.isdir(tdir_in_cache('t')):
|
if not os.path.isdir(tdir_in_cache('t')):
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ from tempfile import SpooledTemporaryFile
|
|||||||
from calibre import sanitize_file_name
|
from calibre import sanitize_file_name
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.ebooks.chardet import detect
|
from calibre.ebooks.chardet import detect
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes, getcwd
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import zlib # We may need its compression method
|
import zlib # We may need its compression method
|
||||||
@ -1083,7 +1083,7 @@ class ZipFile:
|
|||||||
member = self.getinfo(member)
|
member = self.getinfo(member)
|
||||||
|
|
||||||
if path is None:
|
if path is None:
|
||||||
path = os.getcwdu()
|
path = getcwd()
|
||||||
|
|
||||||
return self._extract_member(member, path, pwd)
|
return self._extract_member(member, path, pwd)
|
||||||
|
|
||||||
@ -1334,7 +1334,7 @@ class ZipFile:
|
|||||||
'''
|
'''
|
||||||
if prefix:
|
if prefix:
|
||||||
self.writestr(prefix+'/', b'', 0o755)
|
self.writestr(prefix+'/', b'', 0o755)
|
||||||
cwd = os.path.abspath(os.getcwdu())
|
cwd = os.path.abspath(getcwd())
|
||||||
try:
|
try:
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
fp = (prefix + ('/' if prefix else '')).replace('//', '/')
|
fp = (prefix + ('/' if prefix else '')).replace('//', '/')
|
||||||
|
@ -29,7 +29,7 @@ from calibre.utils.icu import numeric_sort_key
|
|||||||
from calibre.utils.img import save_cover_data_to, add_borders_to_image, image_to_data
|
from calibre.utils.img import save_cover_data_to, add_borders_to_image, image_to_data
|
||||||
from calibre.utils.localization import canonicalize_lang
|
from calibre.utils.localization import canonicalize_lang
|
||||||
from calibre.utils.logging import ThreadSafeWrapper
|
from calibre.utils.logging import ThreadSafeWrapper
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes, getcwd
|
||||||
from polyglot.urllib import urlparse, urlsplit
|
from polyglot.urllib import urlparse, urlsplit
|
||||||
|
|
||||||
|
|
||||||
@ -870,7 +870,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
self.title = unicode_type(self.title, 'utf-8', 'replace')
|
self.title = unicode_type(self.title, 'utf-8', 'replace')
|
||||||
|
|
||||||
self.debug = options.verbose > 1
|
self.debug = options.verbose > 1
|
||||||
self.output_dir = os.path.abspath(os.getcwdu())
|
self.output_dir = os.path.abspath(getcwd())
|
||||||
self.verbose = options.verbose
|
self.verbose = options.verbose
|
||||||
self.test = options.test
|
self.test = options.test
|
||||||
if self.test and not isinstance(self.test, tuple):
|
if self.test and not isinstance(self.test, tuple):
|
||||||
@ -1457,7 +1457,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
mp = getattr(self, 'masthead_path', None)
|
mp = getattr(self, 'masthead_path', None)
|
||||||
if mp is not None and os.access(mp, os.R_OK):
|
if mp is not None and os.access(mp, os.R_OK):
|
||||||
from calibre.ebooks.metadata.opf2 import Guide
|
from calibre.ebooks.metadata.opf2 import Guide
|
||||||
ref = Guide.Reference(os.path.basename(self.masthead_path), os.getcwdu())
|
ref = Guide.Reference(os.path.basename(self.masthead_path), getcwd())
|
||||||
ref.type = 'masthead'
|
ref.type = 'masthead'
|
||||||
ref.title = 'Masthead Image'
|
ref.title = 'Masthead Image'
|
||||||
opf.guide.append(ref)
|
opf.guide.append(ref)
|
||||||
|
@ -74,6 +74,8 @@ if is_py3:
|
|||||||
string_or_bytes = str, bytes
|
string_or_bytes = str, bytes
|
||||||
long_type = int
|
long_type = int
|
||||||
raw_input = input
|
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)
|
||||||
@ -92,9 +94,6 @@ if is_py3:
|
|||||||
x = x.decode('utf-8')
|
x = x.decode('utf-8')
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def getenv(x, default=None):
|
|
||||||
return os.environ.get(environ_item(x), default)
|
|
||||||
|
|
||||||
def exec_path(path, ctx=None):
|
def exec_path(path, ctx=None):
|
||||||
ctx = ctx or {}
|
ctx = ctx or {}
|
||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
@ -132,6 +131,7 @@ else:
|
|||||||
raw_input = builtins.raw_input
|
raw_input = builtins.raw_input
|
||||||
cmp = builtins.cmp
|
cmp = builtins.cmp
|
||||||
int_to_byte = chr
|
int_to_byte = chr
|
||||||
|
getcwd = os.getcwdu
|
||||||
|
|
||||||
def error_message(exc):
|
def error_message(exc):
|
||||||
ans = exc.message
|
ans = exc.message
|
||||||
@ -152,16 +152,16 @@ else:
|
|||||||
|
|
||||||
if hasattr(sys, 'getwindowsversion'):
|
if hasattr(sys, 'getwindowsversion'):
|
||||||
def getenv(x, default=None):
|
def getenv(x, default=None):
|
||||||
from calibre.constants import get_unicode_windows_env_var
|
from win32api import GetEnvironmentVariableW
|
||||||
if isinstance(x, bytes):
|
if isinstance(x, bytes):
|
||||||
x = x.decode('mbcs', 'replace')
|
x = x.decode('mbcs', 'replace')
|
||||||
ans = get_unicode_windows_env_var(x)
|
ans = GetEnvironmentVariableW(x)
|
||||||
if ans is None:
|
if ans is None:
|
||||||
ans = default
|
ans = default
|
||||||
return ans
|
return ans
|
||||||
else:
|
else:
|
||||||
def getenv(x, default=None):
|
def getenv(x, default=None):
|
||||||
ans = os.environ.get(environ_item(x), default)
|
ans = os.getenv(x, default)
|
||||||
if isinstance(ans, bytes):
|
if isinstance(ans, bytes):
|
||||||
ans = ans.decode('utf-8', 'replace')
|
ans = ans.decode('utf-8', 'replace')
|
||||||
return ans
|
return ans
|
||||||
|
Loading…
x
Reference in New Issue
Block a user