calibre now depends on dnspython for email delivery. Also remove python 2.5 builds as it is no longer officially supported, though calibre will probably continue to run on it for a little while longer.

This commit is contained in:
Kovid Goyal 2009-03-25 18:47:23 -07:00
parent 52d968838c
commit 9ca023e9a7
11 changed files with 480 additions and 460 deletions

View File

@ -9,7 +9,7 @@ Create linux binary.
''' '''
def freeze(): def freeze():
import glob, sys, subprocess, tarfile, os, re, textwrap, shutil, cStringIO, bz2, codecs import glob, sys, tarfile, os, textwrap, shutil
from contextlib import closing from contextlib import closing
from cx_Freeze import Executable, setup from cx_Freeze import Executable, setup
from calibre.constants import __version__, __appname__ from calibre.constants import __version__, __appname__
@ -81,6 +81,8 @@ def freeze():
includes = [x[0] for x in executables.values()] includes = [x[0] for x in executables.values()]
includes += ['calibre.ebooks.lrf.fonts.prs500.'+x for x in FONT_MAP.values()] includes += ['calibre.ebooks.lrf.fonts.prs500.'+x for x in FONT_MAP.values()]
includes += ['email.iterators', 'email.generator']
excludes = ['matplotlib', "Tkconstants", "Tkinter", "tcl", "_imagingtk", excludes = ['matplotlib', "Tkconstants", "Tkinter", "tcl", "_imagingtk",
"ImageTk", "FixTk", 'wx', 'PyQt4.QtAssistant', 'PyQt4.QtOpenGL.so', "ImageTk", "FixTk", 'wx', 'PyQt4.QtAssistant', 'PyQt4.QtOpenGL.so',
@ -88,7 +90,7 @@ def freeze():
'glib', 'gobject'] 'glib', 'gobject']
packages = ['calibre', 'encodings', 'cherrypy', 'cssutils', 'xdg', packages = ['calibre', 'encodings', 'cherrypy', 'cssutils', 'xdg',
'dateutil'] 'dateutil', 'dns', 'email']
includes += ['calibre.web.feeds.recipes.'+r for r in recipe_modules] includes += ['calibre.web.feeds.recipes.'+r for r in recipe_modules]

View File

@ -14,12 +14,11 @@ IMAGEMAGICK_DIR = 'C:\\ImageMagick'
FONTCONFIG_DIR = 'C:\\fontconfig' FONTCONFIG_DIR = 'C:\\fontconfig'
VC90 = r'C:\VC90.CRT' VC90 = r'C:\VC90.CRT'
import sys, os, py2exe, shutil, zipfile, glob, subprocess, re import sys, os, py2exe, shutil, zipfile, glob, re
from distutils.core import setup from distutils.core import setup
from distutils.filelist import FileList
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
sys.path.insert(0, BASE_DIR) sys.path.insert(0, BASE_DIR)
from setup import VERSION, APPNAME, entry_points, scripts, basenames from setup import VERSION, APPNAME, scripts, basenames
sys.path.remove(BASE_DIR) sys.path.remove(BASE_DIR)
ICONS = [os.path.abspath(os.path.join(BASE_DIR, 'icons', i)) for i in ('library.ico', 'viewer.ico')] ICONS = [os.path.abspath(os.path.join(BASE_DIR, 'icons', i)) for i in ('library.ico', 'viewer.ico')]
@ -145,6 +144,8 @@ def main(args=sys.argv):
'sip', 'pkg_resources', 'PyQt4.QtSvg', 'sip', 'pkg_resources', 'PyQt4.QtSvg',
'mechanize', 'ClientForm', 'wmi', 'mechanize', 'ClientForm', 'wmi',
'win32file', 'pythoncom', 'win32file', 'pythoncom',
'email.iterators',
'email.generator',
'win32process', 'win32api', 'msvcrt', 'win32process', 'win32api', 'msvcrt',
'win32event', 'calibre.ebooks.lrf.any.*', 'win32event', 'calibre.ebooks.lrf.any.*',
'calibre.ebooks.lrf.feeds.*', 'calibre.ebooks.lrf.feeds.*',
@ -155,7 +156,7 @@ def main(args=sys.argv):
'PyQt4.QtWebKit', 'PyQt4.QtNetwork', 'PyQt4.QtWebKit', 'PyQt4.QtNetwork',
], ],
'packages' : ['PIL', 'lxml', 'cherrypy', 'packages' : ['PIL', 'lxml', 'cherrypy',
'dateutil'], 'dateutil', 'dns'],
'excludes' : ["Tkconstants", "Tkinter", "tcl", 'excludes' : ["Tkconstants", "Tkinter", "tcl",
"_imagingtk", "ImageTk", "FixTk" "_imagingtk", "ImageTk", "FixTk"
], ],

View File

@ -28,7 +28,8 @@ def fetch_metadata(url, max=100, timeout=5.):
raw = urlopen(url).read() raw = urlopen(url).read()
except Exception, err: except Exception, err:
raise ISBNDBError('Could not fetch ISBNDB metadata. Error: '+str(err)) raise ISBNDBError('Could not fetch ISBNDB metadata. Error: '+str(err))
soup = BeautifulStoneSoup(raw) soup = BeautifulStoneSoup(raw,
convertEntities=BeautifulStoneSoup.XML_ENTITIES)
book_list = soup.find('booklist') book_list = soup.find('booklist')
if book_list is None: if book_list is None:
errmsg = soup.find('errormessage').string errmsg = soup.find('errormessage').string

View File

@ -337,7 +337,7 @@ class DeviceMenu(QMenu):
class Emailer(Thread): class Emailer(Thread):
def __init__(self, timeout=10): def __init__(self, timeout=60):
Thread.__init__(self) Thread.__init__(self)
self.setDaemon(True) self.setDaemon(True)
self.job_lock = RLock() self.job_lock = RLock()
@ -369,6 +369,7 @@ class Emailer(Thread):
def _send_mails(self, jobnames, callback, attachments, def _send_mails(self, jobnames, callback, attachments,
to_s, subjects, texts, attachment_names): to_s, subjects, texts, attachment_names):
opts = email_config().parse() opts = email_config().parse()
opts.verbose = 3 if os.environ.get('CALIBRE_DEBUG_EMAIL', False) else 0
from_ = opts.from_ from_ = opts.from_
if not from_: if not from_:
from_ = 'calibre <calibre@'+socket.getfqdn()+'>' from_ = 'calibre <calibre@'+socket.getfqdn()+'>'
@ -380,7 +381,8 @@ class Emailer(Thread):
attachment_name = attachment_names[i]) attachment_name = attachment_names[i])
efrom, eto = map(extract_email_address, (from_, to_s[i])) efrom, eto = map(extract_email_address, (from_, to_s[i]))
eto = [eto] eto = [eto]
sendmail(msg, efrom, eto, localhost=None, verbose=0, sendmail(msg, efrom, eto, localhost=None,
verbose=opts.verbose,
timeout=self.timeout, relay=opts.relay_host, timeout=self.timeout, relay=opts.relay_host,
username=opts.relay_username, username=opts.relay_username,
password=opts.relay_password, port=opts.relay_port, password=opts.relay_password, port=opts.relay_port,

View File

@ -11,7 +11,7 @@ from PyQt4.QtCore import Qt, QObject, SIGNAL, QVariant, QThread, \
from PyQt4.QtGui import QDialog, QItemSelectionModel from PyQt4.QtGui import QDialog, QItemSelectionModel
from calibre.gui2.dialogs.fetch_metadata_ui import Ui_FetchMetadata from calibre.gui2.dialogs.fetch_metadata_ui import Ui_FetchMetadata
from calibre.gui2 import error_dialog, NONE, info_dialog, warning_dialog from calibre.gui2 import error_dialog, NONE, info_dialog
from calibre.gui2.widgets import ProgressIndicator from calibre.gui2.widgets import ProgressIndicator
from calibre.utils.config import prefs from calibre.utils.config import prefs
@ -184,6 +184,16 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
self.matches.resizeColumnsToContents() self.matches.resizeColumnsToContents()
self.pi.stop() self.pi.stop()
def terminate(self):
if hasattr(self, 'fetcher') and self.fetcher.isRunning():
self.fetcher.terminate()
def __enter__(self, *args):
return self
def __exit__(self, *args):
self.terminate()
def selected_book(self): def selected_book(self):
try: try:

View File

@ -1,3 +1,4 @@
from __future__ import with_statement
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
''' '''
@ -412,6 +413,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
publisher = qstring_to_unicode(self.publisher.currentText()) publisher = qstring_to_unicode(self.publisher.currentText())
if isbn or title or author or publisher: if isbn or title or author or publisher:
d = FetchMetadata(self, isbn, title, author, publisher, self.timeout) d = FetchMetadata(self, isbn, title, author, publisher, self.timeout)
with d:
d.exec_() d.exec_()
if d.result() == QDialog.Accepted: if d.result() == QDialog.Accepted:
book = d.selected_book() book = d.selected_book()

View File

@ -5,7 +5,7 @@ import re, textwrap
DEPENDENCIES = [ DEPENDENCIES = [
#(Generic, version, gentoo, ubuntu, fedora) #(Generic, version, gentoo, ubuntu, fedora)
('python', '2.5', None, None, None), ('python', '2.6', None, None, None),
('setuptools', '0.6c5', 'setuptools', 'python-setuptools', 'python-setuptools-devel'), ('setuptools', '0.6c5', 'setuptools', 'python-setuptools', 'python-setuptools-devel'),
('Python Imaging Library', '1.1.6', 'imaging', 'python-imaging', 'python-imaging'), ('Python Imaging Library', '1.1.6', 'imaging', 'python-imaging', 'python-imaging'),
('libusb', '0.1.12', None, None, None), ('libusb', '0.1.12', None, None, None),

View File

@ -32,7 +32,10 @@ def create_mail(from_, to, subject, text=None, attachment_data=None,
if attachment_data is not None: if attachment_data is not None:
from email.mime.base import MIMEBase from email.mime.base import MIMEBase
assert attachment_data and attachment_name assert attachment_data and attachment_name
try:
maintype, subtype = attachment_type.split('/', 1) maintype, subtype = attachment_type.split('/', 1)
except AttributeError:
maintype, subtype = 'application', 'octet-stream'
msg = MIMEBase(maintype, subtype) msg = MIMEBase(maintype, subtype)
msg.set_payload(attachment_data) msg.set_payload(attachment_data)
encoders.encode_base64(msg) encoders.encode_base64(msg)
@ -50,9 +53,11 @@ def get_mx(host):
def sendmail_direct(from_, to, msg, timeout, localhost, verbose): def sendmail_direct(from_, to, msg, timeout, localhost, verbose):
import smtplib import smtplib
hosts = get_mx(to.split('@')[-1].strip())
if 'darwin' in sys.platform:
timeout=None # Non blocking sockets dont work on OS X
s = smtplib.SMTP(timeout=timeout, local_hostname=localhost) s = smtplib.SMTP(timeout=timeout, local_hostname=localhost)
s.set_debuglevel(verbose) s.set_debuglevel(verbose)
hosts = get_mx(to.split('@')[-1].strip())
if not hosts: if not hosts:
raise ValueError('No mail server found for address: %s'%to) raise ValueError('No mail server found for address: %s'%to)
last_error = last_traceback = None last_error = last_traceback = None
@ -76,6 +81,8 @@ def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=30,
return sendmail_direct(from_, x, msg, timeout, localhost, verbose) return sendmail_direct(from_, x, msg, timeout, localhost, verbose)
import smtplib import smtplib
cls = smtplib.SMTP if encryption == 'TLS' else smtplib.SMTP_SSL cls = smtplib.SMTP if encryption == 'TLS' else smtplib.SMTP_SSL
if 'darwin' in sys.platform:
timeout = None # Non-blocking sockets in OS X don't work
s = cls(timeout=timeout, local_hostname=localhost) s = cls(timeout=timeout, local_hostname=localhost)
s.set_debuglevel(verbose) s.set_debuglevel(verbose)
if port < 0: if port < 0:

View File

@ -379,7 +379,7 @@ class BasicNewsRecipe(object, LoggingInterface):
if raw: if raw:
return _raw return _raw
if not isinstance(_raw, unicode) and self.encoding: if not isinstance(_raw, unicode) and self.encoding:
_raw = _raw.decode(self.encoding) _raw = _raw.decode(self.encoding, 'replace')
massage = list(BeautifulSoup.MARKUP_MASSAGE) massage = list(BeautifulSoup.MARKUP_MASSAGE)
massage.append((re.compile(r'&(\S+?);'), lambda match: entity_to_unicode(match, encoding=self.encoding))) massage.append((re.compile(r'&(\S+?);'), lambda match: entity_to_unicode(match, encoding=self.encoding)))
return BeautifulSoup(_raw, markupMassage=massage) return BeautifulSoup(_raw, markupMassage=massage)

View File

@ -651,11 +651,6 @@ class upload_to_pypi(OptionlessCommand):
def run(self): def run(self):
check_call('python setup.py register'.split()) check_call('python setup.py register'.split())
check_call('rm -f dist/*', shell=True) check_call('rm -f dist/*', shell=True)
check_call('sudo rm -rf build src/calibre/plugins/*', shell=True)
os.mkdir('build')
check_call('python2.5 setup.py build_ext bdist_egg --exclude-source-files upload'.split())
check_call('sudo rm -rf build src/calibre/plugins/*', shell=True)
os.mkdir('build')
check_call('python setup.py build_ext bdist_egg --exclude-source-files upload'.split()) check_call('python setup.py build_ext bdist_egg --exclude-source-files upload'.split())
check_call('python setup.py sdist upload'.split()) check_call('python setup.py sdist upload'.split())