1.1 --- a/convert.py Sun Nov 25 16:57:15 2018 +0100
1.2 +++ b/convert.py Sun Nov 25 21:28:12 2018 +0100
1.3 @@ -1,10 +1,51 @@
1.4 #!/usr/bin/env python
1.5
1.6 +"""
1.7 +Moin wiki format converter.
1.8 +
1.9 +Copyright (C) 2018 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 moinformat import make_parser, make_serialiser, Metadata, parse, serialise
1.26 from os.path import split
1.27 import sys
1.28
1.29 +# Long messages.
1.30 +
1.31 +message_all_with_filenames = """\
1.32 +Using --all overrides any indicated pagenames. Either --all or the filenames
1.33 +should be omitted."""
1.34 +
1.35 +message_explicit_pagenames = """\
1.36 +Explicit pagenames (indicated using --pagename) are only to be specified when
1.37 +providing filenames without an input directory (indicated using --input-dir).
1.38 +
1.39 +To indicate pagenames within an input directory, omit any --pagename flags."""
1.40 +
1.41 +
1.42 +
1.43 +# Options management.
1.44 +
1.45 def getmapping(mappings):
1.46 +
1.47 + """
1.48 + Return the given 'mappings' - a collection of key-then-value items - as a
1.49 + dictionary.
1.50 + """
1.51 +
1.52 mapping = {}
1.53 key = None
1.54
1.55 @@ -18,9 +59,22 @@
1.56 return mapping
1.57
1.58 def getvalue(values, default=None):
1.59 +
1.60 + """
1.61 + Return the first value from 'values' or 'default' if 'values' is empty or
1.62 + the first value tests as false.
1.63 + """
1.64 +
1.65 return values and values[0] or default
1.66
1.67 +
1.68 +
1.69 +# Main program.
1.70 +
1.71 def main():
1.72 +
1.73 + "Interpret program options and perform the conversion."
1.74 +
1.75 dirname, progname = split(sys.argv[0])
1.76 args = sys.argv[1:]
1.77
1.78 @@ -182,18 +236,12 @@
1.79
1.80 if input_dir:
1.81 if pagenames:
1.82 - print >>sys.stderr, """\
1.83 -Explicit pagenames (indicated using --pagename) are only to be specified when
1.84 -providing filenames without an input directory (indicated using --input-dir).
1.85 -
1.86 -To indicate pagenames within an input directory, omit any --pagename flags."""
1.87 + print >>sys.stderr, message_explicit_pagenames
1.88 sys.exit(1)
1.89
1.90 if all:
1.91 if filenames:
1.92 - print >>sys.stderr, """\
1.93 -Using --all overrides any indicated pagenames. Either --all or the filenames
1.94 -should be omitted."""
1.95 + print >>sys.stderr, message_all_with_filenames
1.96 sys.exit(1)
1.97 else:
1.98 filenames = input.all()