From fb4882005671862d1f3c27ae614a9000ac5bb102 Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Tue, 29 Nov 2011 03:33:32 +0000 Subject: [PATCH] 5386: libhtmlbackend.py crashes if a dir-name file preexists svn: r18531 --- src/plugins/docgen/PdfDoc.py | 9 ++++++++- src/plugins/lib/libhtmlbackend.py | 21 +++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/plugins/docgen/PdfDoc.py b/src/plugins/docgen/PdfDoc.py index ffb4ce054..97dc99416 100644 --- a/src/plugins/docgen/PdfDoc.py +++ b/src/plugins/docgen/PdfDoc.py @@ -38,6 +38,7 @@ import sys # #------------------------------------------------------------------------ import libcairodoc +import Errors #------------------------------------------------------------------------ # @@ -86,7 +87,13 @@ class PdfDoc(libcairodoc.CairoDoc): # create cairo context and pango layout filename = self._backend.filename.encode(sys.getfilesystemencoding()) - surface = cairo.PDFSurface(filename, paper_width, paper_height) + try: + surface = cairo.PDFSurface(filename, paper_width, paper_height) + except IOError,msg: + errmsg = "%s\n%s" % (_("Could not create %s") % filename, msg) + raise Errors.ReportError(errmsg) + except: + raise Errors.ReportError(_("Could not create %s") % filename) surface.set_fallback_resolution(300, 300) cr = pangocairo.CairoContext(cairo.Context(surface)) diff --git a/src/plugins/lib/libhtmlbackend.py b/src/plugins/lib/libhtmlbackend.py index 7644d0bcd..08d1b777a 100644 --- a/src/plugins/lib/libhtmlbackend.py +++ b/src/plugins/lib/libhtmlbackend.py @@ -45,6 +45,7 @@ import os.path from gen.plug.docbackend import DocBackend from libhtml import Html from Utils import xml_lang +import Errors #------------------------------------------------------------------------ @@ -242,9 +243,25 @@ class HtmlBackend(DocBackend): overwrite method, htmlbackend creates a html object that is written on close """ - DocBackend.open(self) + try: + DocBackend.open(self) + except IOError,msg: + errmsg = "%s\n%s" % (_("Could not create %s") % + self._filename, msg) + raise Errors.ReportError(errmsg) + except: + raise Errors.ReportError(_("Could not create %s") % + self._filename) if not os.path.isdir(self.datadirfull()): - os.mkdir(self.datadirfull()) + try: + os.mkdir(self.datadirfull()) + except IOError,msg: + errmsg = "%s\n%s" % (_("Could not create %s") % + self.datadirfull(), msg) + raise Errors.ReportError(errmsg) + except: + raise Errors.ReportError(_("Could not create %s") % + self.datadirfull()) self.html_page, self.html_header, self.html_body = Html.page( lang=xml_lang(), title=self.title)