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

@ -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:

View file

@ -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