From 7e9cc1e90909ffc0f000336878831faadddbf089 Mon Sep 17 00:00:00 2001 From: Thomas 'nezza-_-' Roth Date: Tue, 15 Feb 2011 14:25:37 +0100 Subject: [PATCH] Added overwriteExisting option to Renderer for overwriting the result file if it already exists. --- pod/renderer.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pod/renderer.py b/pod/renderer.py index cd28aba..54395f0 100644 --- a/pod/renderer.py +++ b/pod/renderer.py @@ -95,7 +95,7 @@ STYLES_POD_FONTS = '<@style@:font-face @style@:name="PodStarSymbol" ' \ class Renderer: def __init__(self, template, context, result, pythonWithUnoPath=None, ooPort=2002, stylesMapping={}, forceOoCall=False, - finalizeFunction=None): + finalizeFunction=None, overwriteExisting=False): '''This Python Open Document Renderer (PodRenderer) loads a document template (p_template) which is an ODT file with some elements written in Python. Based on this template and some Python objects @@ -125,7 +125,11 @@ class Renderer: you can still perform some actions on the content of the ODT file before it is zipped and potentially converted. This function must accept one arg: the absolute path to the temporary folder containing - the un-zipped content of the ODT result.''' + the un-zipped content of the ODT result. + + - If you set p_overwriteExisting to True, Renderer will overwrite the + result file. Elsewise an exception will be thrown if the result file + already exists.''' self.template = template self.templateZip = zipfile.ZipFile(template) self.result = result @@ -139,6 +143,7 @@ class Renderer: self.ooPort = ooPort self.forceOoCall = forceOoCall self.finalizeFunction = finalizeFunction + self.overwriteExisting = overwriteExisting # Retain potential files or images that will be included through # "do ... from document" statements: we will need to declare them in # META-INF/manifest.xml. @@ -287,7 +292,7 @@ class Renderer: def prepareFolders(self): # Check if I can write the result - if os.path.exists(self.result): + if not self.overwriteExisting and os.path.exists(self.result): raise PodError(RESULT_FILE_EXISTS % self.result) try: f = open(self.result, 'w')