From 61b86494cb1386d4cf37df2d341b617500ef9acc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 30 May 2011 12:38:44 -0600 Subject: [PATCH 1/4] ... --- recipes/mediapart.recipe | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/mediapart.recipe b/recipes/mediapart.recipe index 0cf8f21032..4540879f72 100644 --- a/recipes/mediapart.recipe +++ b/recipes/mediapart.recipe @@ -71,7 +71,7 @@ class Mediapart(BasicNewsRecipe): br = BasicNewsRecipe.get_browser() if self.username is not None and self.password is not None: br.open('http://www.mediapart.fr/') - br.select_form(nr=1) + br.select_form(nr=0) br['name'] = self.username br['pass'] = self.password br.submit() From 1237db4c87685548d8613d63a5c34a6f82ba6939 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 30 May 2011 19:47:30 +0100 Subject: [PATCH 2/4] Use the cache for the rest of the calls to get_metadata. --- src/calibre/gui2/library/models.py | 37 +++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index cac0346761..906d2979fa 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -173,10 +173,12 @@ class BooksModel(QAbstractTableModel): # {{{ def refresh_ids(self, ids, current_row=-1): - self.mi_cache = {} rows = self.db.refresh_ids(ids) if rows: self.refresh_rows(rows, current_row=current_row) + else: + self.mi_cache = {} + def refresh_rows(self, rows, current_row=-1): self.mi_cache = {} @@ -367,8 +369,20 @@ class BooksModel(QAbstractTableModel): # {{{ def count(self): return self.rowCount(None) + def get_and_cache_metadata(self, idx, index_is_id = False, get_cover=False, + get_user_categories=True): + if not index_is_id: + idx = self.db.id(idx) + if idx in self.mi_cache: + mi = self.mi_cache[idx] + else: + mi = self.db.get_metadata(idx, index_is_id=True, get_cover=get_cover, + get_user_categories=get_user_categories) + self.mi_cache[idx] = mi + return mi + def get_book_display_info(self, idx): - mi = self.db.get_metadata(idx) + mi = self.get_and_cache_metadata(idx) mi.size = mi.book_size mi.cover_data = ('jpg', self.cover(idx)) mi.id = self.db.id(idx) @@ -395,7 +409,7 @@ class BooksModel(QAbstractTableModel): # {{{ def metadata_for(self, ids): ans = [] for id in ids: - mi = self.db.get_metadata(id, index_is_id=True, get_cover=True) + mi = self.get_and_cache_metadata(id, index_is_id=True, get_cover=True) ans.append(mi) return ans @@ -404,7 +418,7 @@ class BooksModel(QAbstractTableModel): # {{{ if not rows_are_ids: rows = [self.db.id(row.row()) for row in rows] for id in rows: - mi = self.db.get_metadata(id, index_is_id=True) + mi = self.get_and_cache_metadata(id, index_is_id=True) _full_metadata.append(mi) au = authors_to_string(mi.authors if mi.authors else [_('Unknown')]) tags = mi.tags if mi.tags else [] @@ -460,8 +474,9 @@ class BooksModel(QAbstractTableModel): # {{{ pt.seek(0) if set_metadata: try: - _set_metadata(pt, self.db.get_metadata(id, get_cover=True, index_is_id=True), - format) + _set_metadata(pt, self.get_and_cache_metadata(id, + get_cover=True, index_is_id=True), + format) except: traceback.print_exc() pt.close() @@ -505,7 +520,7 @@ class BooksModel(QAbstractTableModel): # {{{ pt.flush() pt.seek(0) if set_metadata: - _set_metadata(pt, self.db.get_metadata(row, get_cover=True), + _set_metadata(pt, self.get_and_cache_metadata(row, get_cover=True), format) pt.close() if paths else pt.seek(0) ans.append(pt) @@ -726,12 +741,8 @@ class BooksModel(QAbstractTableModel): # {{{ elif role == Qt.ForegroundRole: key = self.column_map[col] if key in self.column_color_map: - id_ = self.id(index) - if id_ in self.mi_cache: - mi = self.mi_cache[id_] - else: - mi = self.db.get_metadata(self.id(index), index_is_id=True) - self.mi_cache[id_] = mi + mi = self.get_and_cache_metadata(index.row(), + get_user_categories=False) fmt = self.column_color_map[key] try: color = composite_formatter.safe_format(fmt, mi, '', mi) From 07d2c984c45278f46126eaf7f2f89bf8358dd40f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 30 May 2011 13:05:02 -0600 Subject: [PATCH 3/4] ... --- src/calibre/manual/template_lang.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index f1d2844d37..ef44b0a5c9 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -122,7 +122,7 @@ The functions available are: * ``uppercase()`` -- return the value of the field in upper case. * ``titlecase()`` -- return the value of the field in title case. * ``capitalize()`` -- return the value with the first letter upper case and the rest lower case. - * ``contains(pattern, text if match, text if not match`` -- checks if field contains matches for the regular expression `pattern`. Returns `text if match` if matches are found, otherwise it returns `text if no match`. + * ``contains(pattern, text if match, text if not match)`` -- checks if field contains matches for the regular expression `pattern`. Returns `text if match` if matches are found, otherwise it returns `text if no match`. * ``count(separator)`` -- interprets the value as a list of items separated by `separator`, returning the number of items in the list. Most lists use a comma as the separator, but authors uses an ampersand. Examples: `{tags:count(,)}`, `{authors:count(&)}` * ``ifempty(text)`` -- if the field is not empty, return the value of the field. Otherwise return `text`. * ``in_list(separator, pattern, found_val, not_found_val)`` -- interpret the field as a list of items separated by `separator`, comparing the `pattern` against each value in the list. If the pattern matches a value, return `found_val`, otherwise return `not_found_val`. From dd745a8e3b15e4893231eea0688f241725171aba Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 30 May 2011 14:54:05 -0600 Subject: [PATCH 4/4] ... --- recipes/metro_uk.recipe | 7 +++++-- src/calibre/ebooks/metadata/book/base.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/recipes/metro_uk.recipe b/recipes/metro_uk.recipe index 26133edbd9..deced5976b 100644 --- a/recipes/metro_uk.recipe +++ b/recipes/metro_uk.recipe @@ -1,5 +1,4 @@ from calibre.web.feeds.news import BasicNewsRecipe - class AdvancedUserRecipe1306097511(BasicNewsRecipe): title = u'Metro UK' @@ -14,7 +13,9 @@ class AdvancedUserRecipe1306097511(BasicNewsRecipe): masthead_url = 'http://e-edition.metro.co.uk/images/metro_logo.gif' keep_only_tags = [ - dict(name='h1', attrs={'':''}), + dict(attrs={'class':['img-cnt figure']}), + dict(attrs={'class':['art-img']}), + dict(name='h1'), dict(name='h2', attrs={'class':'h2'}), dict(name='div', attrs={'class':'art-lft'}) ] @@ -24,3 +25,5 @@ class AdvancedUserRecipe1306097511(BasicNewsRecipe): feeds = [ (u'News', u'http://www.metro.co.uk/rss/news/'), (u'Money', u'http://www.metro.co.uk/rss/money/'), (u'Sport', u'http://www.metro.co.uk/rss/sport/'), (u'Film', u'http://www.metro.co.uk/rss/metrolife/film/'), (u'Music', u'http://www.metro.co.uk/rss/metrolife/music/'), (u'TV', u'http://www.metro.co.uk/rss/tv/'), (u'Showbiz', u'http://www.metro.co.uk/rss/showbiz/'), (u'Weird News', u'http://www.metro.co.uk/rss/weird/'), (u'Travel', u'http://www.metro.co.uk/rss/travel/'), (u'Lifestyle', u'http://www.metro.co.uk/rss/lifestyle/'), (u'Books', u'http://www.metro.co.uk/rss/lifestyle/books/'), (u'Food', u'http://www.metro.co.uk/rss/lifestyle/restaurants/')] + + diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 3e2201f6a4..69407dcb2e 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -74,7 +74,7 @@ class Metadata(object): Metadata from custom columns should be accessed via the get() method, passing in the lookup name for the column, for example: "#mytags". - Use the :meth:`is_null` method to test if a filed is null. + Use the :meth:`is_null` method to test if a field is null. This object also has functions to format fields into strings. @@ -105,7 +105,7 @@ class Metadata(object): def is_null(self, field): ''' - Return True if the value of filed is null in this object. + Return True if the value of field is null in this object. 'null' means it is unknown or evaluates to False. So a title of _('Unknown') is null or a language of 'und' is null.