]>
git.proxmox.com Git - mirror_ovs.git/blob - build-aux/xml2nroff
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.
19 import xml
.dom
.minidom
28 %(argv0)s: XML to nroff converter
29 Converts the XML format supplied as input into an nroff-formatted manpage.
30 usage: %(argv0)s [OPTIONS] INPUT.XML [VAR=VALUE]...
31 where INPUT.XML is a manpage in an OVS-specific XML format.
33 Each VAR, when enclosed by "@"s in the input, is replaced by its
34 corresponding VALUE, with characters &<>"' in VALUE escaped.
36 The following options are also available:
37 --version=VERSION use VERSION to display on document footer
38 -h, --help display this help message\
39 """ % {'argv0': argv0
}
43 def manpage_to_nroff(xml_file
, subst
, version
=None):
44 with
open(xml_file
) as f
:
46 for k
, v
in subst
.iteritems():
47 content
= content
.replace(k
, v
)
48 doc
= xml
.dom
.minidom
.parseString(content
).documentElement
52 program
= doc
.attributes
['program'].nodeValue
53 title
= doc
.attributes
['title'].nodeValue
54 section
= doc
.attributes
['section'].nodeValue
56 # Putting '\" p as the first line tells "man" that the manpage
57 # needs to be preprocessed by "pic".
60 .TH "%s" %s "%s" "Open vSwitch %s" "Open vSwitch Manual"
61 .fp 5 L CR \\" Make fixed-width font available as \\fL.
73 ''' % (build
.nroff
.text_to_nroff(program
), build
.nroff
.text_to_nroff(section
),
74 build
.nroff
.text_to_nroff(title
), build
.nroff
.text_to_nroff(version
))
76 s
+= build
.nroff
.block_xml_to_nroff(doc
.childNodes
) + "\n"
81 if __name__
== "__main__":
83 options
, args
= getopt
.gnu_getopt(sys
.argv
[1:], 'hV',
85 except getopt
.GetoptError
, geo
:
86 sys
.stderr
.write("%s: %s\n" % (argv0
, geo
.msg
))
92 for key
, value
in options
:
93 if key
== '--version':
95 elif key
in ['-h', '--help']:
101 sys
.stderr
.write("%s: exactly 1 non-option arguments required "
102 "(use --help for help)\n" % argv0
)
107 var
, value
= s
.split('=', 1)
108 value
= value
.replace('&', '&')
109 value
= value
.replace('<', '<')
110 value
= value
.replace('>', '>')
111 value
= value
.replace('"', '"')
112 value
= value
.replace("'", ''')
113 subst
['@%s@' % var
] = value
116 s
= manpage_to_nroff(args
[0], subst
, version
)
117 except build
.nroff
.error
.Error
, e
:
118 sys
.stderr
.write("%s: %s\n" % (argv0
, e
.msg
))
120 for line
in s
.splitlines():