3 # Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 from datetime import date
21 import xml.dom.minidom
23 from build.nroff import *
29 %(argv0)s: XML to nroff converter
30 Converts the XML format supplied as input into an nroff-formatted manpage.
31 usage: %(argv0)s [OPTIONS] INPUT.XML
32 where INPUT.XML is a manpage in an OVS-specific XML format.
34 The following options are also available:
35 --version=VERSION use VERSION to display on document footer
36 -h, --help display this help message\
37 """ % {'argv0': argv0}
40 def manpage_to_nroff(xml_file, version=None):
41 doc = xml.dom.minidom.parse(xml_file).documentElement
42 d = date.fromtimestamp(os.stat(xml_file).st_mtime)
46 program = doc.attributes['program'].nodeValue
47 title = doc.attributes['title'].nodeValue
48 section = doc.attributes['section'].nodeValue
50 # Putting '\" p as the first line tells "man" that the manpage
51 # needs to be preprocessed by "pic".
54 .TH "%s" %s "%s" "Open vSwitch %s" "Open vSwitch Manual"
55 .fp 5 L CR \\" Make fixed-width font available as \\fL.
67 ''' % (textToNroff(program), textToNroff(section), textToNroff(title), textToNroff(version))
69 s += blockXmlToNroff(doc.childNodes) + "\n"
75 %(argv0)s: converts XML in a somewhat HTML-like format to nroff
76 usage: %(argv0)s [OPTIONS] XML
77 where XML is documentation in a somewhat HTML-like XML format.
78 The manpage, in nroff "man" format, is output on stdout.
80 The following options are also available:
81 --version=VERSION use VERSION to display on document footer
82 -h, --help display this help message\
83 """ % {'argv0': argv0}
86 if __name__ == "__main__":
88 options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
90 except getopt.GetoptError, geo:
91 sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
97 for key, value in options:
98 if key == '--version':
100 elif key in ['-h', '--help']:
106 sys.stderr.write("%s: exactly 1 non-option arguments required "
107 "(use --help for help)\n" % argv0)
111 s = manpage_to_nroff(args[0], version)
112 except error.Error, e:
113 sys.stderr.write("%s: %s\n" % (argv0, e.msg))
115 for line in s.splitlines():