[Mobies-commit] [commit] r4252 - in UDM/trunk: lib src/Udm/PythonAPIGen tests/test_UdmPythonDS

endre at redhat3.isis.vanderbilt.edu endre at redhat3.isis.vanderbilt.edu
Mon Feb 10 01:19:52 CST 2014


Author: endre
Date: Mon Feb 10 01:19:52 2014
New Revision: 4252

Log:
adding more features to the DS Python API (Meta object for classes, attributes)

Modified:
   UDM/trunk/lib/UdmPython.py
   UDM/trunk/src/Udm/PythonAPIGen/PythonAPIGen.cpp
   UDM/trunk/tests/test_UdmPythonDS/Makefile.OSX
   UDM/trunk/tests/test_UdmPythonDS/test.py

Modified: UDM/trunk/lib/UdmPython.py
==============================================================================
--- UDM/trunk/lib/UdmPython.py	Thu Feb  6 11:26:18 2014	(r4251)
+++ UDM/trunk/lib/UdmPython.py	Mon Feb 10 01:19:52 2014	(r4252)
@@ -37,6 +37,9 @@
 		self.__dict__['indent'] = i
 
 	def __str__(self):
+		import udm	
+		if self.impl == udm.null:
+			 return self.impl.__str__()
 		import Uml
 		line = str()
 		cl = Uml.Class(self.impl.type)
@@ -170,3 +173,20 @@
 		return value.lower()=="true" 
 			
 		
+def GetUmlAttributeByName(cl, name):
+	import udm
+	import Uml
+	attrs = cl.getAttributeChildren()
+	for attr in attrs:
+		if attr.name == name:
+			return attr
+	return Uml.Attribute(udm.null)
+
+def GetUmlClassByName(dgr, name):
+	import udm
+	import Uml
+	classes = dgr.getClassChildren()
+	for cl in classes:
+		if cl.name == name:
+			return cl
+	return Uml.Class(udm.null)	

Modified: UDM/trunk/src/Udm/PythonAPIGen/PythonAPIGen.cpp
==============================================================================
--- UDM/trunk/src/Udm/PythonAPIGen/PythonAPIGen.cpp	Thu Feb  6 11:26:18 2014	(r4251)
+++ UDM/trunk/src/Udm/PythonAPIGen/PythonAPIGen.cpp	Mon Feb 10 01:19:52 2014	(r4252)
@@ -73,19 +73,39 @@
 	   set<Uml::Class> bases = currCls .baseTypes();
 	  m_output << "\t" << currCls.name() << ".meta = meta_map." << currCls.name() << endl;
   }
+  
+    m_output << endl;
+    m_output << "def init_classes(diagram):" << endl;
+    for( set< ::Uml::Class>::iterator uc_i = uml_classes.begin(); uc_i != uml_classes.end(); uc_i++ )
+    {
+        m_output << "\t" << uc_i->name() << ".Meta = GetUmlClassByName(diagram,\"" << uc_i->name()   << "\")"<< endl;
+    }
+
+  m_output << endl;
+  m_output << "def init_attributes():" << endl;
+    for( set< ::Uml::Class>::iterator uc_i = uml_classes.begin(); uc_i != uml_classes.end(); uc_i++ )
+    {
+        set< ::Uml::Attribute> attrs = uc_i->attributes();
+        for( set< ::Uml::Attribute>::iterator attrs_i = attrs.begin(); attrs_i != attrs.end(); attrs_i++)
+                m_output << "\t" << uc_i->name() << ".meta_" << attrs_i->name() << " = GetUmlAttributeByName(Uml.Class(" << uc_i->name() << ".meta), \"" << attrs_i->name() << "\")"<< endl;
+    }
+		
 
   m_output << endl << endl;
 
   /*INITIALIZE THE META STATIC VARIABLE*/
 
-  m_output << "def initialize(meta_map, uml_meta_map):" << endl;
+  m_output << "def initialize(diagram):" << endl;
   m_output << "\t" << "try:" << endl;
   m_output << "\t\t" << "module_initialized" << endl;
   m_output << "\t" << "except NameError:" << endl;
+  m_output << "\t\t" << "if sys.modules[__name__] != Uml:" << endl;
+  m_output << "\t\t\t" << "Uml.initialize(udm.uml_diagram())" << endl;
+  m_output << "\t\t" << "meta_map = udm.map_uml_names(diagram)" << endl;
   m_output << "\t\t" << "init_meta(meta_map)" << endl;
+  m_output << "\t\t" << "init_classes(Uml.Diagram(diagram))" << endl;
+  m_output << "\t\t" << "init_attributes()" << endl;
   m_output << "\t\t" << "module_initialized = True" << endl;
-  m_output << "\t\t" << "if sys.modules[__name__] != Uml:" << endl;
-  m_output << "\t\t\t" << "Uml.initialize(uml_meta_map, uml_meta_map)" << endl;
   m_output << endl;
 	
 

Modified: UDM/trunk/tests/test_UdmPythonDS/Makefile.OSX
==============================================================================
--- UDM/trunk/tests/test_UdmPythonDS/Makefile.OSX	Thu Feb  6 11:26:18 2014	(r4251)
+++ UDM/trunk/tests/test_UdmPythonDS/Makefile.OSX	Mon Feb 10 01:19:52 2014	(r4252)
@@ -17,6 +17,9 @@
 test:test.py Uml.py LampDiagram.py ../../lib/udm.so
 	DYLD_LIBRARY_PATH=$(DYLDLIBRARYPATH) VERSIONER_PYTHON_PREFER_32_BIT=$(VERSIONER_PYTHON_PREFER_32_BIT) python test.py
 
+test_console:
+	DYLD_LIBRARY_PATH=$(DYLDLIBRARYPATH) VERSIONER_PYTHON_PREFER_32_BIT=$(VERSIONER_PYTHON_PREFER_32_BIT) python 
+
 
 
 

Modified: UDM/trunk/tests/test_UdmPythonDS/test.py
==============================================================================
--- UDM/trunk/tests/test_UdmPythonDS/test.py	Thu Feb  6 11:26:18 2014	(r4251)
+++ UDM/trunk/tests/test_UdmPythonDS/test.py	Mon Feb 10 01:19:52 2014	(r4252)
@@ -45,7 +45,8 @@
 
 pdn = udm.SmartDataNetwork(udm.uml_diagram())
 pdn.open(r"../../samples/LampDiagram_udm.xml","")
-LampDiagram.initialize(udm.map_uml_names(pdn.root), udm.map_uml_names(udm.uml_diagram()))
+LampDiagram.initialize(pdn.root)  #for the moment, this takes as argument and Udm.Object and not Uml.Diagram
+
 
 
 dn = udm.SmartDataNetwork(pdn.root)
@@ -77,6 +78,8 @@
 print lamp_1.ModelName
 print lamp_1.meta.name
 
+print LampDiagram.Lamp.meta_ModelName
+print Uml.Class.meta_name
 
 dn.close_no_update()
 pdn.close_no_update()


More information about the Mobies-commit mailing list