[Checkins] SVN: zopyx.smartprintng.server/trunk/ added convertZIPEmail() API
Andreas Jung
andreas at andreas-jung.com
Sat Jul 18 04:56:28 EDT 2009
Log message for revision 101981:
added convertZIPEmail() API
Changed:
U zopyx.smartprintng.server/trunk/docs/HISTORY.txt
U zopyx.smartprintng.server/trunk/server.ini
U zopyx.smartprintng.server/trunk/setup.py
U zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/__init__.py
U zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/base.py
U zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/mail_util.py
-=-
Modified: zopyx.smartprintng.server/trunk/docs/HISTORY.txt
===================================================================
--- zopyx.smartprintng.server/trunk/docs/HISTORY.txt 2009-07-18 07:48:48 UTC (rev 101980)
+++ zopyx.smartprintng.server/trunk/docs/HISTORY.txt 2009-07-18 08:56:28 UTC (rev 101981)
@@ -1,6 +1,11 @@
Changelog
=========
+0.4.0 (unreleased)
+------------------
+
+* added convertZIPEmail() API
+
0.3.4 (2009/07/13)
------------------
Modified: zopyx.smartprintng.server/trunk/server.ini
===================================================================
--- zopyx.smartprintng.server/trunk/server.ini 2009-07-18 07:48:48 UTC (rev 101980)
+++ zopyx.smartprintng.server/trunk/server.ini 2009-07-18 08:56:28 UTC (rev 101981)
@@ -10,4 +10,4 @@
[server:main]
use = egg:Paste#http
host = 0.0.0.0
-port = 8080
+port = 6543
Modified: zopyx.smartprintng.server/trunk/setup.py
===================================================================
--- zopyx.smartprintng.server/trunk/setup.py 2009-07-18 07:48:48 UTC (rev 101980)
+++ zopyx.smartprintng.server/trunk/setup.py 2009-07-18 08:56:28 UTC (rev 101981)
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os
-version = '0.3.4'
+version = '0.4.0'
setup(name='zopyx.smartprintng.server',
version=version,
Modified: zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/__init__.py
===================================================================
--- zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/__init__.py 2009-07-18 07:48:48 UTC (rev 101980)
+++ zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/__init__.py 2009-07-18 08:56:28 UTC (rev 101981)
@@ -16,3 +16,6 @@
# recursion error in guess_type()
import mimetypes
mimetypes.init()
+
+# init email subsystem
+import mail_util
Modified: zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/base.py
===================================================================
--- zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/base.py 2009-07-18 07:48:48 UTC (rev 101980)
+++ zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/base.py 2009-07-18 08:56:28 UTC (rev 101981)
@@ -12,8 +12,9 @@
import time
import uuid
import zipfile
+from logger import LOG
+import mail_util
from zopyx.convert2.convert import Converter
-from logger import LOG
temp_directory = os.path.join(tempfile.gettempdir(),
'zopyx.smartprintng.server')
@@ -42,15 +43,14 @@
""" Process a single HTML file """
return Converter(html_filename)(converter_name)
- def convertZIP(self, zip_archive, converter_name='pdf-prince'):
- """ Process html-file + images within a ZIP archive """
+ def _processZIP(self, zip_archive, converter_name):
+ # temp direcotry handling
now = datetime.now().strftime('%Y%m%d%Z%H%M%S')
ident = '%s-%s' % (now, uuid.uuid4())
tempdir = os.path.join(temp_directory, ident)
os.makedirs(tempdir)
- LOG.debug('Incoming request (%s, %d bytes, %s)' % (converter_name, len(zip_archive), tempdir))
- ts = time.time()
+
# store zip archive first
zip_temp = os.path.join(tempdir, 'input.zip')
file(zip_temp, 'wb').write(base64.decodestring(zip_archive))
@@ -80,30 +80,31 @@
ZF = zipfile.ZipFile(zip_out, 'w')
ZF.writestr('output%s' % ext, file(result, 'rb').read())
ZF.close()
+
+ return zip_out, result
+
+ def convertZIP(self, zip_archive, converter_name='pdf-prince'):
+ """ Process html-file + images within a ZIP archive """
+
+ LOG.debug('Incoming request (%s, %d bytes)' % (converter_name, len(zip_archive)))
+ ts = time.time()
+ zip_out, output_filename = self._processZIP(zip_archive, converter_name)
encoded_result = base64.encodestring(file(zip_out, 'rb').read())
- shutil.rmtree(tempdir)
- LOG.debug('Request end (%3.2lf seconds)' % (time.time() -ts))
+ shutil.rmtree(os.path.dirname(zip_out))
+ LOG.debug('Request end (%3.2lf seconds)' % (time.time() - ts))
return encoded_result
def convertZIPEmail(self, zip_archive, converter_name='pdf-prince', email_param={}):
+ """ Process zip archive and send conversion result as mail """
- def send_email(sender, recipient, subject, body):
- import email.MIMEText
- import email.Header
- from repoze.sendmail.interfaces import IMailDelivery
- from zope.component import getUtility
- msg = email.MIMEText.MIMEText(body.encode('UTF-8'), 'plain', 'UTF-8')
- msg["From"] = sender
- msg["To"] = recipient
- msg["Subject"] = email.Header.Header(subject, 'UTF-8')
- mailer = getUtility(IMailDelivery, 'my-app.smtp')
- mailer.send(sender, [recipient], msg.as_string())
-
- result = self.convertZIP(zip_archive, converter_name)
- send_email('info at zopyx.com', 'info at zopyx.com', 'test', 'test')
- return 'foo'
+ LOG.debug('Incoming request (%s, %d bytes)' % (converter_name, len(zip_archive)))
+ ts = time.time()
+ zip_out, output_filename = self._processZIP(zip_archive, converter_name)
+ mail_util.send_email('info at zopyx.com', 'info at zopyx.com', 'test', 'test', [output_filename])
+ shutil.rmtree(os.path.dirname(zip_out))
+ LOG.debug('Request end (%3.2lf seconds)' % (time.time() - ts))
+ return True
-
def availableConverters(self):
from zopyx.convert2.registry import availableConverters
return availableConverters()
Modified: zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/mail_util.py
===================================================================
--- zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/mail_util.py 2009-07-18 07:48:48 UTC (rev 101980)
+++ zopyx.smartprintng.server/trunk/zopyx/smartprintng/server/mail_util.py 2009-07-18 08:56:28 UTC (rev 101981)
@@ -25,7 +25,10 @@
def send_email(sender, recipient, subject, body, attachments=[]):
- mailer = makeMailer()
+ try:
+ mailer = makeMailer()
+ except Exception,e:
+ raise RuntimeError('Email configuration error (%s)' % e)
msg = email.MIMEMultipart.MIMEMultipart()
msg["From"] = sender
More information about the Checkins
mailing list