From 96851834cd5c9c596a00f078fdf97a9f26847351 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 26 Aug 2009 15:02:37 -0600 Subject: [PATCH] IGN:Misc fixes --- installer/linux/freeze.py | 2 +- installer/osx/freeze.py | 2 +- installer/windows/freeze.py | 2 +- src/calibre/gui2/dialogs/add_save.py | 66 ------------------- src/calibre/gui2/wizard/__init__.py | 3 +- src/calibre/library/database2.py | 44 ++++++++----- src/calibre/library/sqlite.py | 6 +- src/calibre/utils/fonts/__init__.py | 8 ++- src/calibre/utils/windows/winutil.c | 1 + .../web/feeds/recipes/recipe_linuxdevices.py | 9 ++- 10 files changed, 51 insertions(+), 92 deletions(-) delete mode 100644 src/calibre/gui2/dialogs/add_save.py diff --git a/installer/linux/freeze.py b/installer/linux/freeze.py index c0f4edfd01..6e5bb0592b 100644 --- a/installer/linux/freeze.py +++ b/installer/linux/freeze.py @@ -93,7 +93,7 @@ def freeze(): includes = [x[0] for x in executables.values()] includes += ['calibre.ebooks.lrf.fonts.prs500.'+x for x in FONT_MAP.values()] - includes += ['email.iterators', 'email.generator'] + includes += ['email.iterators', 'email.generator', 'sqlite3.dump'] excludes = ['matplotlib', "Tkconstants", "Tkinter", "tcl", "_imagingtk", diff --git a/installer/osx/freeze.py b/installer/osx/freeze.py index b9dc2ebe39..7791668a09 100644 --- a/installer/osx/freeze.py +++ b/installer/osx/freeze.py @@ -353,7 +353,7 @@ def main(): 'keyword', 'codeop', 'pydoc', 'readline', 'BeautifulSoup', 'calibre.ebooks.lrf.fonts.prs500.*', 'dateutil', 'email.iterators', - 'email.generator', + 'email.generator', 'sqlite3.dump', 'calibre.ebooks.metadata.amazon', ], 'packages' : ['PIL', 'Authorization', 'lxml', 'dns'], diff --git a/installer/windows/freeze.py b/installer/windows/freeze.py index 8c5feda212..0b4f18ff4a 100644 --- a/installer/windows/freeze.py +++ b/installer/windows/freeze.py @@ -158,7 +158,7 @@ def main(args=sys.argv): 'email.iterators', 'email.generator', 'win32process', 'win32api', 'msvcrt', - 'win32event', + 'win32event', 'sqlite3.dump', 'BeautifulSoup', 'pyreadline', 'pydoc', 'IPython.Extensions.*', 'calibre.web.feeds.recipes.*', diff --git a/src/calibre/gui2/dialogs/add_save.py b/src/calibre/gui2/dialogs/add_save.py deleted file mode 100644 index 7bd6273b4a..0000000000 --- a/src/calibre/gui2/dialogs/add_save.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement - -__license__ = 'GPL v3' -__copyright__ = '2009, Kovid Goyal ' -__docformat__ = 'restructuredtext en' - -import textwrap - -from PyQt4.Qt import QTabWidget - -from calibre.gui2.dialogs.add_save_ui import Ui_TabWidget -from calibre.library.save_to_disk import config, FORMAT_ARG_DESCS - - -class AddSave(QTabWidget, Ui_TabWidget): - - def __init__(self, parent=None): - QTabWidget.__init__(self, parent) - self.setupUi(self) - c = config() - opts = c.parse() - for x in ('asciiize', 'update_metadata', 'save_cover', 'write_opf'): - g = getattr(self, 'opt_'+x) - g.setChecked(getattr(opts, x)) - help = '\n'.join(textwrap.wrap(c.get_option(x).help, 75)) - g.setToolTip(help) - g.setWhatsThis(help) - - for x in ('formats', 'timefmt'): - g = getattr(self, 'opt_'+x) - g.setText(getattr(opts, x)) - help = '\n'.join(textwrap.wrap(c.get_option(x).help, 75)) - g.setToolTip(help) - g.setWhatsThis(help) - - help = '\n'.join(textwrap.wrap(c.get_option('template').help, 75)) - self.opt_template.initialize('save_to_disk_template_history', - opts.template, help=help) - - variables = sorted(FORMAT_ARG_DESCS.keys()) - rows = [] - for var in variables: - rows.append(u'%s%s'% - (var, FORMAT_ARG_DESCS[var])) - table = u'%s
'%(u'\n'.join(rows)) - self.template_variables.setText(table) - - def save_settings(self): - c = config() - for x in ('asciiize', 'update_metadata', 'save_cover', 'write_opf'): - c.set(x, getattr(self, 'opt_'+x).isChecked()) - for x in ('formats', 'template', 'timefmt'): - c.set(x, unicode(getattr(self, 'opt_'+x).text()).strip()) - - - -if __name__ == '__main__': - from PyQt4.Qt import QApplication - app=QApplication([]) - a = AddSave() - a.show() - app.exec_() - a.save_settings() - diff --git a/src/calibre/gui2/wizard/__init__.py b/src/calibre/gui2/wizard/__init__.py index df5d38a927..7045f6334d 100644 --- a/src/calibre/gui2/wizard/__init__.py +++ b/src/calibre/gui2/wizard/__init__.py @@ -424,7 +424,8 @@ def move_library(oldloc, newloc, parent, callback_on_complete): callback) else: rq = Queue() - m = MoveLibrary(oldloc, newloc, db.data.count(), rq) + m = MoveLibrary(oldloc, newloc, + len(db.get_top_level_move_items()[0]), rq) global _mm _mm = MoveMonitor(m, rq, callback, parent) return diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index c48b238c8d..54607d1d11 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1444,9 +1444,7 @@ class LibraryDatabase2(LibraryDatabase): if notify: self.notify('add', [id]) - def move_library_to(self, newloc, progress=lambda x: x): - if not os.path.exists(newloc): - os.makedirs(newloc) + def get_top_level_move_items(self): items = set(os.listdir(self.library_path)) paths = set([]) for x in self.data.universal_set(): @@ -1454,15 +1452,25 @@ class LibraryDatabase2(LibraryDatabase): path = path.split(os.sep)[0] paths.add(path) paths.add('metadata.db') + path_map = {} + for x in paths: + path_map[x] = x if not self.is_case_sensitive: - items = set([x.lower() for x in items]) + for x in items: + path_map[x.lower()] = x + items = set(path_map) paths = set([x.lower() for x in paths]) items = items.intersection(paths) + return items, path_map + def move_library_to(self, newloc, progress=lambda x: x): + if not os.path.exists(newloc): + os.makedirs(newloc) old_dirs = set([]) - for i, x in enumerate(items): + items, path_map = self.get_top_level_move_items() + for x in items: src = os.path.join(self.library_path, x) - dest = os.path.join(newloc, x) + dest = os.path.join(newloc, path_map[x]) if os.path.isdir(src): if os.path.exists(dest): shutil.rmtree(dest) @@ -1472,6 +1480,7 @@ class LibraryDatabase2(LibraryDatabase): if os.path.exists(dest): os.remove(dest) shutil.copyfile(src, dest) + x = path_map[x] if not isinstance(x, unicode): x = x.decode(filesystem_encoding, 'replace') progress(x) @@ -1686,13 +1695,12 @@ books_series_link feeds user_version = self.user_version sql = self.conn.dump() self.conn.close() - dest = self.dbpath+'.old' + dest = self.dbpath+'.tmp' if os.path.exists(dest): os.remove(dest) - shutil.copyfile(self.dbpath, dest) + conn = None try: - os.remove(self.dbpath) - ndb = DBThread(self.dbpath, None) + ndb = DBThread(dest, None) ndb.connect() conn = ndb.conn conn.executescript(sql) @@ -1701,15 +1709,21 @@ books_series_link feeds conn.commit() conn.close() except: - if os.path.exists(self.dbpath): - os.remove(self.dbpath) - shutil.copyfile(dest, self.dbpath) - os.remove(dest) + if conn is not None: + try: + conn.close() + except: + pass + if os.path.exists(dest): + os.remove(dest) raise else: - os.remove(dest) + os.remove(self.dbpath) + shutil.copyfile(dest, self.dbpath) self.connect() self.refresh() + if os.path.exists(dest): + os.remove(dest) callback(0.1, _('Checking for missing files.')) bad = {} us = self.data.universal_set() diff --git a/src/calibre/library/sqlite.py b/src/calibre/library/sqlite.py index a1caf506d9..3c23dd67cc 100644 --- a/src/calibre/library/sqlite.py +++ b/src/calibre/library/sqlite.py @@ -157,6 +157,8 @@ class DatabaseException(Exception): def proxy(fn): ''' Decorator to call methods on the database connection in the proxy thread ''' def run(self, *args, **kwargs): + if self.closed: + raise DatabaseException('Connection closed', '') with global_lock: if self.proxy.unhandled_error[0] is not None: raise DatabaseException(*self.proxy.unhandled_error) @@ -174,10 +176,12 @@ class ConnectionProxy(object): def __init__(self, proxy): self.proxy = proxy + self.closed = False def close(self): - if self.proxy.unhandled_error is None: + if self.proxy.unhandled_error[0] is None: self.proxy.requests.put((self.proxy.CLOSE, [], {})) + self.closed = True @proxy def get(self, query, all=True): pass diff --git a/src/calibre/utils/fonts/__init__.py b/src/calibre/utils/fonts/__init__.py index bc6b117147..f4b4e0fc99 100644 --- a/src/calibre/utils/fonts/__init__.py +++ b/src/calibre/utils/fonts/__init__.py @@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en' import os, sys from threading import Thread -from calibre.constants import plugins +from calibre.constants import plugins, iswindows _fc, _fc_err = plugins['fontconfig'] @@ -31,6 +31,12 @@ class FontConfig(Thread): if isinstance(config_dir, unicode): config_dir = config_dir.encode(sys.getfilesystemencoding()) config = os.path.join(config_dir, 'fonts.conf') + if iswindows and getattr(sys, 'frozen', False): + config_dir = os.path.join(os.path.dirname(sys.executable), + 'etc', 'fonts') + if isinstance(config_dir, unicode): + config_dir = config_dir.encode(sys.getfilesystemencoding()) + config = os.path.join(config_dir, 'fonts.conf') try: _fc.initialize(config) except: diff --git a/src/calibre/utils/windows/winutil.c b/src/calibre/utils/windows/winutil.c index 88091ffc52..be504b7fcf 100644 --- a/src/calibre/utils/windows/winutil.c +++ b/src/calibre/utils/windows/winutil.c @@ -929,6 +929,7 @@ initwinutil(void) { PyModule_AddIntConstant(m, "CSIDL_COOKIES", CSIDL_COOKIES); PyModule_AddIntConstant(m, "CSIDL_FLAG_CREATE", CSIDL_FLAG_CREATE); PyModule_AddIntConstant(m, "CSIDL_FLAG_DONT_VERIFY", CSIDL_FLAG_DONT_VERIFY); + PyModule_AddIntConstant(m, "CSIDL_FONTS", CSIDL_FONTS); PyModule_AddIntConstant(m, "CSIDL_HISTORY", CSIDL_HISTORY); PyModule_AddIntConstant(m, "CSIDL_INTERNET_CACHE", CSIDL_INTERNET_CACHE); PyModule_AddIntConstant(m, "CSIDL_LOCAL_APPDATA", CSIDL_LOCAL_APPDATA); diff --git a/src/calibre/web/feeds/recipes/recipe_linuxdevices.py b/src/calibre/web/feeds/recipes/recipe_linuxdevices.py index ab79b4b911..4c32bad80c 100644 --- a/src/calibre/web/feeds/recipes/recipe_linuxdevices.py +++ b/src/calibre/web/feeds/recipes/recipe_linuxdevices.py @@ -6,10 +6,9 @@ Fetch Linuxdevices. ''' import re from calibre.web.feeds.news import BasicNewsRecipe -from calibre.ebooks.BeautifulSoup import BeautifulSoup -class Sueddeutsche(BasicNewsRecipe): +class LinuxDevices(BasicNewsRecipe): title = u'Linuxdevices' description = 'News about Linux driven Hardware' @@ -20,7 +19,7 @@ class Sueddeutsche(BasicNewsRecipe): no_stylesheets = True language = _('English') remove_javascript = True - conversion_options {' linearize_tables' : True} + conversion_options = { 'linearize_tables' : True} encoding = 'latin1' @@ -83,9 +82,9 @@ class Sueddeutsche(BasicNewsRecipe): for item in soup.findAll('b', text=match): item.extract() for item in soup.findAll(re.compile('^ul')): - item.extract() + item.extract() for item in soup.findAll('br', limit=10): - item.extract() + item.extract() return soup