Add Python3 compability to scripting/build_tools/extract_docstrings.py

Fixes: lp:1815737
* https://bugs.launchpad.net/kicad/+bug/1815737
This commit is contained in:
Thomas Pointhuber 2019-02-13 17:48:04 +01:00 committed by Seth Hillbrand
parent b6027e0815
commit 310e3f5eb9
1 changed files with 11 additions and 11 deletions

View File

@ -23,12 +23,12 @@ output_directory is the directory where output will be written
# Author: Prabhu Ramachandran # Author: Prabhu Ramachandran
# License: BSD style # License: BSD style
from __future__ import print_function
from xml.dom import minidom from xml.dom import minidom
import re import re
import textwrap import textwrap
import sys import sys
import types
import os.path import os.path
@ -130,7 +130,7 @@ class Doxy2SWIG:
def add_text(self, value): def add_text(self, value):
"""Adds text corresponding to `value` into `self.pieces`.""" """Adds text corresponding to `value` into `self.pieces`."""
if type(value) in (types.ListType, types.TupleType): if type(value) in (list, tuple):
self.pieces.extend(value) self.pieces.extend(value)
else: else:
self.pieces.append(value) self.pieces.append(value)
@ -190,13 +190,13 @@ class Doxy2SWIG:
kind = node.attributes['kind'].value kind = node.attributes['kind'].value
if kind in ('class', 'struct'): if kind in ('class', 'struct'):
prot = node.attributes['prot'].value prot = node.attributes['prot'].value
if prot <> 'public': if prot != 'public':
return return
names = ('compoundname', 'briefdescription', names = ('compoundname', 'briefdescription',
'detaileddescription', 'includes') 'detaileddescription', 'includes')
first = self.get_specific_nodes(node, names) first = self.get_specific_nodes(node, names)
for n in names: for n in names:
if first.has_key(n): if n in first:
self.parse(first[n]) self.parse(first[n])
self.add_text(['";','\n']) self.add_text(['";','\n'])
for n in node.childNodes: for n in node.childNodes:
@ -315,7 +315,7 @@ class Doxy2SWIG:
fname = refid + '.xml' fname = refid + '.xml'
if not os.path.exists(fname): if not os.path.exists(fname):
fname = os.path.join(self.my_dir, fname) fname = os.path.join(self.my_dir, fname)
print "parsing file: %s"%fname print("parsing file: %s" % fname)
p = Doxy2SWIG(fname) p = Doxy2SWIG(fname)
p.generate() p.generate()
self.pieces.extend(self.clean_pieces(p.pieces)) self.pieces.extend(self.clean_pieces(p.pieces))
@ -376,7 +376,7 @@ def main(input_py, input_xml, output_dir):
classes = get_python_classes(input_py) classes = get_python_classes(input_py)
with file("%s/docstrings.i"%output_dir,'w') as f_index: with open("%s/docstrings.i"%output_dir,'w') as f_index:
for classname in classes: for classname in classes:
@ -385,21 +385,21 @@ def main(input_py, input_xml, output_dir):
swig_file = "%s/%s.i"%(output_dir,classname.lower()) swig_file = "%s/%s.i"%(output_dir,classname.lower())
if os.path.isfile(class_file): if os.path.isfile(class_file):
print "processing:",class_file," ->",swig_file print("processing:", class_file, " ->", swig_file)
p = Doxy2SWIG(class_file) p = Doxy2SWIG(class_file)
p.generate() p.generate()
p.write(swig_file) p.write(swig_file)
f_index.write('%%include "%s.i"\n'% classname.lower()) f_index.write('%%include "%s.i"\n'% classname.lower())
#else: #else:
# print "ignoring class %s, as %s does not exist" %(classname,class_file) # print("ignoring class %s, as %s does not exist" % (classname,class_file))
if __name__ == '__main__': if __name__ == '__main__':
print sys.argv print(sys.argv)
if len(sys.argv) != 4: if len(sys.argv) != 4:
print __doc__ print(__doc__)
sys.exit(1) sys.exit(1)
main(sys.argv[1], sys.argv[2],sys.argv[3]) main(sys.argv[1], sys.argv[2], sys.argv[3])