Skip to content

Commit

Permalink
nroff: Fix style of names.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Justin Pettit <[email protected]>
  • Loading branch information
blp committed Jul 7, 2015
1 parent 44648b0 commit 4d9d1d9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 42 deletions.
5 changes: 3 additions & 2 deletions build-aux/xml2nroff
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def manpage_to_nroff(xml_file, subst, version=None):
. I "\\$1"
. RE
..
''' % (textToNroff(program), textToNroff(section), textToNroff(title), textToNroff(version))
''' % (text_to_nroff(program), text_to_nroff(section),
text_to_nroff(title), text_to_nroff(version))

s += blockXmlToNroff(doc.childNodes) + "\n"
s += block_xml_to_nroff(doc.childNodes) + "\n"

return s

Expand Down
24 changes: 12 additions & 12 deletions ovsdb/ovsdb-doc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ from build.nroff import *
argv0 = sys.argv[0]

def typeAndConstraintsToNroff(column):
type = column.type.toEnglish(escapeNroffLiteral)
constraints = column.type.constraintsToEnglish(escapeNroffLiteral,
textToNroff)
type = column.type.toEnglish(escape_nroff_literal)
constraints = column.type.constraintsToEnglish(escape_nroff_literal,
text_to_nroff)
if constraints:
type += ", " + constraints
if column.unique:
Expand All @@ -53,7 +53,7 @@ def columnGroupToNroff(table, groupXml, documented_columns):
introNodes += [node]

summary = []
intro = blockXmlToNroff(introNodes)
intro = block_xml_to_nroff(introNodes)
body = ''
for node in columnNodes:
if node.tagName == 'column':
Expand All @@ -76,7 +76,7 @@ def columnGroupToNroff(table, groupXml, documented_columns):

if column.type.value:
typeNroff = "optional %s" % column.type.value.toEnglish(
escapeNroffLiteral)
escape_nroff_literal)
if (column.type.value.type == ovs.db.types.StringType and
type_.type == ovs.db.types.BooleanType):
# This is a little more explicit and helpful than
Expand All @@ -90,8 +90,8 @@ def columnGroupToNroff(table, groupXml, documented_columns):
else:
typeNroff += ", containing a %s" % type_english
constraints = (
type_.constraintsToEnglish(escapeNroffLiteral,
textToNroff))
type_.constraintsToEnglish(escape_nroff_literal,
text_to_nroff))
if constraints:
typeNroff += ", %s" % constraints
else:
Expand All @@ -102,14 +102,14 @@ def columnGroupToNroff(table, groupXml, documented_columns):
if not column.mutable:
typeNroff = "immutable %s" % typeNroff
body += '.IP "\\fB%s\\fR: %s"\n' % (nameNroff, typeNroff)
body += blockXmlToNroff(node.childNodes, '.IP') + "\n"
body += block_xml_to_nroff(node.childNodes, '.IP') + "\n"
summary += [('column', nameNroff, typeNroff)]
elif node.tagName == 'group':
title = node.attributes["title"].nodeValue
subSummary, subIntro, subBody = columnGroupToNroff(
table, node, documented_columns)
summary += [('group', title, subSummary)]
body += '.ST "%s:"\n' % textToNroff(title)
body += '.ST "%s:"\n' % text_to_nroff(title)
body += subIntro + subBody
else:
raise error.Error("unknown element %s in <table>" % node.tagName)
Expand Down Expand Up @@ -186,7 +186,7 @@ def docsToNroff(schemaFile, xmlFile, erFile, version=None):
.SH NAME
%s \- %s database schema
.PP
''' % (manpage, schema.version, version, textToNroff(manpage), schema.name)
''' % (manpage, schema.version, version, text_to_nroff(manpage), schema.name)

tables = ""
introNodes = []
Expand All @@ -212,7 +212,7 @@ def docsToNroff(schemaFile, xmlFile, erFile, version=None):
for table in undocumented_tables:
raise error.Error("undocumented table %s" % table)

s += blockXmlToNroff(introNodes) + "\n"
s += block_xml_to_nroff(introNodes) + "\n"

s += r"""
.SH "TABLE SUMMARY"
Expand All @@ -228,7 +228,7 @@ Purpose
.TQ 1in
\fB%s\fR
%s
""" % (name, textToNroff(title))
""" % (name, text_to_nroff(title))

if erFile:
s += """
Expand Down
56 changes: 28 additions & 28 deletions python/build/nroff.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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)

Expand Down Expand Up @@ -55,20 +55,20 @@ def escape(match):
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'
Expand All @@ -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)
Expand All @@ -101,72 +101,72 @@ 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']:
if s != "":
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':
if s != "":
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"):
s += "\n"
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':
Expand All @@ -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'):
Expand Down

0 comments on commit 4d9d1d9

Please sign in to comment.