# HG changeset patch # User Paul Boddie # Date 1554818639 -7200 # Node ID e133bda9c11835ab7205df6e2a14a355863722d5 # Parent 37470621404825f47b84e616be7b5e83cb646a78 Introduced a general processing error that can be handled in moinconvert. This permits more graceful handling of Graphviz errors. diff -r 374706214048 -r e133bda9c118 moinconvert --- a/moinconvert Fri Mar 15 18:37:04 2019 +0100 +++ b/moinconvert Tue Apr 09 16:03:59 2019 +0200 @@ -19,7 +19,8 @@ this program. If not, see . """ -from moinformat import make_parser, make_serialiser, Metadata, parse, serialise +from moinformat import errors, make_parser, make_serialiser, Metadata, parse, \ + serialise from os.path import split import sys @@ -379,6 +380,9 @@ """ if __name__ == "__main__": - main() + try: + main() + except errors.ProcessingError, exc: + print str(exc) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 374706214048 -r e133bda9c118 moinformat/__init__.py --- a/moinformat/__init__.py Fri Mar 15 18:37:04 2019 +0100 +++ b/moinformat/__init__.py Tue Apr 09 16:03:59 2019 +0200 @@ -3,7 +3,7 @@ """ Moin wiki format tools. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -26,5 +26,6 @@ from moinformat.parsers import get_parser, make_parser, parse from moinformat.serialisers import get_serialiser, make_serialiser, serialise from moinformat.themes import make_theme +import moinformat.errors as errors # vim: tabstop=4 expandtab shiftwidth=4 diff -r 374706214048 -r e133bda9c118 moinformat/errors.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/moinformat/errors.py Tue Apr 09 16:03:59 2019 +0200 @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +""" +Moin wiki processing errors. + +Copyright (C) 2019 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class ProcessingError(Exception): + + "A generic processing error." + + def __init__(self, errors): + self.errors = errors + + def __repr__(self): + return "%s(%r)" % (self.__class__.__name__, self.errors) + + def __str__(self): + return "Error: %s\nMessage: %s\n" % (self.__class__.__name__, self.errors) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 374706214048 -r e133bda9c118 moinformat/serialisers/html/graphviz.py --- a/moinformat/serialisers/html/graphviz.py Fri Mar 15 18:37:04 2019 +0100 +++ b/moinformat/serialisers/html/graphviz.py Tue Apr 09 16:03:59 2019 +0200 @@ -20,7 +20,7 @@ """ from moinformat.serialisers.common import Serialiser, escape_attr, escape_text -from moinformat.utils.graphviz import Graphviz, GraphvizError, IMAGE_FORMATS, \ +from moinformat.utils.graphviz import Graphviz, IMAGE_FORMATS, \ get_output_identifier # Utility functions. diff -r 374706214048 -r e133bda9c118 moinformat/utils/graphviz.py --- a/moinformat/utils/graphviz.py Fri Mar 15 18:37:04 2019 +0100 +++ b/moinformat/utils/graphviz.py Tue Apr 09 16:03:59 2019 +0200 @@ -3,7 +3,7 @@ """ Graphviz utilities. -Copyright (C) 2018 Paul Boddie +Copyright (C) 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -19,6 +19,7 @@ this program. If not, see . """ +from moinformat.errors import ProcessingError from os.path import exists, join from StringIO import StringIO from subprocess import Popen, PIPE @@ -184,12 +185,11 @@ # Classes for interacting with Graphviz. -class GraphvizError(Exception): +class GraphvizError(ProcessingError): "An error produced when using Graphviz." - def __init__(self, errors): - self.errors = errors + pass class Graphviz: