1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/moinformat/imports.py Tue Dec 12 21:02:01 2017 +0100
1.3 @@ -0,0 +1,47 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Import utilities.
1.8 +
1.9 +Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 +from os.path import isdir, join, splitext
1.26 +from os import listdir
1.27 +from importlib import import_module
1.28 +
1.29 +def get_extensions(dirname, modname, stores, reserved):
1.30 +
1.31 + "Import extensions inside 'dirname'."
1.32 +
1.33 + for filename in listdir(dirname):
1.34 + pathname = join(dirname, filename)
1.35 +
1.36 + # Descend into directories.
1.37 +
1.38 + if isdir(pathname):
1.39 + get_extensions(pathname, "%s.%s" % (modname, filename),
1.40 + stores, reserved)
1.41 + continue
1.42 +
1.43 + # Identify modules and import them.
1.44 +
1.45 + leafname, ext = splitext(filename)
1.46 +
1.47 + if ext == ".py" and leafname not in reserved:
1.48 + stores[leafname] = import_module("%s.%s" % (modname, leafname))
1.49 +
1.50 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/moinformat/serialisers/common.py Tue Dec 12 18:17:08 2017 +0100
2.2 +++ b/moinformat/serialisers/common.py Tue Dec 12 21:02:01 2017 +0100
2.3 @@ -25,6 +25,13 @@
2.4
2.5 def __init__(self, out):
2.6 self.out = out
2.7 + self.init()
2.8 +
2.9 + def init(self):
2.10 +
2.11 + "Initialisation method to be overridden by subclasses."
2.12 +
2.13 + pass
2.14
2.15 def escape_attr(s):
2.16
3.1 --- a/moinformat/serialisers/html.py Tue Dec 12 18:17:08 2017 +0100
3.2 +++ b/moinformat/serialisers/html.py Tue Dec 12 21:02:01 2017 +0100
3.3 @@ -162,4 +162,6 @@
3.4 def text(self, s):
3.5 self.out(escape_text(s))
3.6
3.7 +serialiser = HTMLSerialiser
3.8 +
3.9 # vim: tabstop=4 expandtab shiftwidth=4
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/moinformat/serialisers/manifest.py Tue Dec 12 21:02:01 2017 +0100
4.3 @@ -0,0 +1,44 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +"""
4.7 +Moin wiki serialiser manifest.
4.8 +
4.9 +Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
4.10 +
4.11 +This program is free software; you can redistribute it and/or modify it under
4.12 +the terms of the GNU General Public License as published by the Free Software
4.13 +Foundation; either version 3 of the License, or (at your option) any later
4.14 +version.
4.15 +
4.16 +This program is distributed in the hope that it will be useful, but WITHOUT
4.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
4.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
4.19 +details.
4.20 +
4.21 +You should have received a copy of the GNU General Public License along with
4.22 +this program. If not, see <http://www.gnu.org/licenses/>.
4.23 +"""
4.24 +
4.25 +from moinformat.imports import get_extensions
4.26 +from os.path import split
4.27 +
4.28 +reserved = ["__init__", "common", "manifest"]
4.29 +
4.30 +# Obtain details of this module's package.
4.31 +
4.32 +dirname = split(__file__)[0]
4.33 +package = __name__.rsplit(".", 1)[0]
4.34 +
4.35 +# Define an attribute mapping names to modules.
4.36 +
4.37 +modules = {}
4.38 +get_extensions(dirname, package, modules, reserved)
4.39 +
4.40 +# Obtain all serialisers.
4.41 +
4.42 +serialisers = {}
4.43 +
4.44 +for module_name, module in modules.items():
4.45 + serialisers[module_name] = module.serialiser
4.46 +
4.47 +# vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/moinformat/serialisers/moin.py Tue Dec 12 18:17:08 2017 +0100
5.2 +++ b/moinformat/serialisers/moin.py Tue Dec 12 21:02:01 2017 +0100
5.3 @@ -163,4 +163,6 @@
5.4 def text(self, s):
5.5 self.out(s)
5.6
5.7 +serialiser = MoinSerialiser
5.8 +
5.9 # vim: tabstop=4 expandtab shiftwidth=4