mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Fix #782408 (.mobi import broken in 0.8.1)
This commit is contained in:
parent
7912b658f5
commit
997a943257
@ -32,7 +32,6 @@ class Win32(VMInstaller):
|
||||
FREEZE_TEMPLATE = 'python -OO setup.py {freeze_command} --no-ice'
|
||||
INSTALLER_EXT = 'msi'
|
||||
SHUTDOWN_CMD = ['shutdown.exe', '-s', '-f', '-t', '0']
|
||||
BUILD_BUILD = ['python setup.py kakasi',] + VMInstaller.BUILD_BUILD
|
||||
|
||||
def download_installer(self):
|
||||
installer = self.installer()
|
||||
|
@ -6,10 +6,10 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, cPickle, re, anydbm, shutil, marshal, zipfile, glob
|
||||
import os, cPickle, re, shutil, marshal, zipfile, glob
|
||||
from zlib import compress
|
||||
|
||||
from setup import Command, basenames, __appname__, iswindows
|
||||
from setup import Command, basenames, __appname__
|
||||
|
||||
def get_opts_from_parser(parser):
|
||||
def do_opt(opt):
|
||||
@ -34,12 +34,12 @@ class Kakasi(Command):
|
||||
self.records = {}
|
||||
src = self.j(self.KAKASI_PATH, 'kakasidict.utf8')
|
||||
dest = self.j(self.RESOURCES, 'localization',
|
||||
'pykakasi','kanwadict2.db')
|
||||
'pykakasi','kanwadict2.pickle')
|
||||
base = os.path.dirname(dest)
|
||||
if not os.path.exists(base):
|
||||
os.makedirs(base)
|
||||
|
||||
if self.newer(dest, src) or iswindows:
|
||||
if self.newer(dest, src):
|
||||
self.info('\tGenerating Kanwadict')
|
||||
|
||||
for line in open(src, "r"):
|
||||
@ -50,7 +50,7 @@ class Kakasi(Command):
|
||||
dest = self.j(self.RESOURCES, 'localization',
|
||||
'pykakasi','itaijidict2.pickle')
|
||||
|
||||
if self.newer(dest, src) or iswindows:
|
||||
if self.newer(dest, src):
|
||||
self.info('\tGenerating Itaijidict')
|
||||
self.mkitaiji(src, dest)
|
||||
|
||||
@ -58,7 +58,7 @@ class Kakasi(Command):
|
||||
dest = self.j(self.RESOURCES, 'localization',
|
||||
'pykakasi','kanadict2.pickle')
|
||||
|
||||
if self.newer(dest, src) or iswindows:
|
||||
if self.newer(dest, src):
|
||||
self.info('\tGenerating kanadict')
|
||||
self.mkkanadict(src, dest)
|
||||
|
||||
@ -75,7 +75,7 @@ class Kakasi(Command):
|
||||
continue
|
||||
pair = re.sub(r'\\u([0-9a-fA-F]{4})', lambda x:unichr(int(x.group(1),16)), line)
|
||||
dic[pair[0]] = pair[1]
|
||||
cPickle.dump(dic, open(dst, 'w'), protocol=-1) #pickle
|
||||
cPickle.dump(dic, open(dst, 'wb'), protocol=-1) #pickle
|
||||
|
||||
def mkkanadict(self, src, dst):
|
||||
dic = {}
|
||||
@ -87,7 +87,7 @@ class Kakasi(Command):
|
||||
continue
|
||||
(alpha, kana) = line.split(' ')
|
||||
dic[kana] = alpha
|
||||
cPickle.dump(dic, open(dst, 'w'), protocol=-1) #pickle
|
||||
cPickle.dump(dic, open(dst, 'wb'), protocol=-1) #pickle
|
||||
|
||||
def parsekdict(self, line):
|
||||
line = line.decode("utf-8").strip()
|
||||
@ -115,16 +115,11 @@ class Kakasi(Command):
|
||||
self.records[key][kanji]=[(yomi, tail)]
|
||||
|
||||
def kanwaout(self, out):
|
||||
try:
|
||||
# Needed as otherwise anydbm tries to create a gdbm db when the db
|
||||
# created on Unix is found
|
||||
os.remove(out)
|
||||
except:
|
||||
pass
|
||||
dic = anydbm.open(out, 'n')
|
||||
for (k, v) in self.records.iteritems():
|
||||
dic[k] = compress(marshal.dumps(v))
|
||||
dic.close()
|
||||
with open(out, 'wb') as f:
|
||||
dic = {}
|
||||
for k, v in self.records.iteritems():
|
||||
dic[k] = compress(marshal.dumps(v))
|
||||
cPickle.dump(dic, f, -1)
|
||||
|
||||
def clean(self):
|
||||
kakasi = self.j(self.RESOURCES, 'localization', 'pykakasi')
|
||||
|
@ -2,12 +2,8 @@
|
||||
# jisyo.py
|
||||
#
|
||||
# Copyright 2011 Hiroshi Miura <miurahr@linux.com>
|
||||
from cPickle import load
|
||||
import anydbm,marshal
|
||||
import cPickle, marshal
|
||||
from zlib import decompress
|
||||
import os
|
||||
|
||||
import calibre.utils.resources as resources
|
||||
|
||||
class jisyo (object):
|
||||
kanwadict = None
|
||||
@ -25,16 +21,14 @@ class jisyo (object):
|
||||
|
||||
def __init__(self):
|
||||
if self.kanwadict is None:
|
||||
dictpath = resources.get_path(os.path.join('localization','pykakasi','kanwadict2.db'))
|
||||
self.kanwadict = anydbm.open(dictpath,'r')
|
||||
if self.itaijidict is None:
|
||||
itaijipath = resources.get_path(os.path.join('localization','pykakasi','itaijidict2.pickle'))
|
||||
itaiji_pkl = open(itaijipath, 'rb')
|
||||
self.itaijidict = load(itaiji_pkl)
|
||||
self.kanwadict = cPickle.loads(
|
||||
P('localization/pykakasi/kanwadict2.pickle', data=True))
|
||||
if self.itaijidict is None:
|
||||
self.itaijidict = cPickle.loads(
|
||||
P('localization/pykakasi/itaijidict2.pickle', data=True))
|
||||
if self.kanadict is None:
|
||||
kanadictpath = resources.get_path(os.path.join('localization','pykakasi','kanadict2.pickle'))
|
||||
kanadict_pkl = open(kanadictpath, 'rb')
|
||||
self.kanadict = load(kanadict_pkl)
|
||||
self.kanadict = cPickle.loads(
|
||||
P('localization/pykakasi/kanadict2.pickle', data=True))
|
||||
|
||||
def load_jisyo(self, char):
|
||||
try:#python2
|
||||
|
Loading…
x
Reference in New Issue
Block a user