Convert a C program to valid XML to be included in docbook
"""
+from __future__ import print_function, unicode_literals
+
import sys
import os
from xml.sax import saxutils
content = open(source, "r").read()
# print header
- print '<?xml version="1.0"?>'
- print '<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">'
- print
- print '<programlisting>'
+ print ('<?xml version="1.0"?>')
+ print ('<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">')
+ print ()
+ print ('<programlisting>')
# print content
- print saxutils.escape(content).encode('UTF-8')
- print '</programlisting>'
+ print (saxutils.escape(content))
+ print ('</programlisting>')
main()
parse, merge and write gstdoc-scanobj files
"""
+from __future__ import print_function, unicode_literals
+
import sys
import os
return "<Object %s>" % self.name
def add_signal(self, signal, overwrite=True):
- if not overwrite and self._signals.has_key(signal.name):
- raise IndexError, "signal %s already in %r" % (signal.name, self)
+ if not overwrite and signal.name in self._signals:
+ raise IndexError("signal %s already in %r" % (signal.name, self))
self._signals[signal.name] = signal
def add_arg(self, arg, overwrite=True):
- if not overwrite and self._args.has_key(arg.name):
- raise IndexError, "arg %s already in %r" % (arg.name, self)
+ if not overwrite and arg.name in self._args:
+ raise IndexError("arg %s already in %r" % (arg.name, self))
self._args[arg.name] = arg
class Docable:
lines = open(filename).readlines()
self.load_data("".join(lines))
except IOError:
- print "WARNING - could not read from %s" % filename
+ print ("WARNING - could not read from %s" % filename)
def save_file(self, filename, backup=False):
"""
lines = open(filename).readlines()
olddata = "".join(lines)
except IOError:
- print "WARNING - could not read from %s" % filename
+ print ("WARNING - could not read from %s" % filename)
newdata = self.get_data()
if olddata and olddata == newdata:
return
o = nmatch.group('object')
debug("Found object", o)
debug("Found signal", nmatch.group('signal'))
- if not self._objects.has_key(o):
+ if o not in self._objects:
object = Object(o)
self._objects[o] = object
o = nmatch.group('object')
debug("Found object", o)
debug("Found arg", nmatch.group('arg'))
- if not self._objects.has_key(o):
+ if o not in self._objects:
object = Object(o)
self._objects[o] = object
arg = Arg(**dict)
self._objects[o].add_arg(arg)
else:
- print "ERROR: could not match arg from block %s" % block
+ print ("ERROR: could not match arg from block %s" % block)
def get_data(self):
lines = []