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).

This commit is contained in:
Gaetan Delannay 2011-09-24 12:53:33 +02:00
parent 96a592f125
commit eceb9175fd
4 changed files with 40 additions and 12 deletions

View file

@ -138,8 +138,17 @@ class ZodbBackuper:
subject, self.logMem.getvalue()) subject, self.logMem.getvalue())
try: try:
w('> Sending mail notifications to %s...' % self.emails) 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)) smtpServer = smtplib.SMTP(server, port=int(port))
if login:
smtpServer.login(login, password)
res = smtpServer.sendmail(self.options.fromAddress, res = smtpServer.sendmail(self.options.fromAddress,
self.emails.split(','), msg) self.emails.split(','), msg)
if res: if res:
@ -292,8 +301,12 @@ class ZodbBackupScript:
default='', metavar="FROMADDRESS", type='string') default='', metavar="FROMADDRESS", type='string')
optParser.add_option("-s", "--smtp-server", dest="smtpServer", optParser.add_option("-s", "--smtp-server", dest="smtpServer",
help="SMTP server and port (ie: localhost:25) " \ help="SMTP server and port (ie: localhost:25) " \
"for sending mails", default='localhost:25', "for sending mails. You can also embed " \
metavar="SMTPSERVER", type='string') "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", optParser.add_option("-t", "--tempFolder", dest="tempFolder",
help="Folder used by OO for producing temp " \ help="Folder used by OO for producing temp " \
"files. Defaults to /tmp.", "files. Defaults to /tmp.",

BIN
gen/plone25/skin/li.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 B

View file

@ -67,6 +67,8 @@ class DocImporter:
f = file(self.importPath, 'wb') f = file(self.importPath, 'wb')
f.write(fileContent) f.write(fileContent)
f.close() f.close()
# ImageImporter adds additional, image-specific attrs, through
# ImageImporter.setImageInfo.
def getImportFolder(self): def getImportFolder(self):
'''This method must be overridden and gives the path where to dump the '''This method must be overridden and gives the path where to dump the
@ -197,10 +199,13 @@ class ImageImporter(DocImporter):
shutil.copy(at, importPath) shutil.copy(at, importPath)
return importPath return importPath
def setAnchor(self, anchor): def setImageInfo(self, anchor, wrapInPara, size):
# Initialise anchor
if anchor not in self.anchorTypes: if anchor not in self.anchorTypes:
raise PodError(self.WRONG_ANCHOR % str(self.anchorTypes)) raise PodError(self.WRONG_ANCHOR % str(self.anchorTypes))
self.anchor = anchor self.anchor = anchor
self.wrapInPara = wrapInPara
self.size = size
def run(self): def run(self):
# Some shorcuts for the used xml namespaces # Some shorcuts for the used xml namespaces
@ -213,7 +218,10 @@ class ImageImporter(DocImporter):
i = self.importPath.rfind(self.pictFolder) i = self.importPath.rfind(self.pictFolder)
imagePath = self.importPath[i+1:].replace('\\', '/') imagePath = self.importPath[i+1:].replace('\\', '/')
self.fileNames[imagePath] = self.at self.fileNames[imagePath] = self.at
# Compute image size # 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) width, height = getSize(self.importPath, self.format)
if width != None: if width != None:
size = ' %s:width="%fcm" %s:height="%fcm"' % (s, width, s, height) size = ' %s:width="%fcm" %s:height="%fcm"' % (s, width, s, height)

View file

@ -259,12 +259,20 @@ class Renderer:
imageFormats = ('png', 'jpeg', 'jpg', 'gif') imageFormats = ('png', 'jpeg', 'jpg', 'gif')
ooFormats = ('odt',) ooFormats = ('odt',)
def importDocument(self, content=None, at=None, format=None, 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 '''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 the document. If p_at is None, the content of the document is
supposed to be in binary format in p_content. The document 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_format may be: odt or any format in imageFormats.
p_wrapInPara are only relevant for images.'''
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 ns = self.currentParser.env.namespaces
importer = None importer = None
# Is there someting to import? # Is there someting to import?
@ -292,9 +300,8 @@ class Renderer:
else: else:
raise PodError(DOC_WRONG_FORMAT % format) raise PodError(DOC_WRONG_FORMAT % format)
imp = importer(content, at, format, self.tempFolder, ns, self.fileNames) imp = importer(content, at, format, self.tempFolder, ns, self.fileNames)
if isImage: # Initialise image-specific parameters
imp.setAnchor(anchor) if isImage: imp.setImageInfo(anchor, wrapInPara, size)
imp.wrapInPara = wrapInPara
res = imp.run() res = imp.run()
return res return res