mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Use msgpack instead of pickle for a couple more databases
This commit is contained in:
parent
1d54c2f874
commit
d8e24e4a19
@ -7,7 +7,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, tempfile, shutil, subprocess, glob, re, time, textwrap, cPickle, shlex, json, errno, hashlib, sys
|
||||
import os, tempfile, shutil, subprocess, glob, re, time, textwrap, shlex, json, errno, hashlib, sys
|
||||
from collections import defaultdict
|
||||
from locale import normalize as normalize_locale
|
||||
from functools import partial
|
||||
@ -338,9 +338,10 @@ class Translations(POT): # {{{
|
||||
ln = normalize_locale(locale).partition('.')[0]
|
||||
if ln in lcdata:
|
||||
ld = lcdata[ln]
|
||||
lcdest = self.j(self.d(dest), 'lcdata.pickle')
|
||||
lcdest = self.j(self.d(dest), 'lcdata.calibre_msgpack')
|
||||
from calibre.utils.serialize import msgpack_dumps
|
||||
with open(lcdest, 'wb') as lcf:
|
||||
lcf.write(cPickle.dumps(ld, -1))
|
||||
lcf.write(msgpack_dumps(ld))
|
||||
|
||||
stats = {}
|
||||
|
||||
@ -379,7 +380,9 @@ class Translations(POT): # {{{
|
||||
except EnvironmentError as err:
|
||||
if err.errno != errno.EEXIST:
|
||||
raise
|
||||
cPickle.dump(stats, open(dest, 'wb'), -1)
|
||||
from calibre.utils.serialize import msgpack_dumps
|
||||
with open(dest, 'wb') as f:
|
||||
f.write(msgpack_dumps(stats))
|
||||
|
||||
def hash_and_data(self, f):
|
||||
with open(f, 'rb') as s:
|
||||
@ -453,7 +456,7 @@ class Translations(POT): # {{{
|
||||
|
||||
@property
|
||||
def stats(self):
|
||||
return self.j(self.d(self.DEST), 'stats.pickle')
|
||||
return self.j(self.d(self.DEST), 'stats.calibre_msgpack')
|
||||
|
||||
def compile_website_translations(self):
|
||||
from calibre.utils.zipfile import ZipFile, ZipInfo, ZIP_STORED
|
||||
|
@ -7,7 +7,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, locale, re, cStringIO, cPickle
|
||||
import os, locale, re, cStringIO
|
||||
from gettext import GNUTranslations, NullTranslations
|
||||
|
||||
_available_translations = None
|
||||
@ -16,9 +16,10 @@ _available_translations = None
|
||||
def available_translations():
|
||||
global _available_translations
|
||||
if _available_translations is None:
|
||||
stats = P('localization/stats.pickle', allow_user_override=False)
|
||||
stats = P('localization/stats.calibre_msgpack', allow_user_override=False)
|
||||
if os.path.exists(stats):
|
||||
stats = cPickle.load(open(stats, 'rb'))
|
||||
from calibre.utils.serialize import msgpack_loads
|
||||
stats = msgpack_loads(open(stats, 'rb').read())
|
||||
else:
|
||||
stats = {}
|
||||
_available_translations = [x for x in stats if stats[x] > 0.1]
|
||||
@ -223,8 +224,9 @@ def set_translators():
|
||||
except:
|
||||
pass # No iso639 translations for this lang
|
||||
if buf is not None:
|
||||
from calibre.utils.serialize import msgpack_loads
|
||||
try:
|
||||
lcdata = cPickle.loads(zf.read(mpath + '/lcdata.pickle'))
|
||||
lcdata = msgpack_loads(zf.read(mpath + '/lcdata.calibre_msgpack'))
|
||||
except:
|
||||
pass # No lcdata
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user