2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

nroff: Fix style of names.

The recommended Google Python style is multi_word_names, not
multiWordNames.

There are lots of other places where the style could be improved.
I started here because I was working in this code anyway and because
this code is only used at build time and not installed, so that it
can't break any third-party code.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Justin Pettit <jpettit@nicira.com>
This commit is contained in:
Ben Pfaff
2015-07-06 21:05:03 -07:00
parent 44648b0f08
commit 4d9d1d9e72
3 changed files with 43 additions and 42 deletions

View File

@@ -16,7 +16,7 @@ import re
from ovs.db import error
def textToNroff(s, font=r'\fR'):
def text_to_nroff(s, font=r'\fR'):
def escape(match):
c = match.group(0)
@@ -55,20 +55,20 @@ def textToNroff(s, font=r'\fR'):
s = re.sub('(-[0-9]|--|[-"\'\\\\.])', escape, s)
return s
def escapeNroffLiteral(s, font=r'\fB'):
return font + r'%s\fR' % textToNroff(s, font)
def escape_nroff_literal(s, font=r'\fB'):
return font + r'%s\fR' % text_to_nroff(s, font)
def inlineXmlToNroff(node, font, to_upper=False):
def inline_xml_to_nroff(node, font, to_upper=False):
if node.nodeType == node.TEXT_NODE:
if to_upper:
return textToNroff(node.data.upper(), font)
return text_to_nroff(node.data.upper(), font)
else:
return textToNroff(node.data, font)
return text_to_nroff(node.data, font)
elif node.nodeType == node.ELEMENT_NODE:
if node.tagName in ['code', 'em', 'option', 'env']:
s = r'\fB'
for child in node.childNodes:
s += inlineXmlToNroff(child, r'\fB')
s += inline_xml_to_nroff(child, r'\fB')
return s + font
elif node.tagName == 'ref':
s = r'\fB'
@@ -88,7 +88,7 @@ def inlineXmlToNroff(node, font, to_upper=False):
elif node.tagName == 'var' or node.tagName == 'dfn':
s = r'\fI'
for child in node.childNodes:
s += inlineXmlToNroff(child, r'\fI')
s += inline_xml_to_nroff(child, r'\fI')
return s + font
else:
raise error.Error("element <%s> unknown or invalid here" % node.tagName)
@@ -101,15 +101,15 @@ def pre_to_nroff(nodes, para, font):
if node.nodeType != node.TEXT_NODE:
fatal("<pre> element may only have text children")
for line in node.data.split('\n'):
s += escapeNroffLiteral(line, font) + '\n.br\n'
s += escape_nroff_literal(line, font) + '\n.br\n'
s += '.fi\n'
return s
def blockXmlToNroff(nodes, para='.PP'):
def block_xml_to_nroff(nodes, para='.PP'):
s = ''
for node in nodes:
if node.nodeType == node.TEXT_NODE:
s += textToNroff(node.data)
s += text_to_nroff(node.data)
s = s.lstrip()
elif node.nodeType == node.ELEMENT_NODE:
if node.tagName in ['ul', 'ol']:
@@ -117,17 +117,17 @@ def blockXmlToNroff(nodes, para='.PP'):
s += "\n"
s += ".RS\n"
i = 0
for liNode in node.childNodes:
if (liNode.nodeType == node.ELEMENT_NODE
and liNode.tagName == 'li'):
for li_node in node.childNodes:
if (li_node.nodeType == node.ELEMENT_NODE
and li_node.tagName == 'li'):
i += 1
if node.tagName == 'ul':
s += ".IP \\(bu\n"
else:
s += ".IP %d. .25in\n" % i
s += blockXmlToNroff(liNode.childNodes, ".IP")
elif (liNode.nodeType != node.TEXT_NODE
or not liNode.data.isspace()):
s += block_xml_to_nroff(li_node.childNodes, ".IP")
elif (li_node.nodeType != node.TEXT_NODE
or not li_node.data.isspace()):
raise error.Error("<%s> element may only have <li> children" % node.tagName)
s += ".RE\n"
elif node.tagName == 'dl':
@@ -135,30 +135,30 @@ def blockXmlToNroff(nodes, para='.PP'):
s += "\n"
s += ".RS\n"
prev = "dd"
for liNode in node.childNodes:
if (liNode.nodeType == node.ELEMENT_NODE
and liNode.tagName == 'dt'):
for li_node in node.childNodes:
if (li_node.nodeType == node.ELEMENT_NODE
and li_node.tagName == 'dt'):
if prev == 'dd':
s += '.TP\n'
else:
s += '.TQ .5in\n'
prev = 'dt'
elif (liNode.nodeType == node.ELEMENT_NODE
and liNode.tagName == 'dd'):
elif (li_node.nodeType == node.ELEMENT_NODE
and li_node.tagName == 'dd'):
if prev == 'dd':
s += '.IP\n'
prev = 'dd'
elif (liNode.nodeType != node.TEXT_NODE
or not liNode.data.isspace()):
elif (li_node.nodeType != node.TEXT_NODE
or not li_node.data.isspace()):
raise error.Error("<dl> element may only have <dt> and <dd> children")
s += blockXmlToNroff(liNode.childNodes, ".IP")
s += block_xml_to_nroff(li_node.childNodes, ".IP")
s += ".RE\n"
elif node.tagName == 'p':
if s != "":
if not s.endswith("\n"):
s += "\n"
s += para + "\n"
s += blockXmlToNroff(node.childNodes, para)
s += block_xml_to_nroff(node.childNodes, para)
elif node.tagName in ('h1', 'h2', 'h3'):
if s != "":
if not s.endswith("\n"):
@@ -166,7 +166,7 @@ def blockXmlToNroff(nodes, para='.PP'):
nroffTag = {'h1': 'SH', 'h2': 'SS', 'h3': 'ST'}[node.tagName]
s += '.%s "' % nroffTag
for child_node in node.childNodes:
s += inlineXmlToNroff(child_node, r'\fR',
s += inline_xml_to_nroff(child_node, r'\fR',
to_upper=(nroffTag == 'SH'))
s += '"\n'
elif node.tagName == 'pre':
@@ -177,7 +177,7 @@ def blockXmlToNroff(nodes, para='.PP'):
font = r'\fB'
s += pre_to_nroff(node.childNodes, para, font)
else:
s += inlineXmlToNroff(node, r'\fR')
s += inline_xml_to_nroff(node, r'\fR')
else:
raise error.Error("unknown node %s in block xml" % node)
if s != "" and not s.endswith('\n'):