mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: misc fixes to get bootstrapping (almost) working
This commit is contained in:
parent
f809313dc5
commit
67814d2186
@ -11,7 +11,7 @@ from collections import defaultdict
|
|||||||
from locale import normalize as normalize_locale
|
from locale import normalize as normalize_locale
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from setup import Command, __appname__, __version__, require_git_master, build_cache_dir, edit_file, dump_json
|
from setup import Command, __appname__, __version__, require_git_master, build_cache_dir, edit_file, dump_json, ispy3
|
||||||
from setup.parallel_build import parallel_check_output
|
from setup.parallel_build import parallel_check_output
|
||||||
from polyglot.builtins import codepoint_to_chr, iteritems, range
|
from polyglot.builtins import codepoint_to_chr, iteritems, range
|
||||||
is_ci = os.environ.get('CI', '').lower() == 'true'
|
is_ci = os.environ.get('CI', '').lower() == 'true'
|
||||||
@ -508,15 +508,18 @@ class Translations(POT): # {{{
|
|||||||
if l == 'en':
|
if l == 'en':
|
||||||
t = get_language
|
t = get_language
|
||||||
else:
|
else:
|
||||||
t = get_iso639_translator(l).ugettext
|
t = getattr(get_iso639_translator(l), 'gettext' if ispy3 else 'ugettext')
|
||||||
t = partial(get_iso_language, t)
|
t = partial(get_iso_language, t)
|
||||||
lang_names[l] = {x: t(x) for x in dl}
|
lang_names[l] = {x: t(x) for x in dl}
|
||||||
zi = ZipInfo('lang-names.json')
|
zi = ZipInfo('lang-names.json')
|
||||||
zi.compress_type = ZIP_STORED
|
zi.compress_type = ZIP_STORED
|
||||||
zf.writestr(zi, json.dumps(lang_names, ensure_ascii=False).encode('utf-8'))
|
zf.writestr(zi, json.dumps(lang_names, ensure_ascii=False).encode('utf-8'))
|
||||||
dest = self.j(self.d(self.stats), 'website-languages.txt')
|
dest = self.j(self.d(self.stats), 'website-languages.txt')
|
||||||
|
data = ' '.join(sorted(done))
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
with open(dest, 'wb') as f:
|
with open(dest, 'wb') as f:
|
||||||
f.write(' '.join(sorted(done)))
|
f.write(data)
|
||||||
|
|
||||||
def compile_user_manual_translations(self):
|
def compile_user_manual_translations(self):
|
||||||
self.info('Compiling user manual translations...')
|
self.info('Compiling user manual translations...')
|
||||||
|
@ -69,7 +69,7 @@ def compiler():
|
|||||||
c.eval('exports = {}; sha1sum = Duktape.sha1sum;', noreturn=True)
|
c.eval('exports = {}; sha1sum = Duktape.sha1sum;', noreturn=True)
|
||||||
buf = BytesIO()
|
buf = BytesIO()
|
||||||
decompress(P(COMPILER_PATH, data=True, allow_user_override=False), buf)
|
decompress(P(COMPILER_PATH, data=True, allow_user_override=False), buf)
|
||||||
c.eval(buf.getvalue(), fname=COMPILER_PATH, noreturn=True)
|
c.eval(buf.getvalue().decode('utf-8'), fname=COMPILER_PATH, noreturn=True)
|
||||||
return c
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
@ -334,8 +334,8 @@ class ZipInfo (object):
|
|||||||
self.date_time = date_time # year, month, day, hour, min, sec
|
self.date_time = date_time # year, month, day, hour, min, sec
|
||||||
# Standard values:
|
# Standard values:
|
||||||
self.compress_type = ZIP_STORED # Type of compression for the file
|
self.compress_type = ZIP_STORED # Type of compression for the file
|
||||||
self.comment = "" # Comment for each file
|
self.comment = b"" # Comment for each file
|
||||||
self.extra = "" # ZIP extra data
|
self.extra = b"" # ZIP extra data
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
self.create_system = 0 # System which created ZIP archive
|
self.create_system = 0 # System which created ZIP archive
|
||||||
else:
|
else:
|
||||||
@ -744,7 +744,7 @@ class ZipFile:
|
|||||||
self.compression = compression # Method of compression
|
self.compression = compression # Method of compression
|
||||||
self.mode = key = mode.replace('b', '')[0]
|
self.mode = key = mode.replace('b', '')[0]
|
||||||
self.pwd = None
|
self.pwd = None
|
||||||
self.comment = ''
|
self.comment = b''
|
||||||
|
|
||||||
# Check if we were passed a file-like object
|
# Check if we were passed a file-like object
|
||||||
if isinstance(file, string_or_bytes):
|
if isinstance(file, string_or_bytes):
|
||||||
@ -1280,13 +1280,15 @@ class ZipFile:
|
|||||||
self.filelist.append(zinfo)
|
self.filelist.append(zinfo)
|
||||||
self.NameToInfo[zinfo.filename] = zinfo
|
self.NameToInfo[zinfo.filename] = zinfo
|
||||||
|
|
||||||
def writestr(self, zinfo_or_arcname, bytes, permissions=0o600,
|
def writestr(self, zinfo_or_arcname, byts, permissions=0o600,
|
||||||
compression=ZIP_DEFLATED, raw_bytes=False):
|
compression=ZIP_DEFLATED, raw_bytes=False):
|
||||||
"""Write a file into the archive. The contents is the string
|
"""Write a file into the archive. The contents is the string
|
||||||
'bytes'. 'zinfo_or_arcname' is either a ZipInfo instance or
|
'byts'. 'zinfo_or_arcname' is either a ZipInfo instance or
|
||||||
the name of the file in the archive."""
|
the name of the file in the archive."""
|
||||||
assert not raw_bytes or (raw_bytes and
|
assert not raw_bytes or (raw_bytes and
|
||||||
isinstance(zinfo_or_arcname, ZipInfo))
|
isinstance(zinfo_or_arcname, ZipInfo))
|
||||||
|
if not isinstance(byts, bytes):
|
||||||
|
byts = byts.encode('utf-8')
|
||||||
if not isinstance(zinfo_or_arcname, ZipInfo):
|
if not isinstance(zinfo_or_arcname, ZipInfo):
|
||||||
if not isinstance(zinfo_or_arcname, unicode_type):
|
if not isinstance(zinfo_or_arcname, unicode_type):
|
||||||
zinfo_or_arcname = zinfo_or_arcname.decode(filesystem_encoding)
|
zinfo_or_arcname = zinfo_or_arcname.decode(filesystem_encoding)
|
||||||
@ -1302,22 +1304,22 @@ class ZipFile:
|
|||||||
"Attempt to write to ZIP archive that was already closed")
|
"Attempt to write to ZIP archive that was already closed")
|
||||||
|
|
||||||
if not raw_bytes:
|
if not raw_bytes:
|
||||||
zinfo.file_size = len(bytes) # Uncompressed size
|
zinfo.file_size = len(byts) # Uncompressed size
|
||||||
zinfo.header_offset = self.fp.tell() # Start of header bytes
|
zinfo.header_offset = self.fp.tell() # Start of header bytes
|
||||||
self._writecheck(zinfo)
|
self._writecheck(zinfo)
|
||||||
self._didModify = True
|
self._didModify = True
|
||||||
if not raw_bytes:
|
if not raw_bytes:
|
||||||
zinfo.CRC = crc32(bytes) & 0xffffffff # CRC-32 checksum
|
zinfo.CRC = crc32(byts) & 0xffffffff # CRC-32 checksum
|
||||||
if zinfo.compress_type == ZIP_DEFLATED:
|
if zinfo.compress_type == ZIP_DEFLATED:
|
||||||
co = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
|
co = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
|
||||||
zlib.DEFLATED, -15)
|
zlib.DEFLATED, -15)
|
||||||
bytes = co.compress(bytes) + co.flush()
|
byts = co.compress(byts) + co.flush()
|
||||||
zinfo.compress_size = len(bytes) # Compressed size
|
zinfo.compress_size = len(byts) # Compressed size
|
||||||
else:
|
else:
|
||||||
zinfo.compress_size = zinfo.file_size
|
zinfo.compress_size = zinfo.file_size
|
||||||
zinfo.header_offset = self.fp.tell() # Start of header bytes
|
zinfo.header_offset = self.fp.tell() # Start of header bytes
|
||||||
self.fp.write(zinfo.FileHeader())
|
self.fp.write(zinfo.FileHeader())
|
||||||
self.fp.write(bytes)
|
self.fp.write(byts)
|
||||||
self.fp.flush()
|
self.fp.flush()
|
||||||
if zinfo.flag_bits & 0x08:
|
if zinfo.flag_bits & 0x08:
|
||||||
# Write CRC and file sizes after the file data
|
# Write CRC and file sizes after the file data
|
||||||
@ -1331,7 +1333,7 @@ class ZipFile:
|
|||||||
Add a directory recursively to the zip file with an optional prefix.
|
Add a directory recursively to the zip file with an optional prefix.
|
||||||
'''
|
'''
|
||||||
if prefix:
|
if prefix:
|
||||||
self.writestr(prefix+'/', '', 0o755)
|
self.writestr(prefix+'/', b'', 0o755)
|
||||||
cwd = os.path.abspath(os.getcwdu())
|
cwd = os.path.abspath(os.getcwdu())
|
||||||
try:
|
try:
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user