Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak tools for RosettaQM #109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions doc_tools/xsd_to_doc_fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def get_annotation(node, name1, name2=None):
if node.tag != '{http://www.w3.org/2001/XMLSchema}annotation': return ''
if len(node) < 1 or node[0].tag != '{http://www.w3.org/2001/XMLSchema}documentation':
if name2 is not None:
print "Error parsing annotation for entry", name1, "in", name2
print( "Error parsing annotation for entry", name1, "in", name2 )
else:
print "Error parsing annotation for entry", name1
print( "Error parsing annotation for entry", name1 )
return ''
return node[0].text

Expand All @@ -77,16 +77,16 @@ def parse_subelement( subelem, parentname ):
doc_lines = []

if 'name' not in subelem.attrib:
print 'Error: missing name when parsing subtag for ', parentname
print( 'Error: missing name when parsing subtag for ', parentname )
name = subelem.attrib['name']

if len(subelem) >=2:
print "Error: can't parse type for", name, "in", parentname
print( "Error: can't parse type for", name, "in", parentname )
return None

if len( subelem ) == 0:
if 'type' not in subelem.attrib:
print "Error: can't parse type entry for", name, "in", parentname
print( "Error: can't parse type entry for", name, "in", parentname )
return None
typename = subelem.attrib['type']
if typename in COMMON_TYPES:
Expand All @@ -98,14 +98,14 @@ def parse_subelement( subelem, parentname ):

# Parse complex type in ALL_ENTRIES
if typename not in ALL_ENTRIES:
print "Error: can't parse type of ", typename, " for", name, "in", parentname
print( "Error: can't parse type of ", typename, " for", name, "in", parentname )
return None
ctype = ALL_ENTRIES[typename]
elif len( subelem ) == 1:
ctype = subelem[0]

if ctype.tag != '{http://www.w3.org/2001/XMLSchema}complexType':
print "Error getting type for", name, "in", parentname
print( "Error getting type for", name, "in", parentname )
return None
sct = parse_complextype( name, parentname, ctype )
if sct is None:
Expand All @@ -125,7 +125,7 @@ def parse_subelement( subelem, parentname ):
def parse_multi( node, parentname ):
nodetype = node.tag.split('}')[-1]

#print "PARSING", nodetype.upper(), " for ", parentname
#print( "PARSING", nodetype.upper(), " for ", parentname )

main_doc = ''
tag_lines = []
Expand Down Expand Up @@ -164,7 +164,7 @@ def parse_multi( node, parentname ):
tag_lines.extend( subtag_lines )
doc_lines.extend( subdoc_lines )
else:
print "Error parsing subtag of", nodetype, "for", parentname, '::', subelem.tag
print( "Error parsing subtag of", nodetype, "for", parentname, '::', subelem.tag )
continue


Expand All @@ -178,10 +178,10 @@ def parse_multi( node, parentname ):
parse_all = parse_multi

def parse_group( node, parentname ):
#print "PARSING GROUP for ", parentname
#print( "PARSING GROUP for ", parentname )

if 'ref' not in node.attrib:
print "Error parsing group element for ", parentname
print( "Error parsing group element for ", parentname )
return None

ref = node.attrib['ref']
Expand All @@ -192,16 +192,16 @@ def parse_group( node, parentname ):
return '', '', [ tagline, ], ['',docline,]

if ref not in ALL_ENTRIES:
print "Error: can't parse group ", typename, " for in", parentname
print( "Error: can't parse group ", typename, " for in", parentname )
return None
ctype = ALL_ENTRIES[ref]
if ctype.tag != '{http://www.w3.org/2001/XMLSchema}group' or len(ctype) != 1:
print "Error: issue parsing group", ref, 'in', parentname
print( "Error: issue parsing group", ref, 'in', parentname )
return None
ctype = ctype[0]
if ctype.tag != '{http://www.w3.org/2001/XMLSchema}choice':
print 'Error: issue parsing group', ref, 'in', parentname
print '... putting group', ref, 'in-line for', parentname
print( 'Error: issue parsing group', ref, 'in', parentname )
print( '... putting group', ref, 'in-line for', parentname )
sc = parse_choice( ctype, parentname )
if sc is None:
return None
Expand All @@ -224,9 +224,9 @@ def parse_complextype( name, parentname, node ):
elif gc.tag == '{http://www.w3.org/2001/XMLSchema}attribute':
if 'name' not in gc.attrib:
if parentname is not None:
print "Error parsing attribute for entry", name, 'on', parentname
print( "Error parsing attribute for entry", name, 'on', parentname )
else:
print "Error parsing attribute for entry", name
print( "Error parsing attribute for entry", name )
continue
attrib = dict( gc.attrib )
docstring = ''
Expand Down Expand Up @@ -254,7 +254,7 @@ def parse_complextype( name, parentname, node ):
if sa is not None:
subtags.append( sa )
else:
print "Warning: skipping entry of type '"+ gc.tag+ "' in", name
print( "Warning: skipping entry of type '"+ gc.tag+ "' in", name )
pass

# Format the tags:
Expand Down Expand Up @@ -314,7 +314,7 @@ def process( name, node, outfilename ):
subtags = []

if node.tag != '{http://www.w3.org/2001/XMLSchema}complexType':
print "Error: expected complex type."
print( "Error: expected complex type." )
return

_, main_doc, tag_lines, doc_lines = parse_complextype( name, None, node )
Expand All @@ -341,13 +341,13 @@ def main( xsdfile, outdir ):
root = xsd.getroot()

if root.tag != '{http://www.w3.org/2001/XMLSchema}schema':
print "ERROR: Malformed XSD schema file."
print( "ERROR: Malformed XSD schema file." )
sys.exit()

entries = {}
for child in root:
if 'name' not in child.attrib:
print "Error in reading", child.tag
print( "Error in reading", child.tag )
continue

entries[ child.attrib['name'] ] = child
Expand All @@ -359,28 +359,28 @@ def main( xsdfile, outdir ):
to_process = {} # dictionary of lower-cased name:(xsd_type_name, display_name)
for section in SECTIONS:
if section not in entries:
print "ERROR: can't find section for", section, " in XSD."
print( "ERROR: can't find section for", section, " in XSD." )
continue
sec_entry = entries[ section ]
sec_choice = None
for se in sec_entry:
if se.tag != '{http://www.w3.org/2001/XMLSchema}choice':
continue
if sec_choice is not None:
print "ERROR: malformed entry for section", section
print( "ERROR: malformed entry for section", section )
continue
sec_choice = se
if sec_choice is None:
print "ERROR: malformed entry for section", section
print( "ERROR: malformed entry for section", section )
continue
for child in sec_choice:
if 'type' not in child.attrib or 'name' not in child.attrib:
print "ERROR: malformed entry in section", section
print( "ERROR: malformed entry in section", section )
continue
entry_type = child.attrib['type']
entry_name = child.attrib['name']
if entry_type not in entries:
print "ERROR: can't find definition for", entry_type
print( "ERROR: can't find definition for", entry_type )
continue
to_process.setdefault( entry_type.lower(), [] ).append( (entry_type, entry_name) )

Expand All @@ -390,7 +390,7 @@ def main( xsdfile, outdir ):
for key in to_process:
to_process[key].sort()
if len( to_process[key] ) > 1:
print "Case sensitivity conflict between: ", ' '.join( et for et, en in to_process[key] )
print( "Case sensitivity conflict between: ", ' '.join( et for et, en in to_process[key] ) )
for ii, (entry_type, entry_name) in enumerate( to_process[key] ):
if ii == 0:
outname = outdir + '/' + entry_type + '.md'
Expand All @@ -402,10 +402,10 @@ def main( xsdfile, outdir ):
if __name__ == "__main__":

if len(sys.argv) != 3:
print
print "ERROR: Usage: ./create_rosetta_scripts_docs.py <xsd file> <directory to write docs to>"
print
print __doc__
print()
print( "ERROR: Usage: ./create_rosetta_scripts_docs.py <xsd file> <directory to write docs to>" )
print()
print( __doc__ )
sys.exit()

main(sys.argv[1], sys.argv[2])
Expand Down