From eceb9175fd2aa419a4913d8fa20e86abc4e8b898 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Sat, 24 Sep 2011 12:53:33 +0200 Subject: [PATCH] appy.bin: backup.py: added the possibility to define login and password for SMTP authentication (the script allows to send mail); appy.pod: added the possibility to specify size of images to import (see https://answers.launchpad.net/appy/+question/171846). --- bin/backup.py | 19 ++++++++++++++++--- gen/plone25/skin/li.gif | Bin 0 -> 51 bytes pod/doc_importers.py | 14 +++++++++++--- pod/renderer.py | 19 +++++++++++++------ 4 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 gen/plone25/skin/li.gif diff --git a/bin/backup.py b/bin/backup.py index 00bf4e4..1eac11b 100644 --- a/bin/backup.py +++ b/bin/backup.py @@ -138,8 +138,17 @@ class ZodbBackuper: subject, self.logMem.getvalue()) try: w('> Sending mail notifications to %s...' % self.emails) - server, port = self.options.smtpServer.split(':') + smtpInfo = self.options.smtpServer.split(':', 3) + login = password = None + if len(smtpInfo) == 2: + # We simply have server and port + server, port = smtpInfo + else: + # We also have login and password + server, port, login, password = smtpInfo smtpServer = smtplib.SMTP(server, port=int(port)) + if login: + smtpServer.login(login, password) res = smtpServer.sendmail(self.options.fromAddress, self.emails.split(','), msg) if res: @@ -292,8 +301,12 @@ class ZodbBackupScript: default='', metavar="FROMADDRESS", type='string') optParser.add_option("-s", "--smtp-server", dest="smtpServer", help="SMTP server and port (ie: localhost:25) " \ - "for sending mails", default='localhost:25', - metavar="SMTPSERVER", type='string') + "for sending mails. You can also embed " \ + "username and password if the SMTP server " \ + "requires authentication, ie " \ + "localhost:25:myLogin:myPassword", + default='localhost:25', metavar="SMTPSERVER", + type='string') optParser.add_option("-t", "--tempFolder", dest="tempFolder", help="Folder used by OO for producing temp " \ "files. Defaults to /tmp.", diff --git a/gen/plone25/skin/li.gif b/gen/plone25/skin/li.gif new file mode 100644 index 0000000000000000000000000000000000000000..01f428b26bb3abad6cddfcc24f1d29d7405375e3 GIT binary patch literal 51 zcmZ?wbhEHbWM^PyXkcIn3JUuF|G(l-7FH1kMg|=QAOOiQFmbUYEu2~XN6Bg-1A{dH DI@$~K literal 0 HcmV?d00001 diff --git a/pod/doc_importers.py b/pod/doc_importers.py index 8f9a0d6..5c3a180 100644 --- a/pod/doc_importers.py +++ b/pod/doc_importers.py @@ -67,6 +67,8 @@ class DocImporter: f = file(self.importPath, 'wb') f.write(fileContent) f.close() + # ImageImporter adds additional, image-specific attrs, through + # ImageImporter.setImageInfo. def getImportFolder(self): '''This method must be overridden and gives the path where to dump the @@ -197,10 +199,13 @@ class ImageImporter(DocImporter): shutil.copy(at, importPath) return importPath - def setAnchor(self, anchor): + def setImageInfo(self, anchor, wrapInPara, size): + # Initialise anchor if anchor not in self.anchorTypes: raise PodError(self.WRONG_ANCHOR % str(self.anchorTypes)) self.anchor = anchor + self.wrapInPara = wrapInPara + self.size = size def run(self): # Some shorcuts for the used xml namespaces @@ -213,8 +218,11 @@ class ImageImporter(DocImporter): i = self.importPath.rfind(self.pictFolder) imagePath = self.importPath[i+1:].replace('\\', '/') self.fileNames[imagePath] = self.at - # Compute image size - width, height = getSize(self.importPath, self.format) + # Compute image size, or retrieve it from self.size if given + if self.size: + width, height = self.size + else: + width, height = getSize(self.importPath, self.format) if width != None: size = ' %s:width="%fcm" %s:height="%fcm"' % (s, width, s, height) else: diff --git a/pod/renderer.py b/pod/renderer.py index d6224e6..f0ddbdb 100644 --- a/pod/renderer.py +++ b/pod/renderer.py @@ -259,12 +259,20 @@ class Renderer: imageFormats = ('png', 'jpeg', 'jpg', 'gif') ooFormats = ('odt',) def importDocument(self, content=None, at=None, format=None, - anchor='as-char', wrapInPara=True): + anchor='as-char', wrapInPara=True, size=None): '''If p_at is not None, it represents a path or url allowing to find the document. If p_at is None, the content of the document is supposed to be in binary format in p_content. The document - p_format may be: odt or any format in imageFormats. p_anchor and - p_wrapInPara are only relevant for images.''' + p_format may be: odt or any format in imageFormats. + + p_anchor, p_wrapInPara and p_size are only relevant for images: + * p_anchor defines the way the image is anchored into the document; + Valid values are 'page','paragraph', 'char' and 'as-char'; + * p_wrapInPara, if true, wraps the resulting 'image' tag into a 'p' + tag; + * p_size, if specified, is a tuple of float or integers + (width, height) expressing size in centimeters. If not + specified, size will be computed from image info.''' ns = self.currentParser.env.namespaces importer = None # Is there someting to import? @@ -292,9 +300,8 @@ class Renderer: else: raise PodError(DOC_WRONG_FORMAT % format) imp = importer(content, at, format, self.tempFolder, ns, self.fileNames) - if isImage: - imp.setAnchor(anchor) - imp.wrapInPara = wrapInPara + # Initialise image-specific parameters + if isImage: imp.setImageInfo(anchor, wrapInPara, size) res = imp.run() return res