Added the possibility of genearting sm, am and registry separately
[sfa.git] / wsdl / gw2wsdl.py
index f08891d..558ad1f 100755 (executable)
@@ -10,13 +10,17 @@ import time
 import pdb
 import xml.dom.minidom
 import xml.dom.ext
-import globals
 import apistub
+import inspect
+
 from types import *
+from optparse import OptionParser
 
 from sfa.trust.auth import Auth
 from sfa.util.parameter import Parameter,Mixed
 
+import globals
+
 complex_types = {}
 services = {}
 
@@ -59,6 +63,7 @@ def name_complex_type(arg):
 
     types_section = types.getElementsByTagName("xsd:schema")[0]
 
+    #pdb.set_trace()
     if (isinstance(arg, Mixed)):
         inner_types = reduce(fold_complex_type, arg)
         inner_names = reduce(fold_complex_type_names, arg)
@@ -91,8 +96,7 @@ def name_complex_type(arg):
         complex_content = complex_type.appendChild(types.createElement("xsd:list"))
         complex_content.setAttribute("itemType",inner_type)
         return "xsdl:%s"%type_name
-        
-    elif type(arg) == DictType or arg == DictType or issubclass(arg, dict):
+    elif type(arg) == DictType or arg == DictType or (inspect.isclass(arg) and issubclass(arg, dict)):
         num_types=num_types+1
         type_name = "Type%d"%num_types
         complex_type = types_section.appendChild(types.createElement("xsd:complexType"))
@@ -106,11 +110,13 @@ def name_complex_type(arg):
             element.setAttribute("type",inner_type)
 
         return "xsdl:%s"%type_name 
-
     else:
         return (name_simple_type(arg))
 
 def name_simple_type(arg_type):
+    # A Parameter is reported as an instance, even though it is serialized as a type <>
+    if type(arg_type) == InstanceType:
+        return (name_simple_type(arg_type.type))
     if arg_type == None:
         return "none"
     if arg_type == DictType:
@@ -132,6 +138,7 @@ def param_type(arg):
 
 def add_wsdl_ports_and_bindings (wsdl):
     for method in apistub.methods:
+
         # Skip system. methods
         if "system." in method:
             continue
@@ -218,17 +225,19 @@ def add_wsdl_ports_and_bindings (wsdl):
 
 def add_wsdl_service(wsdl):
     for service in services.keys():
-        service_el = wsdl.firstChild.appendChild(wsdl.createElement("service"))
-        service_el.setAttribute("name", service)
+        global interface_options
+        if (getattr(interface_options,service)):
+            service_el = wsdl.firstChild.appendChild(wsdl.createElement("service"))
+            service_el.setAttribute("name", service)
 
-        for method in services[service]:
-            name=method
-            servport_el = service_el.appendChild(wsdl.createElement("port"))
-            servport_el.setAttribute("name", name + "_port")
-            servport_el.setAttribute("binding", "tns:" + name + "_binding")
+            for method in services[service]:
+                    name=method
+                    servport_el = service_el.appendChild(wsdl.createElement("port"))
+                    servport_el.setAttribute("name", name + "_port")
+                    servport_el.setAttribute("binding", "tns:" + name + "_binding")
 
-            soapaddress = servport_el.appendChild(wsdl.createElement("soap:address"))
-            soapaddress.setAttribute("location", "%s/%s" % (globals.plc_ns,service))
+                    soapaddress = servport_el.appendChild(wsdl.createElement("soap:address"))
+                    soapaddress.setAttribute("location", "%s/%s" % (globals.plc_ns,service))
 
 
 def get_wsdl_definitions():
@@ -268,13 +277,28 @@ def get_wsdl_definitions_and_types():
     wsdl = xml.dom.minidom.parseString(wsdl_text_header)
     return wsdl
 
-    
-types = get_wsdl_definitions_and_types()
-
-wsdl = get_wsdl_definitions()
-add_wsdl_ports_and_bindings(wsdl)
-wsdl_types = wsdl.importNode(types.getElementsByTagName("types")[0], True)
-wsdl.firstChild.appendChild(wsdl_types)
-add_wsdl_service(wsdl)
-
-xml.dom.ext.PrettyPrint(wsdl)
+def main():
+    global types
+    global interface_options
+
+    parser = OptionParser()
+    parser.add_option("-r", "--registry", dest="registry", action="store_true", 
+                              help="Generate registry.wsdl", metavar="FILE")
+    parser.add_option("-s", "--slice-manager",
+                              action="store_true", dest="slicemgr", 
+                              help="Generate sm.wsdl")
+    parser.add_option("-a", "--aggregate", action="store_true", dest="aggregate",
+                              help="Generate am.wsdl")
+
+    (interface_options, args) = parser.parse_args()
+    types = get_wsdl_definitions_and_types()
+    wsdl = get_wsdl_definitions()
+    add_wsdl_ports_and_bindings(wsdl)
+    wsdl_types = wsdl.importNode(types.getElementsByTagName("types")[0], True)
+    wsdl.firstChild.appendChild(wsdl_types)
+    add_wsdl_service(wsdl)
+
+    xml.dom.ext.PrettyPrint(wsdl)
+
+if __name__ == "__main__":
+        main()