[Mobies-commit] [commit] r4092 - in UDM/trunk/src/UdmPython: . udm

ksmyth at redhat1.isis.vanderbilt.edu ksmyth at redhat1.isis.vanderbilt.edu
Fri Aug 17 14:25:32 CDT 2012


Author: ksmyth
Date: Fri Aug 17 14:25:31 2012
New Revision: 4092

Log:
UdmPython for Linux. distutils setup.py

Added:
   UDM/trunk/src/UdmPython/setup.py   (contents, props changed)
   UDM/trunk/src/UdmPython/udm/
   UDM/trunk/src/UdmPython/udm/__init__.py
Modified:
   UDM/trunk/src/UdmPython/UdmPython.cpp

Modified: UDM/trunk/src/UdmPython/UdmPython.cpp
==============================================================================
--- UDM/trunk/src/UdmPython/UdmPython.cpp	Mon Aug 13 10:31:25 2012	(r4091)
+++ UDM/trunk/src/UdmPython/UdmPython.cpp	Fri Aug 17 14:25:31 2012	(r4092)
@@ -2,7 +2,9 @@
 #include "UdmBase.h"
 #include "Uml.h"
 #include "UmlExt.h"
+#ifdef _WIN32
 #include "UdmGme.h"
+#endif
 #include "UdmUtil.h"
 
 #include "boost/python.hpp"
@@ -15,6 +17,7 @@
 using namespace boost::python;
 using namespace std;
 
+#ifdef _WIN32
 // returns borrowed reference
 IUnknown* object2IUnknown(object o) {
 	//	oleobj = disp._oleobj_
@@ -37,6 +40,7 @@
 		throw std::runtime_error("self is not a GmeDataNetwork");
 	return gmedn->Gme2Udm(punk);
 }
+#endif
 
 void SDN_OpenExisting(Udm::SmartDataNetwork& self, object systemname, const string& metalocator) {
 	extract<std::string> string_systemname(systemname);
@@ -45,6 +49,7 @@
 		self.OpenExisting(string_systemname, metalocator, Udm::CHANGES_LOST_DEFAULT);
 		return;
 	}
+#ifdef _WIN32
 	if (PyObject_HasAttrString(systemname.ptr(), "_oleobj_") 
 		|| PyObject_HasAttrString(systemname.ptr(), "GetIDsOfNames"))
 	{
@@ -58,6 +63,7 @@
 		});
 		return;
 	}
+#endif
 	throw runtime_error("Unrecognized type for systemname");
 }
 
@@ -90,10 +96,10 @@
 	return (Udm::Object) Uml::Class::meta.parent();
 }
 
-template<class colT>
+template<typename colT>
 boost::python::list toList(colT collection) {
 	boost::python::list ret;
-	colT::iterator it = collection.begin();
+	typename colT::iterator it = collection.begin();
 	for (; it != collection.end(); it++) {
 		ret.append(object(*it));
 	}
@@ -110,7 +116,7 @@
 	attrs.insert(aattrs.begin(),aattrs.end());
 
 	
-	for(set< ::Uml::Attribute>::iterator attrsIt = attrs.begin(); attrsIt != attrs.end(); attrsIt++) {
+	for(set< ::Uml::Attribute> ::iterator attrsIt = attrs.begin(); attrsIt != attrs.end(); attrsIt++) {
 		string strCurrAttrName = attrsIt->name();
 		
 		if (strCurrAttrName == name) {
@@ -208,13 +214,13 @@
 	}
 
 	::Uml::Class srcClass = self.type();
-	set<::Uml::Class> ancestorClasses = ::Uml::AncestorClasses(srcClass);
-	set<::Uml::Class>::iterator ancestorClassesIt = ancestorClasses.begin();
+	set< ::Uml::Class> ancestorClasses = ::Uml::AncestorClasses(srcClass);
+	set< ::Uml::Class> ::iterator ancestorClassesIt = ancestorClasses.begin();
 
 	for(; ancestorClassesIt != ancestorClasses.end(); ancestorClassesIt++) {
 		// Getting the association roles and iterating through them
-		set<::Uml::AssociationRole> assocRoles = ancestorClassesIt->associationRoles();
-		set<::Uml::AssociationRole>::iterator assocRolesIt = assocRoles.begin();
+		set< ::Uml::AssociationRole> assocRoles = ancestorClassesIt->associationRoles();
+		set< ::Uml::AssociationRole> ::iterator assocRolesIt = assocRoles.begin();
 		for(; assocRolesIt != assocRoles.end(); assocRolesIt++) {
 			::Uml::AssociationRole oRole = ::Uml::theOther(*assocRolesIt);
 			// Checking role names
@@ -257,7 +263,7 @@
 					Udm::Object& o = extract<Udm::Object&>(_targets[i]);
 					targets_impl.push_back(o.__impl());
 					if (o.__impl()->__getdn()->uniqueId() != self.__impl()->__getdn()->uniqueId()) {
-						throw std::exception("Cannot set_adjacent with a target from a different DataNetwork");
+						throw udm_exception("Cannot set_adjacent with a target from a different DataNetwork");
 					}
 				}
 			}
@@ -310,28 +316,28 @@
 	}
 
 	::Uml::Class srcClass = self.type();
-	set<::Uml::Class> ancestorClasses = ::Uml::AncestorClasses(srcClass);
-	set<::Uml::Class>::iterator ancestorClassesIt = ancestorClasses.begin();
+	set< ::Uml::Class> ancestorClasses = ::Uml::AncestorClasses(srcClass);
+	set< ::Uml::Class> ::iterator ancestorClassesIt = ancestorClasses.begin();
 
 	for(; ancestorClassesIt != ancestorClasses.end(); ancestorClassesIt++) {
-		::Uml::Association association = static_cast<::Uml::Association>(ancestorClassesIt->association());
+		::Uml::Association association = static_cast< ::Uml::Association>(ancestorClassesIt->association());
 		if (association && dstrolename != object()) {
-			std::set<::Uml::AssociationRole> roles = association.AssociationRole_kind_children();
-			for (auto roleIt = roles.begin(); roleIt != roles.end(); roleIt++) {
+			std::set< ::Uml::AssociationRole> roles = association.AssociationRole_kind_children();
+			for (std::set< ::Uml::AssociationRole> ::iterator roleIt = roles.begin(); roleIt != roles.end(); roleIt++) {
 				::Uml::AssociationRole role = *roleIt;
 				if (static_cast<std::string>(role.name()) == 
 						static_cast<const char*>(extract<const char*>(dstrolename))) {
 					using namespace Udm;
 					vector<ObjectImpl*> dstPeers = self.__impl()->getAssociation(role, Udm::TARGETFROMCLASS);
-					vector<ObjectImpl*>::iterator dstPeersIt = dstPeers.begin();
+					vector<ObjectImpl*> ::iterator dstPeersIt = dstPeers.begin();
 					foundApplicableAssociation = true;
 					return object(Udm::Object(*dstPeersIt));
 				}
 			}
 		}
 		// Getting the association roles and iterating through them
-		set<::Uml::AssociationRole> assocRoles = ancestorClassesIt->associationRoles();
-		set<::Uml::AssociationRole>::iterator assocRolesIt = assocRoles.begin();
+		set< ::Uml::AssociationRole> assocRoles = ancestorClassesIt->associationRoles();
+		set< ::Uml::AssociationRole> ::iterator assocRolesIt = assocRoles.begin();
 		for(; assocRolesIt != assocRoles.end(); assocRolesIt++) {
 			::Uml::AssociationRole oRole = ::Uml::theOther(*assocRolesIt);
 			// Checking role names
@@ -360,7 +366,7 @@
 			// simple association
 			if (!assoc_cls) {
 				vector<ObjectImpl*> dstPeers = self.__impl()->getAssociation(oRole, Udm::TARGETFROMPEER);
-				vector<ObjectImpl*>::iterator dstPeersIt = dstPeers.begin();
+				vector<ObjectImpl*> ::iterator dstPeersIt = dstPeers.begin();
 
 				for (; dstPeersIt != dstPeers.end(); dstPeersIt++) {
 					Udm::Object dstObject(*dstPeersIt);
@@ -382,7 +388,7 @@
 			// Check all association with classes
 			vector<ObjectImpl*> assocs = self.__impl()->getAssociation(oRole, Udm::CLASSFROMTARGET);
 
-			for(vector<ObjectImpl*>::iterator p_currAssoc = assocs.begin(); p_currAssoc != assocs.end(); p_currAssoc++)
+			for(vector<ObjectImpl*> ::iterator p_currAssoc = assocs.begin(); p_currAssoc != assocs.end(); p_currAssoc++)
 			{
 				Udm::Object assocCls_obj(*p_currAssoc);
 				::Uml::Class clsAssociation = assocCls_obj.type();
@@ -393,7 +399,7 @@
 
 				// Get and test the peers
 				vector<ObjectImpl*> dstPeers = assocCls_obj.__impl()->getAssociation(oRole, Udm::TARGETFROMCLASS);
-				vector<ObjectImpl*>::iterator dstPeersIt = dstPeers.begin();
+				vector<ObjectImpl*> ::iterator dstPeersIt = dstPeers.begin();
 				for (; dstPeersIt != dstPeers.end(); dstPeersIt++) {
 					Udm::Object dstObject(*dstPeersIt);
 						
@@ -520,7 +526,11 @@
 }
 
 extern "C" {
+#ifdef _WIN32
 __declspec(dllexport) PyObject* __cdecl Object_Convert(Udm::Object udmObject) {
+#else
+PyObject* Object_Convert(Udm::Object udmObject) {
+#endif
 	object o(udmObject);
 	PyObject* ret = o.ptr();
 	Py_INCREF(ret);
@@ -587,7 +597,9 @@
 		.def("close_no_update", &Udm::SmartDataNetwork::CloseNoUpdate)
 		.def("save_as", &Udm::SmartDataNetwork::SaveAs)
 		.add_property("root", &Udm::SmartDataNetwork::GetRootObject)
+#ifdef _WIN32
 		.def("convert_gme2udm", SDN_Gme2Udm)
+#endif
 	;
 	scope().attr("SmartDataNetwork").attr("__init__") = eval("lambda self, *args: None");
 	exec(
@@ -606,8 +618,10 @@
 "    return map_classes(diagram)\n",
 		import("__main__").attr("__dict__"), scope().attr("__dict__"));
 
+#ifdef _WIN32
 	def("UdmId2GmeId", UdmGme::UdmId2GmeId);
 	Udm::Object::uniqueId_type (*GmeId2UdmId)(const char* gmeId) = &UdmGme::GmeId2UdmId;
 	def("GmeId2UdmId", GmeId2UdmId);
+#endif
 
 }

Added: UDM/trunk/src/UdmPython/setup.py
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ UDM/trunk/src/UdmPython/setup.py	Fri Aug 17 14:25:31 2012	(r4092)
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+import sys
+import os
+import os.path
+import platform
+from distutils.core import setup, Extension
+from distutils.command.build_ext import build_ext
+
+this_dir = os.path.dirname(os.path.abspath(__file__))
+
+setup_args = dict(
+    name='Udm',
+    version='3.2',
+    description='Universal Data Model',
+    long_description='Universal Data Model',
+    author='Kevin Smyth',
+    author_email='ksmyth at isis.vanderbilt.edu',
+    url='http://repo.isis.vanderbilt.edu/',
+    license='Vanderbilt UDM License',
+    packages=['udm'],
+)
+
+setup_args['ext_modules'] = [
+  Extension('udm',
+    ['UdmPython.cpp'],
+    libraries=['boost_python'], # TODO: udm?
+    include_dirs=['/usr/include/udm/', os.path.join(this_dir, '../../include')])
+]
+if platform.system() == 'Windows':
+    class my_build_ext(build_ext):
+        def build_extension(self, ext):
+            ''' Copies the already-compiled pyd
+            '''
+            import shutil
+            import os.path
+            try:
+                os.makedirs(os.path.dirname(self.get_ext_fullpath(ext.name)))
+            except WindowsError, e:
+                if e.winerror != 183: # already exists
+                    raise
+
+
+            shutil.copyfile(os.path.join(this_dir, r'..\..\bin\Python%d%d\udm.pyd' % sys.version_info[0:2]), self.get_ext_fullpath(ext.name))
+
+    setup_args['cmdclass'] = {'build_ext': my_build_ext }
+
+setup(**setup_args)

Added: UDM/trunk/src/UdmPython/udm/__init__.py
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ UDM/trunk/src/UdmPython/udm/__init__.py	Fri Aug 17 14:25:31 2012	(r4092)
@@ -0,0 +1,9 @@
+'''
+Udm: Universal data model
+
+Udm is a metaprogrammable tool for providing uniform access to data structures that could be persistent.
+
+http://repo.isis.vanderbilt.edu/tools/get_tool?UDM
+'''
+
+from udm import *


More information about the Mobies-commit mailing list