From f55b74bae43b5a67bb18ad9c0fbdcbabbe9fb384 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 12 Dec 2009 10:52:24 -0700 Subject: [PATCH 1/4] ... --- src/calibre/ebooks/pdf/reflow.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/calibre/ebooks/pdf/reflow.py b/src/calibre/ebooks/pdf/reflow.py index 31002c72fe..8cef0f327d 100644 --- a/src/calibre/ebooks/pdf/reflow.py +++ b/src/calibre/ebooks/pdf/reflow.py @@ -18,8 +18,6 @@ class Font(object): class Text(object): - A = etree.XPath('descendant::a[@href]') - def __init__(self, text, font_map, opts, log): self.opts, self.log = opts, log self.font_map = font_map From 658bdb36ccbec48f935dd5ae7874939f6a071f96 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 12 Dec 2009 10:53:10 -0700 Subject: [PATCH 2/4] Fix setup.py --clean-all --- setup/extensions.py | 6 +++--- setup/installer/__init__.py | 2 +- src/calibre/ebooks/pdb/ereader/reader132.py | 2 +- src/calibre/ebooks/pdb/ereader/reader202.py | 4 ++-- src/calibre/ebooks/pdb/palmdoc/reader.py | 2 +- src/calibre/ebooks/pdb/palmdoc/writer.py | 3 ++- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/setup/extensions.py b/setup/extensions.py index faa1a3d88a..0d465f4a0a 100644 --- a/setup/extensions.py +++ b/setup/extensions.py @@ -375,9 +375,9 @@ class Build(Command): for x in (dest, dest+'.manifest'): if os.path.exists(x): os.remove(x) - shutil.rmtree(self.j(self.d(self.SRC), 'build')) - - + build_dir = self.j(self.d(self.SRC), 'build') + if os.path.exists(build_dir): + shutil.rmtree(build_dir) class BuildPDF2XML(Command): diff --git a/setup/installer/__init__.py b/setup/installer/__init__.py index 99e7586aa3..2acc5d4649 100644 --- a/setup/installer/__init__.py +++ b/setup/installer/__init__.py @@ -126,5 +126,5 @@ class VMInstaller(Command): def clean(self): installer = self.installer() - if os.patyh.exists(installer): + if os.path.exists(installer): os.remove(installer) diff --git a/src/calibre/ebooks/pdb/ereader/reader132.py b/src/calibre/ebooks/pdb/ereader/reader132.py index d2a1c006e3..cce1d40f8c 100644 --- a/src/calibre/ebooks/pdb/ereader/reader132.py +++ b/src/calibre/ebooks/pdb/ereader/reader132.py @@ -15,7 +15,6 @@ import zlib from calibre import CurrentDir from calibre.ebooks import DRMError -from calibre.ebooks.compression.palmdoc import decompress_doc from calibre.ebooks.metadata.opf2 import OPFCreator from calibre.ebooks.pdb.ereader import EreaderError from calibre.ebooks.pdb.formatreader import FormatReader @@ -79,6 +78,7 @@ class Reader132(FormatReader): def decompress_text(self, number): if self.header_record.compression == 2: + from calibre.ebooks.compression.palmdoc import decompress_doc return decompress_doc(self.section_data(number)).decode('cp1252' if self.encoding is None else self.encoding, 'replace') if self.header_record.compression == 10: return zlib.decompress(self.section_data(number)).decode('cp1252' if self.encoding is None else self.encoding, 'replace') diff --git a/src/calibre/ebooks/pdb/ereader/reader202.py b/src/calibre/ebooks/pdb/ereader/reader202.py index ce7ad1263a..a674c5bf60 100644 --- a/src/calibre/ebooks/pdb/ereader/reader202.py +++ b/src/calibre/ebooks/pdb/ereader/reader202.py @@ -12,7 +12,6 @@ import struct from calibre import CurrentDir from calibre.ebooks.metadata.opf2 import OPFCreator -from calibre.ebooks.compression.palmdoc import decompress_doc from calibre.ebooks.pdb.formatreader import FormatReader from calibre.ebooks.pdb.ereader import EreaderError @@ -55,7 +54,8 @@ class Reader202(FormatReader): return self.sections[number] def decompress_text(self, number): - return decompress_doc(''.join([chr(ord(x) ^ 0xA5) for x in self.section_data(number)])).decode('cp1252' if self.encoding is None else self.encoding, 'replace') + from calibre.ebooks.compression.palmdoc import decompress_doc + return decompress_doc(''.join([chr(ord(x) ^ 0xA5) for x in self.section_data(number)])).decode('cp1252' if self.encoding is None else self.encoding, 'replace') def get_image(self, number): name = None diff --git a/src/calibre/ebooks/pdb/palmdoc/reader.py b/src/calibre/ebooks/pdb/palmdoc/reader.py index 0a57e3f51a..ea7e6bbc2b 100644 --- a/src/calibre/ebooks/pdb/palmdoc/reader.py +++ b/src/calibre/ebooks/pdb/palmdoc/reader.py @@ -11,7 +11,6 @@ __docformat__ = 'restructuredtext en' import os import struct -from calibre.ebooks.compression.palmdoc import decompress_doc from calibre.ebooks.pdb.formatreader import FormatReader from calibre.ebooks.txt.processor import convert_basic, opf_writer, \ separate_paragraphs_single_line, separate_paragraphs_print_formatted @@ -51,6 +50,7 @@ class Reader(FormatReader): if self.header_record.compression == 1: return self.section_data(number).decode('cp1252' if self.encoding is None else self.encoding) if self.header_record.compression == 2: + from calibre.ebooks.compression.palmdoc import decompress_doc return decompress_doc(self.section_data(number)).decode('cp1252' if self.encoding is None else self.encoding, 'replace') return '' diff --git a/src/calibre/ebooks/pdb/palmdoc/writer.py b/src/calibre/ebooks/pdb/palmdoc/writer.py index 91a5eb3d97..3f4a92fbed 100644 --- a/src/calibre/ebooks/pdb/palmdoc/writer.py +++ b/src/calibre/ebooks/pdb/palmdoc/writer.py @@ -10,7 +10,6 @@ __docformat__ = 'restructuredtext en' import struct -from calibre.ebooks.compression.palmdoc import compress_doc from calibre.ebooks.pdb.formatwriter import FormatWriter from calibre.ebooks.pdb.header import PdbHeaderBuilder from calibre.ebooks.txt.txtml import TXTMLizer @@ -25,6 +24,8 @@ class Writer(FormatWriter): self.log = log def write_content(self, oeb_book, out_stream, metadata=None): + from calibre.ebooks.compression.palmdoc import compress_doc + title = self.opts.title if self.opts.title else oeb_book.metadata.title[0].value if oeb_book.metadata.title != [] else _('Unknown') txt_records, txt_length = self._generate_text(oeb_book) From a4082773adc590a68b36d3916ee16a999e9fc2cf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 12 Dec 2009 12:06:14 -0700 Subject: [PATCH 3/4] New recipes: Golem, Netzpolitik by KG and Nu.nl by Rob Hankel --- resources/recipes/golem_de.recipe | 17 ++++++++ resources/recipes/netzpolitik.recipe | 14 ++++++ resources/recipes/nu.recipe | 53 +++++++++++++++++++++++ src/calibre/gui2/dialogs/user_profiles.py | 2 +- 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 resources/recipes/golem_de.recipe create mode 100644 resources/recipes/netzpolitik.recipe create mode 100644 resources/recipes/nu.recipe diff --git a/resources/recipes/golem_de.recipe b/resources/recipes/golem_de.recipe new file mode 100644 index 0000000000..d0280a9617 --- /dev/null +++ b/resources/recipes/golem_de.recipe @@ -0,0 +1,17 @@ +from calibre.web.feeds.news import BasicNewsRecipe + +class AdvancedUserRecipe1257093338(BasicNewsRecipe): + title = u'Golem.de' + language = 'de' + __author__ = 'Kovid Goyal' + oldest_article = 7 + max_articles_per_feed = 100 + + feeds = [(u'Golem.de', u'http://rss.golem.de/rss.php?feed=ATOM1.0')] + + def print_version(self, url): + murxb = url.rfind('/') + 1 + murxc = url[murxb :-5] + murxa = 'http://www.golem.de/' + 'print.php?a=' + murxc + return murxa + diff --git a/resources/recipes/netzpolitik.recipe b/resources/recipes/netzpolitik.recipe new file mode 100644 index 0000000000..52d3c57f39 --- /dev/null +++ b/resources/recipes/netzpolitik.recipe @@ -0,0 +1,14 @@ +from calibre.web.feeds.news import BasicNewsRecipe + +class BasicUserRecipe1257093186(BasicNewsRecipe): + title = u'Netzpolitik' + oldest_article = 14 + language = 'de' + no_stylesheets = True + __author__ = 'Kovid Goyal' + max_articles_per_feed = 100 + remove_tags = [dict(id=['respond', 'ackt', 'nav', 'commentblock', + 'l_sidebar', 'r_sidebar']), dict(attrs={'class':['widgettitle', + 'bt-links', 'navigation']})] + + feeds = [(u'Netzpolitik.org', u'http://www.netzpolitik.org/feed/')] diff --git a/resources/recipes/nu.recipe b/resources/recipes/nu.recipe new file mode 100644 index 0000000000..782193b55c --- /dev/null +++ b/resources/recipes/nu.recipe @@ -0,0 +1,53 @@ +__license__ = 'GPL v3' +__copyright__ = '2009, Rob Hankel ' +''' +nu.nl +''' + +from calibre.web.feeds.news import BasicNewsRecipe + +class Nu(BasicNewsRecipe): + title = u'Nu.nl' + __author__ = u'Rob Hankel' + + publisher = 'nu.nl' + description = u'Dutch News' + category = 'news' + oldest_article = 7 + max_articles_per_feed = 100 + no_stylesheets = True + use_embedded_content = False + encoding = 'utf-8' + remove_javascript = True + language = 'nl' + + keep_only_tags = [dict(name='div' , attrs={'id':['leadarticle']})] + + feeds = [(u'binnenland', u'http://www.nu.nl/feeds/rss/binnenland.rss'), + (u'Algemeen nieuws', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Algemeen'), + (u'Economie', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Economie'), + (u'Internet', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Internet'), + (u'Sport', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Sport'), + (u'Achterklap', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Achterklap'), + (u'Opmerkelijk', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Opmerkelijk'), + (u'Muziek', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Muziek'), + (u'DVD', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=DVD'), + (u'Film', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Film'), + (u'Boek', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Boek'), + (u'Games', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Games'), + (u'Columns', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Columns'), + (u'Cartoon', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Cartoon'), + (u'Lifehacking', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Lifehacking'), + (u'Jurryt', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Jurryt'), + (u'Formule 1', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Formule1'), + (u'Plugged', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Plugged'), + (u'Auto', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Auto'), + (u'Wetenschap', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Wetenschap'), + (u'Gezondheid', u'http://www.nu.nl/deeplink_rss2/index.jsp?r=Gezondheid'), + (u'Dagelijkse tv-tips', u'http://www.nu.nl/tvgids/rss/tips'), + (u'Podcast Algemeen nieuws', u'http://www.nu.nl/podcast.php')] + + + def get_article_url(self, article): + return article.get('guid', None) + diff --git a/src/calibre/gui2/dialogs/user_profiles.py b/src/calibre/gui2/dialogs/user_profiles.py index 86449a34e7..bd332c2aa3 100644 --- a/src/calibre/gui2/dialogs/user_profiles.py +++ b/src/calibre/gui2/dialogs/user_profiles.py @@ -126,7 +126,7 @@ class UserProfiles(ResizableDialog, Ui_Dialog): if not title or not src: error_dialog(self, _('No recipe selected'), _('No recipe selected')).exec_() return - pt = PersistentTemporaryFile(suffix='.py') + pt = PersistentTemporaryFile(suffix='.recipe') pt.write(src.encode('utf-8')) pt.close() body = _('The attached file: %s is a recipe to download %s.')%(os.path.basename(pt.name), title) From 8919eacd7a94561108181acb0b973ea9a6c77488 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 12 Dec 2009 12:25:10 -0700 Subject: [PATCH 4/4] libusb info should now work on 32 bit platforms as well --- src/calibre/devices/libusb.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/libusb.c b/src/calibre/devices/libusb.c index 3cc506e5fe..c13927d44f 100644 --- a/src/calibre/devices/libusb.c +++ b/src/calibre/devices/libusb.c @@ -65,19 +65,23 @@ py_libusb_scan(PyObject *self, PyObject *args) { PyObject* py_libusb_info(PyObject *self, PyObject *args) { - unsigned long idVendor, idProduct, bcdDevice; + uint16_t idVendor, idProduct, bcdDevice; ssize_t ret = 0, i = 0; int err = 0, n; libusb_device **list = NULL; libusb_device_handle *handle = NULL; struct libusb_device_descriptor dev; - PyObject *ans, *t; + PyObject *ans, *t, *t1 = NULL, *t2 = NULL, *t3 = NULL; unsigned char data[1000]; if (ctxt == NULL) return PyErr_NoMemory(); - if (!PyArg_ParseTuple(args, "LLL", &idVendor, &idProduct, &bcdDevice)) + if (!PyArg_ParseTuple(args, "OOO", &t1, &t2, &t3)) return NULL; + idVendor = (uint16_t)PyInt_AsSsize_t(t1); + idProduct = (uint16_t)PyInt_AsSsize_t(t2); + bcdDevice = (uint16_t)PyInt_AsSsize_t(t3); + ret = libusb_get_device_list(ctxt, &list); if (ret == LIBUSB_ERROR_NO_MEM) return PyErr_NoMemory();