Merge from trunk

This commit is contained in:
Charles Haley 2011-06-05 10:43:06 +01:00
commit 51e192f097
8 changed files with 81 additions and 36 deletions

View File

@ -69,7 +69,11 @@ class Newsweek(BasicNewsRecipe):
for section, shref in self.newsweek_sections(): for section, shref in self.newsweek_sections():
self.log('Processing section', section, shref) self.log('Processing section', section, shref)
articles = [] articles = []
soups = [self.index_to_soup(shref)] try:
soups = [self.index_to_soup(shref)]
except:
self.log.warn('Section %s not found, skipping'%section)
continue
na = soups[0].find('a', rel='next') na = soups[0].find('a', rel='next')
if na: if na:
soups.append(self.index_to_soup(self.BASE_URL+na['href'])) soups.append(self.index_to_soup(self.BASE_URL+na['href']))

View File

@ -85,7 +85,7 @@ class Translations(POT):
def mo_file(self, po_file): def mo_file(self, po_file):
locale = os.path.splitext(os.path.basename(po_file))[0] locale = os.path.splitext(os.path.basename(po_file))[0]
return locale, os.path.join(self.DEST, locale, 'LC_MESSAGES', 'messages.mo') return locale, os.path.join(self.DEST, locale, 'messages.mo')
def run(self, opts): def run(self, opts):
@ -94,9 +94,8 @@ class Translations(POT):
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, f): self.info('\tCompiling translations for', locale)
self.info('\tCompiling translations for', locale) subprocess.check_call(['msgfmt', '-o', dest, f])
subprocess.check_call(['msgfmt', '-o', dest, f])
if locale in ('en_GB', 'nds', 'te', 'yi'): if locale in ('en_GB', 'nds', 'te', 'yi'):
continue continue
pycountry = self.j(sysconfig.get_python_lib(), 'pycountry', pycountry = self.j(sysconfig.get_python_lib(), 'pycountry',
@ -123,6 +122,16 @@ class Translations(POT):
shutil.copy2(f, dest) shutil.copy2(f, dest)
self.write_stats() self.write_stats()
self.freeze_locales()
def freeze_locales(self):
zf = self.DEST + '.zip'
from calibre import CurrentDir
from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED
with ZipFile(zf, 'w', ZIP_DEFLATED) as zf:
with CurrentDir(self.DEST):
zf.add_dir('.')
shutil.rmtree(self.DEST)
@property @property
def stats(self): def stats(self):

View File

@ -69,7 +69,7 @@ def object_to_unicode(obj, enc=preferred_encoding):
return obj return obj
def encode_is_multiple(fm): def encode_is_multiple(fm):
if fm.get('is_multiple'): if fm.get('is_multiple', None):
# migrate is_multiple back to a character # migrate is_multiple back to a character
fm['is_multiple2'] = fm.get('is_multiple', {}) fm['is_multiple2'] = fm.get('is_multiple', {})
dt = fm.get('datatype', None) dt = fm.get('datatype', None)

View File

@ -94,6 +94,9 @@ class DeleteAction(InterfaceAction):
self.delete_menu.addAction( self.delete_menu.addAction(
_('Remove all formats from selected books, except...'), _('Remove all formats from selected books, except...'),
self.delete_all_but_selected_formats) self.delete_all_but_selected_formats)
self.delete_menu.addAction(
_('Remove all formats from selected books'),
self.delete_all_formats)
self.delete_menu.addAction( self.delete_menu.addAction(
_('Remove covers from selected books'), self.delete_covers) _('Remove covers from selected books'), self.delete_covers)
self.delete_menu.addSeparator() self.delete_menu.addSeparator()
@ -174,6 +177,28 @@ class DeleteAction(InterfaceAction):
if ids: if ids:
self.gui.tags_view.recount() self.gui.tags_view.recount()
def delete_all_formats(self, *args):
ids = self._get_selected_ids()
if not ids:
return
if not confirm('<p>'+_('<b>All formats</b> for the selected books will '
'be <b>deleted</b> from your library.<br>'
'The book metadata will be kept. Are you sure?')
+'</p>', 'delete_all_formats', self.gui):
return
db = self.gui.library_view.model().db
for id in ids:
fmts = db.formats(id, index_is_id=True, verify_formats=False)
if fmts:
for fmt in fmts.split(','):
self.gui.library_view.model().db.remove_format(id, fmt,
index_is_id=True, notify=False)
self.gui.library_view.model().refresh_ids(ids)
self.gui.library_view.model().current_changed(self.gui.library_view.currentIndex(),
self.gui.library_view.currentIndex())
if ids:
self.gui.tags_view.recount()
def remove_matching_books_from_device(self, *args): def remove_matching_books_from_device(self, *args):
if not self.gui.device_manager.is_device_connected: if not self.gui.device_manager.is_device_connected:
d = error_dialog(self.gui, _('Cannot delete books'), d = error_dialog(self.gui, _('Cannot delete books'),

View File

@ -23,7 +23,6 @@ entry_points = {
'calibre-server = calibre.library.server.main:main', 'calibre-server = calibre.library.server.main:main',
'lrf2lrs = calibre.ebooks.lrf.lrfparser:main', 'lrf2lrs = calibre.ebooks.lrf.lrfparser:main',
'lrs2lrf = calibre.ebooks.lrf.lrs.convert_from:main', 'lrs2lrf = calibre.ebooks.lrf.lrs.convert_from:main',
'librarything = calibre.ebooks.metadata.library_thing:main',
'calibre-debug = calibre.debug:main', 'calibre-debug = calibre.debug:main',
'calibredb = calibre.library.cli:main', 'calibredb = calibre.library.cli:main',
'calibre-parallel = calibre.utils.ipc.worker:main', 'calibre-parallel = calibre.utils.ipc.worker:main',

View File

@ -5,10 +5,9 @@ Dynamic language lookup of translations for user-visible strings.
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>' __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
import os import cStringIO
from gettext import GNUTranslations from gettext import GNUTranslations
from calibre.utils.localization import get_lc_messages_path from calibre.utils.localization import get_lc_messages_path, ZipFile
__all__ = ['translate'] __all__ = ['translate']
@ -21,10 +20,15 @@ def translate(lang, text):
else: else:
mpath = get_lc_messages_path(lang) mpath = get_lc_messages_path(lang)
if mpath is not None: if mpath is not None:
p = os.path.join(mpath, 'messages.mo') with ZipFile(P('localization/locales.zip',
if os.path.exists(p): allow_user_override=False), 'r') as zf:
trans = GNUTranslations(open(p, 'rb')) try:
_CACHE[lang] = trans buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
except:
pass
else:
trans = GNUTranslations(buf)
_CACHE[lang] = trans
if trans is None: if trans is None:
return getattr(__builtins__, '_', lambda x: x)(text) return getattr(__builtins__, '_', lambda x: x)(text)
return trans.ugettext(text) return trans.ugettext(text)

View File

@ -223,8 +223,7 @@ class OptionSet(object):
if val is val is True or val is False or val is None or \ if val is val is True or val is False or val is None or \
isinstance(val, (int, float, long, basestring)): isinstance(val, (int, float, long, basestring)):
return repr(val) return repr(val)
from PyQt4.QtCore import QString if val.__class__.__name__ == 'QString':
if isinstance(val, QString):
return repr(unicode(val)) return repr(unicode(val))
pickle = cPickle.dumps(val, -1) pickle = cPickle.dumps(val, -1)
return 'cPickle.loads(%s)'%repr(pickle) return 'cPickle.loads(%s)'%repr(pickle)

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import with_statement from __future__ import absolute_import
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
@ -8,13 +8,14 @@ __docformat__ = 'restructuredtext en'
import os, locale, re, cStringIO, cPickle import os, locale, re, cStringIO, cPickle
from gettext import GNUTranslations from gettext import GNUTranslations
from zipfile import ZipFile
_available_translations = None _available_translations = None
def available_translations(): def available_translations():
global _available_translations global _available_translations
if _available_translations is None: if _available_translations is None:
stats = P('localization/stats.pickle') stats = P('localization/stats.pickle', allow_user_override=False)
if os.path.exists(stats): if os.path.exists(stats):
stats = cPickle.load(open(stats, 'rb')) stats = cPickle.load(open(stats, 'rb'))
else: else:
@ -49,21 +50,20 @@ def get_lang():
lang = 'en' lang = 'en'
return lang return lang
def messages_path(lang):
return P('localization/locales/%s/LC_MESSAGES'%lang)
def get_lc_messages_path(lang): def get_lc_messages_path(lang):
hlang = None hlang = None
if lang in available_translations(): if zf_exists():
hlang = lang if lang in available_translations():
else: hlang = lang
xlang = lang.split('_')[0] else:
if xlang in available_translations(): xlang = lang.split('_')[0]
hlang = xlang if xlang in available_translations():
if hlang is not None: hlang = xlang
return messages_path(hlang) return hlang
return None
def zf_exists():
return os.path.exists(P('localization/locales.zip',
allow_user_override=False))
def set_translators(): def set_translators():
# To test different translations invoke as # To test different translations invoke as
@ -79,12 +79,17 @@ def set_translators():
mpath = get_lc_messages_path(lang) mpath = get_lc_messages_path(lang)
if mpath is not None: if mpath is not None:
if buf is None: with ZipFile(P('localization/locales.zip',
buf = open(os.path.join(mpath, 'messages.mo'), 'rb') allow_user_override=False), 'r') as zf:
mpath = mpath.replace(os.sep+'nds'+os.sep, os.sep+'de'+os.sep) if buf is None:
isof = os.path.join(mpath, 'iso639.mo') buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
if os.path.exists(isof): if mpath == 'nds':
iso639 = open(isof, 'rb') mpath = 'de'
isof = mpath + '/iso639.mo'
try:
iso639 = cStringIO.StringIO(zf.read(isof))
except:
pass # No iso639 translations for this lang
if buf is not None: if buf is not None:
t = GNUTranslations(buf) t = GNUTranslations(buf)