X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=doc%2FDocBook.py;h=90b384d7f189025b98f816f278b53dfe1b4e5cef;hb=19d4a01ccf66af9e00914351b3eacd5fc880f988;hp=3434ce5c38add9d36cce556cb39c8fa31cd0f147;hpb=395fedea864079eea984bf6d9950076c0e893105;p=plcapi.git diff --git a/doc/DocBook.py b/doc/DocBook.py index 3434ce5..90b384d 100755 --- a/doc/DocBook.py +++ b/doc/DocBook.py @@ -6,16 +6,12 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id$ -# import xml.dom.minidom from xml.dom.minidom import Element, Text import codecs -from PLC.Method import * -import DocBookLocal -import groups +from PLC.Parameter import Parameter, Mixed, xmlrpc_type, python_type # xml.dom.minidom.Text.writexml adds surrounding whitespace to textual # data when pretty-printing. Override this behavior. @@ -104,96 +100,52 @@ class paramElement(Element): for subparam in param: itemizedlist.appendChild(paramElement(None, subparam)) - -def get_method_doc(func): - - method = func.name - - if func.status == "deprecated": - return - - (min_args, max_args, defaults) = func.args() - - section = Element('section') - section.setAttribute('id', func.name) - section.appendChild(simpleElement('title', func.name)) - - prototype = "%s (%s)" % (method, ", ".join(max_args)) - para = paraElement('Prototype:') - para.appendChild(blockquoteElement(prototype)) - section.appendChild(para) - - para = paraElement('Description:') - para.appendChild(blockquoteElement(func.__doc__)) - section.appendChild(para) - - para = paraElement('Allowed Roles:') - para.appendChild(blockquoteElement(", ".join(func.roles))) - section.appendChild(para) - - section.appendChild(paraElement('Parameters:')) - params = Element('itemizedlist') - if func.accepts: - for name, param, default in zip(max_args, func.accepts, defaults): - params.appendChild(paramElement(name, param)) - else: - listitem = Element('listitem') - listitem.appendChild(paraElement('None')) - params.appendChild(listitem) - section.appendChild(params) - - section.appendChild(paraElement('Returns:')) - returns = Element('itemizedlist') - returns.appendChild(paramElement(None, func.returns)) - section.appendChild(returns) - - #print section.toprettyxml(encoding = "UTF-8") - return section - - -def get_section(fields, field_list = None): - if not field_list: - field_list = fields.keys() - field_list.sort() - - for field in field_list: - value = fields[field] - section = Element('section') - section.setAttribute('id', field.title()) - section.appendChild(simpleElement('title', field.title())) - # if list of methods, append method docs - # else if dict, make a new section group - if isinstance(value, dict): - section.appendChild(get_section(value)) - elif isinstance(value, list): - methods = DocBookLocal.get_func_list(value) - for method in methods: - method_doc = get_method_doc(method) - section.appendChild(method_doc) - - return section - -# write full list of methods to Methods.xml -#api_func_list = DocBookLocal.get_func_list() -#methods_xml = file('Methods.xml', 'w') -#for func in api_func_list: -# section = get_method_doc(func) -# if section: -# methods_xml.write(section) -#methods_xml.close() - -# write methods grouped into interfaces -interfaces = ['Registry_Interface', 'Management_Interface', 'Slice_Interface'] -for interface in interfaces: - interface_file = file(interface+'.xml', 'w') - interface_methods = groups.interfaces[interface] - section = get_section(interface_methods, ['public', 'admin']) - if section: - interface_file.write(section.toprettyxml(encoding = "UTF-8")) - interface_file.close() - - - - - - +class DocBook: + + def __init__ (self,functions_list): + self.functions_list = functions_list + + def Process (self): + + for func in self.functions_list: + method = func.name + + if func.status == "deprecated": + continue + + (min_args, max_args, defaults) = func.args() + + section = Element('section') + section.setAttribute('id', func.name) + section.appendChild(simpleElement('title', func.name)) + + prototype = "%s (%s)" % (method, ", ".join(max_args)) + para = paraElement('Prototype:') + para.appendChild(blockquoteElement(prototype)) + section.appendChild(para) + + para = paraElement('Description:') + para.appendChild(blockquoteElement(func.__doc__)) + section.appendChild(para) + + para = paraElement('Allowed Roles:') + para.appendChild(blockquoteElement(", ".join(func.roles))) + section.appendChild(para) + + section.appendChild(paraElement('Parameters:')) + params = Element('itemizedlist') + if func.accepts: + for name, param, default in zip(max_args, func.accepts, defaults): + params.appendChild(paramElement(name, param)) + else: + listitem = Element('listitem') + listitem.appendChild(paraElement('None')) + params.appendChild(listitem) + section.appendChild(params) + + section.appendChild(paraElement('Returns:')) + returns = Element('itemizedlist') + returns.appendChild(paramElement(None, func.returns)) + section.appendChild(returns) + + print section.toprettyxml(encoding = "UTF-8")