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