Fix API doc extractor to stop munging comment formatting

The python method help docs are copied across from the C
funtion comments, but in the process all line breaks and
indentation was being lost. This made the resulting text
and code examples completely unreadable. Both the API
doc extractor and the python generator were destroying
whitespace & this fixes them to preserve it exactly.

* docs/apibuild.py: Preserve all whitespace when extracting
  function comments. Print function comment inside a <![CDATA[
  section to fully preserve all whitespace. Look for the
  word 'returns' to describe return values, instead of 'return'
  to avoid getting confused with code examples including the
  C 'return' statement.
* python/generator.py: Preserve all whitespace when printing
  function help docs
* src/libvirt.c: Change any return parameter indicated by
  'return' to be 'returns', to avoid confusing the API extractor
* docs/libvirt-api.xml: Re-build for fixed descriptions
This commit is contained in:
Daniel P. Berrange 2009-09-25 13:24:40 +01:00
parent d104362d90
commit 5486abfe4e
4 changed files with 816 additions and 285 deletions

View File

@ -838,14 +838,20 @@ class CParser:
arg, name))
while len(lines) > 0 and lines[0] == '*':
del lines[0]
desc = ""
desc = None
while len(lines) > 0:
l = lines[0]
while len(l) > 0 and l[0] == '*':
l = l[1:]
l = string.strip(l)
if len(l) >= 6 and l[0:6] == "return" or l[0:6] == "Return":
try:
i = 0
# Remove all leading '*', followed by at most one ' ' character
# since we need to preserve correct identation of code examples
while i < len(l) and l[i] == '*':
i = i + 1
if i > 0:
if i < len(l) and l[i] == ' ':
i = i + 1
l = l[i:]
if len(l) >= 6 and l[0:7] == "returns" or l[0:7] == "Returns":
try:
l = string.split(l, ' ', 1)[1]
except:
l = ""
@ -859,9 +865,14 @@ class CParser:
retdesc = retdesc + " " + l
del lines[0]
else:
desc = desc + " " + l
if desc is not None:
desc = desc + "\n" + l
else:
desc = l
del lines[0]
if desc is None:
desc = ""
retdesc = string.strip(retdesc)
desc = string.strip(desc)
@ -1716,7 +1727,7 @@ class docBuilder:
try:
(args, desc) = id.info
if desc != None and desc != "":
output.write(" <info>%s</info>\n" % (escape(desc)))
output.write(" <info><![CDATA[%s]]></info>\n" % (desc))
self.indexString(name, desc)
for arg in args:
(name, desc) = arg
@ -1760,7 +1771,7 @@ class docBuilder:
try:
desc = id.extra
if desc != None and desc != "":
output.write(">\n <info>%s</info>\n" % (escape(desc)))
output.write(">\n <info><![CDATA[%s]]></info>\n" % (desc))
output.write(" </typedef>\n")
else:
output.write("/>\n")
@ -1796,7 +1807,7 @@ class docBuilder:
output.write(" <cond>%s</cond>\n"% (apstr));
try:
(ret, params, desc) = id.info
output.write(" <info>%s</info>\n" % (escape(desc)))
output.write(" <info><![CDATA[%s]]></info>\n" % (desc))
self.indexString(name, desc)
if ret[0] != None:
if ret[0] == "void":

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,7 @@ if sgmlop:
self.finish_starttag = target.start
self.finish_endtag = target.end
self.handle_data = target.data
self.handle_cdata = target.cdata
# activate parser
self.parser = sgmlop.XMLParser()
@ -78,6 +79,7 @@ class SlowParser(xmllib.XMLParser):
def __init__(self, target):
self.unknown_starttag = target.start
self.handle_data = target.data
self.handle_cdata = target.cdata
self.unknown_endtag = target.end
xmllib.XMLParser.__init__(self)
@ -108,6 +110,11 @@ class docParser:
print "data %s" % text
self._data.append(text)
def cdata(self, text):
if debug:
print "data %s" % text
self._data.append(text)
def start(self, tag, attrs):
if debug:
print "start %s, %s" % (tag, attrs)
@ -843,20 +850,14 @@ def writeDoc(name, args, indent, output):
val = string.replace(val, "NULL", "None");
output.write(indent)
output.write('"""')
while len(val) > 60:
if val[0] == " ":
val = val[1:]
continue
str = val[0:60]
i = string.rfind(str, " ");
if i < 0:
i = 60
str = val[0:i]
val = val[i:]
i = string.find(val, "\n")
while i >= 0:
str = val[0:i+1]
val = val[i+1:]
output.write(str)
output.write('\n ');
i = string.find(val, "\n")
output.write(indent)
output.write(val);
output.write(val)
output.write(' """\n')
def buildWrappers():

View File

@ -814,7 +814,7 @@ virRegisterStateDriver(virStateDriverPtr driver)
*
* Initialize all virtualization drivers.
*
* Return 0 if all succeed, -1 upon any failure.
* Returns 0 if all succeed, -1 upon any failure.
*/
int virStateInitialize(int privileged) {
int i, ret = 0;
@ -835,7 +835,7 @@ int virStateInitialize(int privileged) {
*
* Run each virtualization driver's cleanup method.
*
* Return 0 if all succeed, -1 upon any failure.
* Returns 0 if all succeed, -1 upon any failure.
*/
int virStateCleanup(void) {
int i, ret = 0;
@ -853,7 +853,7 @@ int virStateCleanup(void) {
*
* Run each virtualization driver's reload method.
*
* Return 0 if all succeed, -1 upon any failure.
* Returns 0 if all succeed, -1 upon any failure.
*/
int virStateReload(void) {
int i, ret = 0;
@ -871,7 +871,7 @@ int virStateReload(void) {
*
* Run each virtualization driver's "active" method.
*
* Return 0 if none are active, 1 if at least one is.
* Returns 0 if none are active, 1 if at least one is.
*/
int virStateActive(void) {
int i, ret = 0;
@ -7040,7 +7040,7 @@ virStoragePoolRef(virStoragePoolPtr pool)
* involve communicating with a remote server, and/or initializing
* new devices at the OS layer
*
* Return 0 if the volume list was refreshed, -1 on failure
* Returns 0 if the volume list was refreshed, -1 on failure
*/
int
virStoragePoolRefresh(virStoragePoolPtr pool,
@ -7085,7 +7085,7 @@ error:
*
* Fetch the locally unique name of the storage pool
*
* Return the name of the pool, or NULL on error
* Returns the name of the pool, or NULL on error
*/
const char*
virStoragePoolGetName(virStoragePoolPtr pool)
@ -7109,7 +7109,7 @@ virStoragePoolGetName(virStoragePoolPtr pool)
*
* Fetch the globally unique ID of the storage pool
*
* Return 0 on success, or -1 on error;
* Returns 0 on success, or -1 on error;
*/
int
virStoragePoolGetUUID(virStoragePoolPtr pool,
@ -7145,7 +7145,7 @@ error:
*
* Fetch the globally unique ID of the storage pool as a string
*
* Return 0 on success, or -1 on error;
* Returns 0 on success, or -1 on error;
*/
int
virStoragePoolGetUUIDString(virStoragePoolPtr pool,
@ -7186,7 +7186,7 @@ error:
* Get volatile information about the storage pool
* such as free space / usage summary
*
* returns 0 on success, or -1 on failure.
* Returns 0 on success, or -1 on failure.
*/
int
virStoragePoolGetInfo(virStoragePoolPtr pool,
@ -7236,7 +7236,7 @@ error:
* storage pool. This is suitable for later feeding back
* into the virStoragePoolCreateXML method.
*
* returns a XML document, or NULL on error
* Returns a XML document, or NULL on error
*/
char *
virStoragePoolGetXMLDesc(virStoragePoolPtr pool,
@ -7283,7 +7283,7 @@ error:
* Fetches the value of the autostart flag, which determines
* whether the pool is automatically started at boot time
*
* return 0 on success, -1 on failure
* Returns 0 on success, -1 on failure
*/
int
virStoragePoolGetAutostart(virStoragePoolPtr pool,
@ -7329,7 +7329,7 @@ error:
*
* Sets the autostart flag
*
* returns 0 on success, -1 on failure
* Returns 0 on success, -1 on failure
*/
int
virStoragePoolSetAutostart(virStoragePoolPtr pool,
@ -7490,7 +7490,7 @@ virStorageVolGetConnect (virStorageVolPtr vol)
* Fetch a pointer to a storage volume based on its name
* within a pool
*
* return a storage volume, or NULL if not found / error
* Returns a storage volume, or NULL if not found / error
*/
virStorageVolPtr
virStorageVolLookupByName(virStoragePoolPtr pool,
@ -7535,7 +7535,7 @@ error:
* Fetch a pointer to a storage volume based on its
* globally unique key
*
* return a storage volume, or NULL if not found / error
* Returns a storage volume, or NULL if not found / error
*/
virStorageVolPtr
virStorageVolLookupByKey(virConnectPtr conn,
@ -7578,7 +7578,7 @@ error:
* Fetch a pointer to a storage volume based on its
* locally (host) unique path
*
* return a storage volume, or NULL if not found / error
* Returns a storage volume, or NULL if not found / error
*/
virStorageVolPtr
virStorageVolLookupByPath(virConnectPtr conn,
@ -7621,7 +7621,7 @@ error:
* Fetch the storage volume name. This is unique
* within the scope of a pool
*
* return the volume name, or NULL on error
* Returns the volume name, or NULL on error
*/
const char*
virStorageVolGetName(virStorageVolPtr vol)
@ -7646,7 +7646,7 @@ virStorageVolGetName(virStorageVolPtr vol)
* unique, so the same volume will have the same
* key no matter what host it is accessed from
*
* return the volume key, or NULL on error
* Returns the volume key, or NULL on error
*/
const char*
virStorageVolGetKey(virStorageVolPtr vol)
@ -7673,7 +7673,7 @@ virStorageVolGetKey(virStorageVolPtr vol)
* on an XML description. Not all pools support
* creation of volumes
*
* return the storage volume, or NULL on error
* Returns the storage volume, or NULL on error
*/
virStorageVolPtr
virStorageVolCreateXML(virStoragePoolPtr pool,
@ -7723,7 +7723,7 @@ error:
* volume (name, perms) are passed via a typical volume
* XML description.
*
* return the storage volume, or NULL on error
* Returns the storage volume, or NULL on error
*/
virStorageVolPtr
virStorageVolCreateXMLFrom(virStoragePoolPtr pool,
@ -7777,7 +7777,7 @@ error:
*
* Delete the storage volume from the pool
*
* Return 0 on success, or -1 on error
* Returns 0 on success, or -1 on error
*/
int
virStorageVolDelete(virStorageVolPtr vol,
@ -7823,7 +7823,7 @@ error:
* Release the storage volume handle. The underlying
* storage volume continues to exist.
*
* Return 0 on success, or -1 on error
* Returns 0 on success, or -1 on error
*/
int
virStorageVolFree(virStorageVolPtr vol)
@ -7881,7 +7881,7 @@ virStorageVolRef(virStorageVolPtr vol)
* Fetches volatile information about the storage
* volume such as its current allocation
*
* Return 0 on success, or -1 on failure
* Returns 0 on success, or -1 on failure
*/
int
virStorageVolGetInfo(virStorageVolPtr vol,
@ -7930,7 +7930,7 @@ error:
* Fetch an XML document describing all aspects of
* the storage volume
*
* Return the XML document, or NULL on error
* Returns the XML document, or NULL on error
*/
char *
virStorageVolGetXMLDesc(virStorageVolPtr vol,
@ -8161,7 +8161,7 @@ error:
* Fetch an XML document describing all aspects of
* the device.
*
* Return the XML document, or NULL on error
* Returns the XML document, or NULL on error
*/
char *virNodeDeviceGetXMLDesc(virNodeDevicePtr dev, unsigned int flags)
{
@ -9377,7 +9377,7 @@ virSecretRef(virSecretPtr secret)
*
* Release the secret handle. The underlying secret continues to exist.
*
* Return 0 on success, or -1 on error
* Returns 0 on success, or -1 on error
*/
int
virSecretFree(virSecretPtr secret)