Added with: to dispatch enabling __enter__ execution

This commit is contained in:
GRiker 2010-01-14 09:54:28 -07:00
commit a94451984d
7 changed files with 167 additions and 69 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

View File

@ -0,0 +1,52 @@
__license__ = 'GPL v3'
__copyright__ = '2010, Darko Miletic <darko.miletic at gmail.com>'
'''
www.eluniversal.com
'''
from calibre import strftime
from calibre.web.feeds.recipes import BasicNewsRecipe
class ElUniversal(BasicNewsRecipe):
title = 'El Universal'
__author__ = 'Darko Miletic'
description = 'Noticias de Venezuela'
oldest_article = 2
max_articles_per_feed = 100
no_stylesheets = True
use_embedded_content = False
encoding = 'cp1252'
publisher = 'El Universal'
category = 'news, Caracas, Venezuela, world'
language = 'es'
cover_url = strftime('http://static.eluniversal.com/%Y/%m/%d/portada.jpg')
conversion_options = {
'comments' : description
,'tags' : category
,'language' : language
,'publisher' : publisher
}
keep_only_tags = [dict(name='div', attrs={'class':'Nota'})]
remove_tags = [
dict(name=['object','link','script','iframe'])
,dict(name='div',attrs={'class':'Herramientas'})
]
feeds = [
(u'Ultimas Noticias', u'http://www.eluniversal.com/rss/avances.xml' )
,(u'Economia' , u'http://www.eluniversal.com/rss/eco_avances.xml')
,(u'Internacionales' , u'http://www.eluniversal.com/rss/int_avances.xml')
,(u'Deportes' , u'http://www.eluniversal.com/rss/dep_avances.xml')
,(u'Cultura' , u'http://www.eluniversal.com/rss/cul_avances.xml')
,(u'Nacional y politica' , u'http://www.eluniversal.com/rss/pol_avances.xml')
,(u'Ciencia y tecnologia', u'http://www.eluniversal.com/rss/cyt_avances.xml')
,(u'Universo empresarial', u'http://www.eluniversal.com/rss/uni_avances.xml')
,(u'Caracas' , u'http://www.eluniversal.com/rss/ccs_avances.xml')
]
def print_version(self, url):
rp,sep,rest = url.rpartition('/')
return rp + sep + 'imp_' + rest

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from calibre.web.feeds.recipes import BasicNewsRecipe from calibre.web.feeds.recipes import BasicNewsRecipe
class NYTimes(BasicNewsRecipe): class NYTimes(BasicNewsRecipe):
@ -9,21 +10,17 @@ class NYTimes(BasicNewsRecipe):
needs_subscription = True needs_subscription = True
no_stylesheets = True no_stylesheets = True
#remove_tags_before = dict(name='h1', attrs={'class':'heading'}) remove_tags_before = dict(name='div', attrs={'align':'center'})
#remove_tags_after = dict(name='td', attrs={'class':'newptool1'}) remove_tags_after = dict(name='ol', attrs={'compact':'COMPACT'})
remove_tags = [ remove_tags = [
dict(name='iframe'), dict(name='iframe'),
#dict(name='div', attrs={'class':'related-articles'}), #dict(name='div', attrs={'class':'related-articles'}),
#dict(name='div', attrs={'id':['qrformdiv', 'inSection', 'alpha-inner']}), dict(name='div', attrs={'id':['sidebar']}),
dict(name='form', attrs={'onsubmit':"return verifySearch(this.w,'Keyword, citation, or author')"}), #dict(name='form', attrs={'onsubmit':"return verifySearch(this.w,'Keyword, citation, or author')"}),
dict(name='table', attrs={'cellspacing':'0'}), dict(name='table', attrs={'align':'RIGHT'}),
] ]
def preprocess_html(self, soup):
table = soup.find('table')
if table is not None:
table.extract()
return soup
#TO LOGIN #TO LOGIN
def get_browser(self): def get_browser(self):
@ -44,9 +41,9 @@ class NYTimes(BasicNewsRecipe):
# To parse artice toc # To parse artice toc
def parse_index(self): def parse_index(self):
soup = self.nejm_get_index() parse_soup = self.nejm_get_index()
div = soup.find(id='centerTOC') div = parse_soup.find(id='centerTOC')
current_section = None current_section = None
current_articles = [] current_articles = []
@ -81,3 +78,20 @@ class NYTimes(BasicNewsRecipe):
return feeds return feeds
def preprocess_html(self, soup):
for a in soup.findAll(text=lambda x: x and '[in this window]' in x):
a = a.findParent('a')
url = a.get('href', None)
if not url:
continue
if url.startswith('/'):
url = 'http://content.nejm.org'+url
isoup = self.index_to_soup(url)
img = isoup.find('img', src=lambda x: x and
x.startswith('/content/'))
if img is not None:
img.extract()
table = a.findParent('table')
table.replaceWith(img)
return soup

View File

@ -354,21 +354,19 @@ def catalog_plugins():
for plugin in _initialized_plugins: for plugin in _initialized_plugins:
if isinstance(plugin, CatalogPlugin): if isinstance(plugin, CatalogPlugin):
yield plugin yield plugin
def available_catalog_formats(): def available_catalog_formats():
formats = set([]) formats = set([])
for plugin in catalog_plugins(): for plugin in catalog_plugins():
if not is_disabled(plugin): if not is_disabled(plugin):
for format in plugin.file_types: for format in plugin.file_types:
formats.add(format) formats.add(format)
return formats return formats
def plugin_for_catalog_format(fmt): def plugin_for_catalog_format(fmt):
for plugin in catalog_plugins(): for plugin in catalog_plugins():
if fmt.lower() in plugin.file_types: if fmt.lower() in plugin.file_types:
return plugin return plugin
else:
return None
def device_plugins(): def device_plugins():
for plugin in _initialized_plugins: for plugin in _initialized_plugins:

View File

@ -7,34 +7,47 @@ __docformat__ = 'restructuredtext en'
''' '''
import textwrap, os import textwrap, os
from PyQt4.QtCore import QCoreApplication, SIGNAL, QModelIndex, QUrl from PyQt4.QtCore import QCoreApplication, SIGNAL, QModelIndex, QUrl, QTimer, Qt
from PyQt4.QtGui import QDialog, QPixmap, QGraphicsScene, QIcon, QDesktopServices from PyQt4.QtGui import QDialog, QPixmap, QGraphicsScene, QIcon, QDesktopServices
from calibre.gui2.dialogs.book_info_ui import Ui_BookInfo from calibre.gui2.dialogs.book_info_ui import Ui_BookInfo
from calibre.gui2 import dynamic
from calibre import fit_image
class BookInfo(QDialog, Ui_BookInfo): class BookInfo(QDialog, Ui_BookInfo):
def __init__(self, parent, view, row): def __init__(self, parent, view, row):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
Ui_BookInfo.__init__(self) Ui_BookInfo.__init__(self)
self.setupUi(self) self.setupUi(self)
self.cover_pixmap = None
desktop = QCoreApplication.instance().desktop() desktop = QCoreApplication.instance().desktop()
screen_height = desktop.availableGeometry().height() - 100 screen_height = desktop.availableGeometry().height() - 100
self.resize(self.size().width(), screen_height) self.resize(self.size().width(), screen_height)
self.view = view self.view = view
self.current_row = None self.current_row = None
self.fit_cover.setChecked(dynamic.get('book_info_dialog_fit_cover',
False))
self.refresh(row) self.refresh(row)
self.connect(self.view.selectionModel(), SIGNAL('currentChanged(QModelIndex,QModelIndex)'), self.slave) self.connect(self.view.selectionModel(), SIGNAL('currentChanged(QModelIndex,QModelIndex)'), self.slave)
self.connect(self.next_button, SIGNAL('clicked()'), self.next) self.connect(self.next_button, SIGNAL('clicked()'), self.next)
self.connect(self.previous_button, SIGNAL('clicked()'), self.previous) self.connect(self.previous_button, SIGNAL('clicked()'), self.previous)
self.connect(self.text, SIGNAL('linkActivated(QString)'), self.open_book_path) self.connect(self.text, SIGNAL('linkActivated(QString)'), self.open_book_path)
self.fit_cover.stateChanged.connect(self.toggle_cover_fit)
self.cover.resizeEvent = self.cover_view_resized
def toggle_cover_fit(self, state):
dynamic.set('book_info_dialog_fit_cover', self.fit_cover.isChecked())
self.resize_cover()
def cover_view_resized(self, event):
QTimer.singleShot(1, self.resize_cover)
def slave(self, current, previous): def slave(self, current, previous):
row = current.row() row = current.row()
self.refresh(row) self.refresh(row)
def open_book_path(self, path): def open_book_path(self, path):
if os.sep in unicode(path): if os.sep in unicode(path):
QDesktopServices.openUrl(QUrl('file:'+path)) QDesktopServices.openUrl(QUrl('file:'+path))
@ -43,41 +56,53 @@ class BookInfo(QDialog, Ui_BookInfo):
path = self.view.model().db.format_abspath(self.current_row, format) path = self.view.model().db.format_abspath(self.current_row, format)
if path is not None: if path is not None:
QDesktopServices.openUrl(QUrl('file:'+path)) QDesktopServices.openUrl(QUrl('file:'+path))
def next(self): def next(self):
row = self.view.currentIndex().row() row = self.view.currentIndex().row()
ni = self.view.model().index(row+1, 0) ni = self.view.model().index(row+1, 0)
if ni.isValid(): if ni.isValid():
self.view.setCurrentIndex(ni) self.view.setCurrentIndex(ni)
def previous(self): def previous(self):
row = self.view.currentIndex().row() row = self.view.currentIndex().row()
ni = self.view.model().index(row-1, 0) ni = self.view.model().index(row-1, 0)
if ni.isValid(): if ni.isValid():
self.view.setCurrentIndex(ni) self.view.setCurrentIndex(ni)
def resize_cover(self):
if self.cover_pixmap is None:
return
self.setWindowIcon(QIcon(self.cover_pixmap))
self.scene = QGraphicsScene()
pixmap = self.cover_pixmap
if self.fit_cover.isChecked():
scaled, new_width, new_height = fit_image(pixmap.width(),
pixmap.height(), self.cover.size().width()-10,
self.cover.size().height()-10)
if scaled:
pixmap = pixmap.scaled(new_width, new_height,
Qt.KeepAspectRatio, Qt.SmoothTransformation)
self.scene.addPixmap(pixmap)
self.cover.setScene(self.scene)
def refresh(self, row): def refresh(self, row):
if isinstance(row, QModelIndex): if isinstance(row, QModelIndex):
row = row.row() row = row.row()
if row == self.current_row: if row == self.current_row:
return return
self.previous_button.setEnabled(False if row == 0 else True) self.previous_button.setEnabled(False if row == 0 else True)
self.next_button.setEnabled(False if row == self.view.model().rowCount(QModelIndex())-1 else True) self.next_button.setEnabled(False if row == self.view.model().rowCount(QModelIndex())-1 else True)
self.current_row = row self.current_row = row
info = self.view.model().get_book_info(row) info = self.view.model().get_book_info(row)
self.setWindowTitle(info[_('Title')]) self.setWindowTitle(info[_('Title')])
self.title.setText('<b>'+info.pop(_('Title'))) self.title.setText('<b>'+info.pop(_('Title')))
self.comments.setText(info.pop(_('Comments'), '')) self.comments.setText(info.pop(_('Comments'), ''))
cdata = info.pop('cover', '') cdata = info.pop('cover', '')
pixmap = QPixmap.fromImage(cdata) self.cover_pixmap = QPixmap.fromImage(cdata)
self.setWindowIcon(QIcon(pixmap)) self.resize_cover()
self.scene = QGraphicsScene()
self.scene.addPixmap(pixmap)
self.cover.setScene(self.scene)
rows = u'' rows = u''
self.text.setText('') self.text.setText('')
self.data = info self.data = info
@ -94,4 +119,4 @@ class BookInfo(QDialog, Ui_BookInfo):
txt = info[key] txt = info[key]
txt = u'<br />\n'.join(textwrap.wrap(txt, 120)) txt = u'<br />\n'.join(textwrap.wrap(txt, 120))
rows += u'<tr><td><b>%s:</b></td><td>%s</td></tr>'%(key, txt) rows += u'<tr><td><b>%s:</b></td><td>%s</td></tr>'%(key, txt)
self.text.setText(u'<table>'+rows+'</table>') self.text.setText(u'<table>'+rows+'</table>')

View File

@ -1,7 +1,8 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BookInfo</class> <class>BookInfo</class>
<widget class="QDialog" name="BookInfo" > <widget class="QDialog" name="BookInfo">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
@ -9,70 +10,77 @@
<height>783</height> <height>783</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout" > <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2" > <item row="0" column="0" colspan="2">
<widget class="QLabel" name="title" > <widget class="QLabel" name="title">
<property name="text" > <property name="text">
<string>TextLabel</string> <string>TextLabel</string>
</property> </property>
<property name="alignment" > <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" > <item row="1" column="0">
<widget class="QGraphicsView" name="cover" /> <widget class="QGraphicsView" name="cover"/>
</item> </item>
<item row="1" column="1" > <item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout" > <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QLabel" name="text" > <widget class="QLabel" name="text">
<property name="text" > <property name="text">
<string>TextLabel</string> <string>TextLabel</string>
</property> </property>
<property name="alignment" > <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property> </property>
<property name="wordWrap" > <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox" > <widget class="QGroupBox" name="groupBox">
<property name="title" > <property name="title">
<string>Comments</string> <string>Comments</string>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout">
<item row="0" column="0" > <item row="0" column="0">
<widget class="QTextBrowser" name="comments" /> <widget class="QTextBrowser" name="comments"/>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout" > <widget class="QCheckBox" name="fit_cover">
<property name="text">
<string>Fit &amp;cover to view</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QPushButton" name="previous_button" > <widget class="QPushButton" name="previous_button">
<property name="text" > <property name="text">
<string>&amp;Previous</string> <string>&amp;Previous</string>
</property> </property>
<property name="icon" > <property name="icon">
<iconset resource="../../../../resources/images.qrc" > <iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/previous.svg</normaloff>:/images/previous.svg</iconset> <normaloff>:/images/previous.svg</normaloff>:/images/previous.svg</iconset>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="next_button" > <widget class="QPushButton" name="next_button">
<property name="text" > <property name="text">
<string>&amp;Next</string> <string>&amp;Next</string>
</property> </property>
<property name="icon" > <property name="icon">
<iconset resource="../../../../resources/images.qrc" > <iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/next.svg</normaloff>:/images/next.svg</iconset> <normaloff>:/images/next.svg</normaloff>:/images/next.svg</iconset>
</property> </property>
</widget> </widget>
@ -84,7 +92,7 @@
</layout> </layout>
</widget> </widget>
<resources> <resources>
<include location="../../../../resources/images.qrc" /> <include location="../../../../resources/images.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -691,7 +691,8 @@ def command_catalog(args, dbpath):
return 1 return 1
if opts.verbose: if opts.verbose:
log("library.cli:command_catalog dispatching to plugin %s" % plugin.name) log("library.cli:command_catalog dispatching to plugin %s" % plugin.name)
plugin.run(args[1], opts, get_db(dbpath, opts)) with plugin:
plugin.run(args[1], opts, get_db(dbpath, opts))
return 0 return 0
# end of GR additions # end of GR additions