[commit] r1751 - in trunk/Tests/GPyUnit: . GME_297 GME_310 util
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Wed Dec 28 16:35:29 CST 2011
Author: ksmyth
Date: Wed Dec 28 16:35:28 2011
New Revision: 1751
Log:
Jython compat
Modified:
trunk/Tests/GPyUnit/GME_297/__init__.py
trunk/Tests/GPyUnit/GME_310/__init__.py
trunk/Tests/GPyUnit/GME_371.py
trunk/Tests/GPyUnit/__init__.py
trunk/Tests/GPyUnit/__main__.py
trunk/Tests/GPyUnit/test_gmeoleapp.py
trunk/Tests/GPyUnit/test_parser.py
trunk/Tests/GPyUnit/test_registrar.py
trunk/Tests/GPyUnit/test_registry.py
trunk/Tests/GPyUnit/util/__init__.py
trunk/Tests/GPyUnit/util/gme.py
trunk/Tests/GPyUnit/util/mgadiff.py
Modified: trunk/Tests/GPyUnit/GME_297/__init__.py
==============================================================================
--- trunk/Tests/GPyUnit/GME_297/__init__.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/GME_297/__init__.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -1,4 +1,5 @@
# tests for GME-311 and GME-297
+from __future__ import with_statement
import sys
import os.path
@@ -25,7 +26,7 @@
"""
def _adjacent_file(file):
import os.path
- return os.path.join(os.path.dirname(__file__), file)
+ return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
from GPyUnit import util
util.register_xmp(_adjacent_file('GME297ModelRefportTest.xmp'))
with util.disable_early_binding():
@@ -43,7 +44,7 @@
destination = self.project.ObjectByPath(self.destination_model)
if destination.ObjType == OBJTYPE_FOLDER:
- destination.MoveFolders(tomove, None)
+ destination.MoveFolderDisp(fco_to_move)
else:
self._move_fcos(destination, fco_to_move, tomove)
#destination.MoveFCOs(tomove, None, None)
@@ -59,10 +60,20 @@
# print "Reference file '%s' matches output '%s'" % (self.correct_file, self.output_file)
def _move_fcos(self, destination, fco_to_move, col_to_move):
- destination.MoveFCOs(col_to_move, None, None)
+ import platform
+ if platform.system() == 'Java':
+ import org.isis.jaut.Variant
+ destination.MoveFCODisp(fco_to_move, org.isis.jaut.Variant.create(org.isis.jaut.Variant.VT_UNKNOWN))
+ else:
+ destination.MoveFCOs(col_to_move, None, None)
def _move_fcos_disp(self, destination, fco_to_move, col_to_move):
- destination.MoveFCODisp(fco_to_move, None)
+ import platform
+ if platform.system() == 'Java':
+ import org.isis.jaut.Variant
+ destination.MoveFCODisp(fco_to_move, org.isis.jaut.Variant.create(org.isis.jaut.Variant.VT_UNKNOWN))
+ else:
+ destination.MoveFCODisp(fco_to_move, None)
def suite():
suite = unittest.TestSuite()
Modified: trunk/Tests/GPyUnit/GME_310/__init__.py
==============================================================================
--- trunk/Tests/GPyUnit/GME_310/__init__.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/GME_310/__init__.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -1,4 +1,5 @@
# tests for GME-310
+from __future__ import with_statement
import sys
import os.path
@@ -22,7 +23,7 @@
"""
def _adjacent_file(file):
import os.path
- return os.path.join(os.path.dirname(__file__), file)
+ return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
from GPyUnit import util
util.register_xmp(_adjacent_file('GME310ModelRefportTest.xmp'))
@@ -36,7 +37,7 @@
tomove = win32com.client.DispatchEx("Mga.MgaFolders")
tomove.Append(modelb)
#self.project.ObjectByPath(self.destination_folder).CopyFolders(tomove, None)
- self.project.RootFolder.CopyFolders(tomove, None)
+ self.project.RootFolder.CopyFolderDisp(modelb)
self.project.CommitTransaction()
self.project.Save("MGA=" + _adjacent_file(self.output_file))
Modified: trunk/Tests/GPyUnit/GME_371.py
==============================================================================
--- trunk/Tests/GPyUnit/GME_371.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/GME_371.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -5,7 +5,6 @@
def test_ParseMetaGME(self):
testdir = os.path.dirname(os.path.abspath(__file__))
inputfile = os.environ['GME_ROOT'] + r"\Paradigms\MetaGME\MetaGME-model.xme"
- from pythoncom import com_error
import win32com.client
xme = win32com.client.DispatchEx("Mga.MgaParser")
(paradigm, parversion, parguid, basename, ver) = xme.GetXMLInfo(inputfile)
@@ -13,8 +12,15 @@
mga.Create("MGA=tmp.mga", paradigm)
terr = mga.BeginTransactionInNewTerr()
+ import platform
+ if platform.system() != 'Java':
+ from pythoncom import com_error
+ exc_type = com_error
+ else:
+ import org.isis.jaut.InvokeException
+ exc_type = org.isis.jaut.InvokeException
# GME-371: this would crash
- self.assertRaises(com_error, xme.ParseProject, mga, inputfile)
+ self.assertRaises(exc_type, xme.ParseProject, mga, inputfile)
return
mga.CommitTransaction()
terr.Destroy()
Modified: trunk/Tests/GPyUnit/__init__.py
==============================================================================
--- trunk/Tests/GPyUnit/__init__.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/__init__.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -1,11 +1,27 @@
+from __future__ import with_statement
+
import unittest
-import GPyUnit.Regr.Mga.tc1
+import platform
+if platform.system() == 'Java':
+ import os
+ import os.path
+ import sys
+ sys.path.append(os.path.join(os.environ['GME_ROOT'], 'SDK', 'Java'))
+ sys.path.append(os.path.join(os.environ['GME_ROOT'], 'SDK', 'Java', 'gme.jar'))
+ #sys.registry['java.library.path'] = sys.registry['java.library.path'] + r';C:\Users\ksmyth\git\GMESRC\SDK\Java\native\Jaut\Release'
+ #print sys.registry['java.library.path']
+ #import java.lang
+ #java.lang.System.loadLibrary(r'C:\Users\ksmyth\git\GMESRC\SDK\Java\native\Jaut\Release\jaut.dll')
+ import org.isis.jaut
+ if not org.isis.jaut.Apartment.currentApartment():
+ org.isis.jaut.Apartment.enter(0)
+
+import GPyUnit.test_PIAs
# it is also possible to run tests like this on Python 2.7:
# python -m unittest GPyUnit.Regr.Mga.tc7
-_tests = unittest.defaultTestLoader.loadTestsFromNames(
-[ 'GPyUnit.' + test for test in (
+_tests = [
'test_PIAs',
'test_registrar',
'test_gmeoleapp',
@@ -14,10 +30,16 @@
'GME_297.suite',
'GME_310.suite',
'GME_371',
- 'Regr.Mga.tc1',
- 'Regr.Mga.tc2',
- 'Regr.Mga.tc3',
- 'Regr.Mga.tc5',
- 'Regr.Mga.tc6',
-)])
+]
+
+if platform.system() != 'Java':
+ _tests = _tests + [
+'Regr.Mga.tc1',
+'Regr.Mga.tc2',
+'Regr.Mga.tc3',
+'Regr.Mga.tc5',
+'Regr.Mga.tc6',
+]
+
+_tests = unittest.defaultTestLoader.loadTestsFromNames(['GPyUnit.' + test for test in _tests])
Modified: trunk/Tests/GPyUnit/__main__.py
==============================================================================
--- trunk/Tests/GPyUnit/__main__.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/__main__.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -1,3 +1,5 @@
+from __future__ import with_statement
+
import GPyUnit
import unittest
Modified: trunk/Tests/GPyUnit/test_gmeoleapp.py
==============================================================================
--- trunk/Tests/GPyUnit/test_gmeoleapp.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/test_gmeoleapp.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -1,3 +1,5 @@
+from __future__ import with_statement
+
import unittest
class TestGMEOLEApp(unittest.TestCase):
Modified: trunk/Tests/GPyUnit/test_parser.py
==============================================================================
--- trunk/Tests/GPyUnit/test_parser.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/test_parser.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -11,10 +11,12 @@
mga = GPyUnit.util.parse_xme(self.connstr)
mga.Save()
mga.Close()
+ if type(self) == TestParser:
+ self.assertTrue(os.path.isfile(_adjacent_file("parsertest.mga")))
@property
def connstr(self):
- return "MGA=" + _adjacent_file("tmp.mga")
+ return "MGA=" + _adjacent_file("parsertest.mga")
GPyUnit.util.MUGenerator(globals(), TestParser)
Modified: trunk/Tests/GPyUnit/test_registrar.py
==============================================================================
--- trunk/Tests/GPyUnit/test_registrar.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/test_registrar.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -4,7 +4,7 @@
def test_GetAssociatedParadigmsDisp(self):
import win32com.client
x = win32com.client.DispatchEx("MGA.MgaRegistrar")
- self.assertEqual(x.GetAssociatedParadigmsDisp("MGA.Interpreter.MetaInterpreter", 1), (u'MetaGME',))
+ self.assertEqual(list(x.GetAssociatedParadigmsDisp("MGA.Interpreter.MetaInterpreter", 1)), [u'MetaGME'])
#suite = (TestRegistrar(),)
Modified: trunk/Tests/GPyUnit/test_registry.py
==============================================================================
--- trunk/Tests/GPyUnit/test_registry.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/test_registry.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -1,13 +1,15 @@
+from __future__ import with_statement
import sys
import os.path
import unittest
import GPyUnit.util
+import GPyUnit.util.gme
import win32com.client
def _adjacent_file(file):
import os.path
- return os.path.join(os.path.dirname(__file__), file)
+ return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
class TestRegistry(unittest.TestCase):
def __init__(self, name, **kwds):
@@ -29,7 +31,7 @@
with util.disable_early_binding():
self.project = GPyUnit.util.DispatchEx("Mga.MgaProject")
self.project.Create(self.connstr, "MetaGME")
- self.project.BeginTransactionInNewTerr()
+ self.project.BeginTransactionInNewTerr(0)
rootregs = self.project.RootFolder.GetRegistryDisp(True)
self.assertEqual(rootregs.Count, 0)
@@ -108,7 +110,6 @@
self.project.CommitTransaction()
self.project.Close(True)
if self.connstr.find("MGA=") == 0:
- import util.gme
util.gme.mga2xme(_adjacent_file(self.output_file))
util.gme.xme2mga(os.path.splitext(_adjacent_file(self.output_file))[0] + ".xme")
self.project.Open(self.connstr)
@@ -159,7 +160,7 @@
sheet_meta = self.project.RootMeta.RootFolder.DefinedFCOs.Item(i)
sheet = self.project.RootFolder.CreateRootObject(sheet_meta)
sheet.SetRegistryValueDisp('test123', 'test')
- sheet2 = self.project.RootFolder.CopyFCOs(self.project.RootFolder.ChildFCOs).Item(1)
+ sheet2 = self.project.RootFolder.CopyFCODisp(sheet)
self.assertEqual(sheet2.GetRegistryValueDisp('test123'), 'test')
self.project.CommitTransaction()
self.project.Save()
Modified: trunk/Tests/GPyUnit/util/__init__.py
==============================================================================
--- trunk/Tests/GPyUnit/util/__init__.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/util/__init__.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -1,8 +1,8 @@
+from __future__ import with_statement
import os
import sys
import unittest
-import win32com.client
_opts = type("Options", (object,), {
'Dispatch_x64': False,
@@ -10,9 +10,9 @@
})
def DispatchEx(progid):
- from pythoncom import CLSCTX_ALL, CLSCTX_LOCAL_SERVER
- CLSCTX_ACTIVATE_32_BIT_SERVER = 0x40000
- CLSCTX_ACTIVATE_64_BIT_SERVER = 0x80000
+ import win32com.client
+ CLSCTX_ALL = 23
+ CLSCTX_LOCAL_SERVER = 4
if _opts.Dispatch_x64:
return win32com.client.DispatchEx(progid, clsctx=CLSCTX_LOCAL_SERVER|CLSCTX_ACTIVATE_64_BIT_SERVER)
else:
@@ -28,8 +28,20 @@
return self
def __exit__(self, exc_type, exc_value, traceback):
+ import win32com.client.gencache
win32com.client.gencache.GetClassForCLSID = self._savedGetClassForCLSID
+class NoopUsing(object):
+ def __enter__(self):
+ return self
+
+ def __exit__(self, exc_type, exc_value, traceback):
+ pass
+
+import platform
+if platform.system() == 'Java':
+ disable_early_binding = NoopUsing
+
def dec_disable_early_binding(f):
def ret(*args, **kwargs):
with disable_early_binding():
@@ -41,7 +53,7 @@
def register_xmp(xmpfile):
import os.path
predef = { 'SF': os.path.join(os.environ['GME_ROOT'], "Paradigms", "SF", "SF.xmp"),
- 'MetaGME': os.path.join(os.environ['GME_ROOT'], "Paradigms", "MetaGME", "Paradigm", "MetaGME.xmp") }
+ 'MetaGME': os.path.join(os.environ['GME_ROOT'], "Paradigms", "MetaGME", "MetaGME.xmp") }
if not os.path.isfile(xmpfile):
xmpfile = predef[xmpfile]
import gme
@@ -55,6 +67,8 @@
if project is None:
(paradigm, parversion, parguid, basename, ver) = parser.GetXMLInfo(xme)
+ import sys
+ #sys.stderr.write("xxx'" + paradigm + "'")
project = DispatchEx("Mga.MgaProject")
project.Create(connstr, paradigm)
parser.ParseProject(project, xme)
@@ -84,7 +98,7 @@
def __init__(self, name, **kwds):
super(MUTestMixin, self).__init__(name, **kwds)
import os.path
- self.mgxdir = os.path.abspath(os.path.join(os.path.dirname(__file__), "MUTest"))
+ self.mgxdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "MUTest")
def setUp(self):
super(MUTestMixin, self).setUp()
@@ -101,7 +115,7 @@
class MUSVNTestMixin(MUTestMixin):
def setUp(self):
super(MUSVNTestMixin, self).setUp()
- svn_file = os.path.abspath(os.path.join(os.path.dirname(__file__), "MUTestRepo"))
+ svn_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "MUTestRepo")
self.svn_url = "file:///" + svn_file
if os.path.isdir(svn_file):
import shutil
Modified: trunk/Tests/GPyUnit/util/gme.py
==============================================================================
--- trunk/Tests/GPyUnit/util/gme.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/util/gme.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -1,15 +1,18 @@
#!/bin/python
+from __future__ import with_statement
+
import re
import sys
import os.path
-import pythoncom
import win32com.client
import StringIO
+import platform
+
# For py2exe support
# To generate the exe, be sure to rename or delete .../Python/lib/site-packages/win32com/gen_py
# See http://www.py2exe.org/index.cgi/UsingEnsureDispatch
-if win32com.client.gencache.is_readonly == True:
+if hasattr(win32com.client, "gencache") and win32com.client.gencache.is_readonly == True:
#allow gencache to create the cached wrapper objects
win32com.client.gencache.is_readonly = False
# under p2exe the call in gencache to __init__() does not happen
@@ -25,7 +28,6 @@
print output.getvalue()
raise
-import pywintypes
import subprocess
import itertools
@@ -66,7 +68,7 @@
def maybe_elevate():
def decorator(func):
- if sys.getwindowsversion()[0] < 6:
+ if not hasattr(sys, "getwindowsversion") or sys.getwindowsversion()[0] < 6:
wrap = func
else:
def wrap(*args, **kwargs):
@@ -84,15 +86,7 @@
# GME functions
def create_project(project, connection, paradigm):
- try:
- return project.Create(connection, paradigm)
- except pywintypes.com_error as err:
-# from Mga.idl:
-#[helpstring("The paradigm is not registered")]
-# E_MGA_PARADIGM_NOTREG = 0x87650011,
- if err.excepinfo and err.excepinfo[5] == -2023423983:
- raise Exception("Paradigm '%s' not registered; can't open file '%s'" % (paradigm, connection), err)
- raise err
+ return project.Create(connection, paradigm)
# aka CreateMga.vbs
def xme2mga(xmefile, mgafile=None):
@@ -110,9 +104,12 @@
def get_paradigm_file(paradigm, regaccess=3):
"Returns the .mta file for a given registered paradigm"
registrar = win32com.client.DispatchEx("Mga.MgaRegistrar")
- guid = registrar.ParadigmGUIDString(regaccess, paradigm)
+ guid = registrar.GetParadigmGUIDStringDisp(regaccess, paradigm)
import uuid
- buf = buffer(uuid.UUID(guid).bytes_le, 0, 16)
+ if platform.system() != 'Java':
+ buf = buffer(uuid.UUID(guid).bytes_le, 0, 16)
+ else:
+ buf = str(uuid.UUID(guid).bytes_le[0:16])
(connstr, guid) = registrar.QueryParadigm(paradigm, None, buf, regaccess)
# >>> constr
# "MGA=....mta"
@@ -140,9 +137,9 @@
registrar = win32com.client.DispatchEx("Mga.MgaRegistrar")
paradigms = []
# REGACCESS_USER = 1
- paradigms.extend(registrar.Paradigms(1))
+ paradigms.extend(registrar.GetParadigmsDisp(1))
# REGACCESS_SYSTEM = 2
- paradigms.extend(registrar.Paradigms(2))
+ paradigms.extend(registrar.GetParadigmsDisp(2))
return filter(lambda p: p == paradigm, paradigms)
REGISTER = 128
@@ -150,7 +147,7 @@
def register_if_not_registered(file):
"Register an xme or mga if it has not already been registered"
if os.path.splitext(file)[1] == ".xmp":
- if not is_registered(os.path.basename(os.path.splitext(file)[0])) or not os.path.isfile(get_paradigm_file(os.path.splitext(os.path.basename(file))[0])):
+ if not is_registered(os.path.basename(os.path.splitext(file)[0])) or (platform.system() != 'Java' and not os.path.isfile(get_paradigm_file(os.path.splitext(os.path.basename(file))[0]))):
regxmp(file)
return
@@ -224,16 +221,7 @@
# TODO: on Vista or 7 we need to start an elevated registrar
registrar = win32com.client.DispatchEx("Mga.MgaRegistrar")
# REGACCESS_BOTH = 3,
- try:
- registrar.RegisterComponentLibrary(file, 3)
- except pywintypes.com_error as err:
-# KMS: GME assumes that the .dll has a type library. If it is a CLR component, it will not.
-# Warn if the type library registration fails
-# #define TYPE_E_CANTLOADLIBRARY _HRESULT_TYPEDEF_(0x80029C4AL)
- if warn_on_tlb_error and err.excepinfo and (err.excepinfo[5] & 0xffffffff == 0x80029c4a):
- sys.stderr.write("Type library registration for %s failed" % file);
- else:
- raise err
+ registrar.RegisterComponentLibrary(file, 3)
# UDM functions
@@ -305,118 +293,121 @@
reg.write(str)
elevated_check_call("regedit", regname)
+if platform.system() != 'Java':
+ # GME Project functions
+ import win32com.client.gencache
+ # Generate .py's for GME Type Library
+ # n.b. we don't use EnsureModule here because we don't properly version the typelib
+ # A change in the typelib may invalidate the cache, but gencache doesn't know it, e.g. GMESRC r947
+ meta_module = win32com.client.gencache.MakeModuleForTypelib('{0ADEEC71-D83A-11D3-B36B-005004D38590}', 0, 1, 0)
+ mga_module = win32com.client.gencache.MakeModuleForTypelib('{270B4F86-B17C-11D3-9AD1-00AA00B6FE26}', 0, 1, 0)
+
+ gme_constants = getattr(meta_module, "constants")
+
+ OBJTYPE_INTERFACE_MAP = {
+ gme_constants.OBJTYPE_MODEL: "IMgaModel",
+ # Seems IMgaAtom isn't generated because it defines no new methods
+ # 2: "IMgaAtom",
+ gme_constants.OBJTYPE_ATOM: "IMgaFCO",
+ gme_constants.OBJTYPE_REFERENCE: "IMgaReference",
+ gme_constants.OBJTYPE_CONNECTION: "IMgaConnection",
+ gme_constants.OBJTYPE_SET: "IMgaSet",
+ gme_constants.OBJTYPE_FOLDER: "IMgaFolder",
+ # gme_constants.OBJTYPE_ASPECT: "IMgaAspect",
+ # gme_constants.OBJTYPE_ROLE: "IMgaRole",
+ gme_constants.OBJTYPE_ATTRIBUTE: "IMgaAttribute",
+ gme_constants.OBJTYPE_PART: "IMgaPart",
+ }
+
+ def cast(fco):
+ return win32com.client.CastTo(fco, OBJTYPE_INTERFACE_MAP.get(fco.ObjType))
+
+ # KMS I'm not sure why gen_py lowercases these (for GME<VS2010). Create aliases:
+ if mga_module.IMgaReference._prop_map_get_.has_key("referred"):
+ mga_module.IMgaReference._prop_map_get_["Referred"] = mga_module.IMgaReference._prop_map_get_["referred"]
+ #mga_module.IMgaConnPoint._prop_map_get_["Target"] = mga_module.IMgaConnPoint._prop_map_get_["target"]
+ # Make IMgaFolder behave more like IMgaFCO
+ mga_module.IMgaFolder._prop_map_get_["Meta"] = mga_module.IMgaFolder._prop_map_get_["MetaFolder"]
+
+
+ def monkeypatch_method(classes):
+ def decorator(func):
+ for name in classes:
+ setattr(getattr(mga_module, name), func.__name__, func)
+ return func
+ return decorator
+
+ # ConnPoints([out, retval] IMgaConnPoints **pVal);
+ @monkeypatch_method(["IMgaConnection"])
+ def get_end(self, role):
+ ends = filter(lambda cp: cp.ConnRole == role, self.ConnPoints)
+ if ends:
+ return ends[0].Target
+ else:
+ raise Exception(self.Name + " has no connection point " + role)
-# GME Project functions
-import win32com.client.gencache
-# Generate .py's for GME Type Library
-# n.b. we don't use EnsureModule here because we don't properly version the typelib
-# A change in the typelib may invalidate the cache, but gencache doesn't know it, e.g. GMESRC r947
-meta_module = win32com.client.gencache.MakeModuleForTypelib('{0ADEEC71-D83A-11D3-B36B-005004D38590}', 0, 1, 0)
-mga_module = win32com.client.gencache.MakeModuleForTypelib('{270B4F86-B17C-11D3-9AD1-00AA00B6FE26}', 0, 1, 0)
-
-gme_constants = getattr(meta_module, "constants")
-
-OBJTYPE_INTERFACE_MAP = {
- gme_constants.OBJTYPE_MODEL: "IMgaModel",
- # Seems IMgaAtom isn't generated because it defines no new methods
-# 2: "IMgaAtom",
- gme_constants.OBJTYPE_ATOM: "IMgaFCO",
- gme_constants.OBJTYPE_REFERENCE: "IMgaReference",
- gme_constants.OBJTYPE_CONNECTION: "IMgaConnection",
- gme_constants.OBJTYPE_SET: "IMgaSet",
- gme_constants.OBJTYPE_FOLDER: "IMgaFolder",
-# gme_constants.OBJTYPE_ASPECT: "IMgaAspect",
-# gme_constants.OBJTYPE_ROLE: "IMgaRole",
- gme_constants.OBJTYPE_ATTRIBUTE: "IMgaAttribute",
- gme_constants.OBJTYPE_PART: "IMgaPart",
-}
-
-def cast(fco):
- return win32com.client.CastTo(fco, OBJTYPE_INTERFACE_MAP.get(fco.ObjType))
-
-# KMS I'm not sure why gen_py lowercases these (for GME<VS2010). Create aliases:
-if mga_module.IMgaReference._prop_map_get_.has_key("referred"):
- mga_module.IMgaReference._prop_map_get_["Referred"] = mga_module.IMgaReference._prop_map_get_["referred"]
-#mga_module.IMgaConnPoint._prop_map_get_["Target"] = mga_module.IMgaConnPoint._prop_map_get_["target"]
-# Make IMgaFolder behave more like IMgaFCO
-mga_module.IMgaFolder._prop_map_get_["Meta"] = mga_module.IMgaFolder._prop_map_get_["MetaFolder"]
-
-
-def monkeypatch_method(classes):
- def decorator(func):
- for name in classes:
- setattr(getattr(mga_module, name), func.__name__, func)
- return func
- return decorator
-
-# ConnPoints([out, retval] IMgaConnPoints **pVal);
- at monkeypatch_method(["IMgaConnection"])
-def get_end(self, role):
- ends = filter(lambda cp: cp.ConnRole == role, self.ConnPoints)
- if ends:
- return ends[0].Target
- else:
- raise Exception(self.Name + " has no connection point " + role)
-
- at monkeypatch_method(itertools.chain(["IMgaFCO"], OBJTYPE_INTERFACE_MAP.itervalues()))
-def kind(self):
- return self.Meta.Name
-
-OBJTYPE_MAP = {
- gme_constants.OBJTYPE_MODEL: "Model",
- gme_constants.OBJTYPE_ATOM: "Atom",
- gme_constants.OBJTYPE_REFERENCE: "Reference",
- gme_constants.OBJTYPE_CONNECTION: "Connection",
- gme_constants.OBJTYPE_SET: "Set",
- gme_constants.OBJTYPE_FOLDER: "Folder",
- gme_constants.OBJTYPE_ASPECT: "Aspect",
- gme_constants.OBJTYPE_ROLE: "Role",
- gme_constants.OBJTYPE_ATTRIBUTE: "Attribute",
- gme_constants.OBJTYPE_PART: "Part",
-}
-
- at monkeypatch_method(itertools.chain(["IMgaFCO"], OBJTYPE_INTERFACE_MAP.itervalues()))
-def mga_type(self):
- return OBJTYPE_MAP.get(self.ObjType)
-
- at monkeypatch_method(itertools.chain(["IMgaFCO"], OBJTYPE_INTERFACE_MAP.itervalues()))
-def parent(self):
- if self.mga_type() == "Folder":
- return self.ParentFolder
- parent = self.ParentFolder
- if not parent:
- parent = self.ParentModel
- return parent
-
- at monkeypatch_method(itertools.chain(["IMgaFCO"], OBJTYPE_INTERFACE_MAP.itervalues()))
-def parents(self):
- parents = []
- current = self
- while True:
- parent = current.parent()
+ @monkeypatch_method(itertools.chain(["IMgaFCO"], OBJTYPE_INTERFACE_MAP.itervalues()))
+ def kind(self):
+ return self.Meta.Name
+
+ OBJTYPE_MAP = {
+ gme_constants.OBJTYPE_MODEL: "Model",
+ gme_constants.OBJTYPE_ATOM: "Atom",
+ gme_constants.OBJTYPE_REFERENCE: "Reference",
+ gme_constants.OBJTYPE_CONNECTION: "Connection",
+ gme_constants.OBJTYPE_SET: "Set",
+ gme_constants.OBJTYPE_FOLDER: "Folder",
+ gme_constants.OBJTYPE_ASPECT: "Aspect",
+ gme_constants.OBJTYPE_ROLE: "Role",
+ gme_constants.OBJTYPE_ATTRIBUTE: "Attribute",
+ gme_constants.OBJTYPE_PART: "Part",
+ }
+
+ @monkeypatch_method(itertools.chain(["IMgaFCO"], OBJTYPE_INTERFACE_MAP.itervalues()))
+ def mga_type(self):
+ return OBJTYPE_MAP.get(self.ObjType)
+
+ @monkeypatch_method(itertools.chain(["IMgaFCO"], OBJTYPE_INTERFACE_MAP.itervalues()))
+ def parent(self):
+ if self.mga_type() == "Folder":
+ return self.ParentFolder
+ parent = self.ParentFolder
if not parent:
- return parents
- else:
- current = parent
- parents.append(parent)
+ parent = self.ParentModel
+ return parent
- at monkeypatch_method(itertools.chain(["IMgaFCO"], OBJTYPE_INTERFACE_MAP.itervalues()))
-def in_library(self):
- return filter(lambda x: x.mga_type() == "Folder" and x.LibraryName != "", self.parents())
-
- at monkeypatch_method(["IMgaFolder"])
-def children(self):
- children = []
- children.extend(self.ChildFolders)
- children.extend(self.ChildFCOs)
- return children
-
- at monkeypatch_method(["IMgaModel"])
-def children(self):
- return self.ChildFCOs
+ @monkeypatch_method(itertools.chain(["IMgaFCO"], OBJTYPE_INTERFACE_MAP.itervalues()))
+ def parents(self):
+ parents = []
+ current = self
+ while True:
+ parent = current.parent()
+ if not parent:
+ return parents
+ else:
+ current = parent
+ parents.append(parent)
-def is_container(fco):
- return fco.ObjType == gme_constants.OBJTYPE_MODEL or fco.ObjType == gme_constants.OBJTYPE_FOLDER
+ @monkeypatch_method(itertools.chain(["IMgaFCO"], OBJTYPE_INTERFACE_MAP.itervalues()))
+ def in_library(self):
+ return filter(lambda x: x.mga_type() == "Folder" and x.LibraryName != "", self.parents())
+
+ @monkeypatch_method(["IMgaFolder"])
+ def children(self):
+ children = []
+ children.extend(self.ChildFolders)
+ children.extend(self.ChildFCOs)
+ return children
+
+ @monkeypatch_method(["IMgaModel"])
+ def children(self):
+ return self.ChildFCOs
+
+ def is_container(fco):
+ return fco.ObjType == gme_constants.OBJTYPE_MODEL or fco.ObjType == gme_constants.OBJTYPE_FOLDER
+else:
+ def cast(fco):
+ return fco
import tempfile
class Project():
Modified: trunk/Tests/GPyUnit/util/mgadiff.py
==============================================================================
--- trunk/Tests/GPyUnit/util/mgadiff.py Wed Dec 28 16:35:05 2011 (r1750)
+++ trunk/Tests/GPyUnit/util/mgadiff.py Wed Dec 28 16:35:28 2011 (r1751)
@@ -1,3 +1,5 @@
+from __future__ import with_statement
+
import sys
import gme
import gc
@@ -14,13 +16,29 @@
def iter_parents(fco):
while fco:
yield fco
- fco = fco.parent()
+ if fco.ObjType == 6:
+ fco = fco.ParentFolder
+ else:
+ if fco.ParentFolder:
+ fco = fco.ParentFolder
+ else:
+ fco = fco.ParentModel
def fco_path(fco):
parents = list(iter_parents(fco))
parents.reverse()
return "/".join(map(lambda x: x.Name, parents))
+def _get_Meta(object):
+ if object.ObjType == 6:
+ return object.MetaFolder
+ return object.Meta
+
+def _get_children(object):
+ if object.ObjType == 6:
+ return list(object.ChildFolders) + list(object.ChildFCOs)
+ return list(object.ChildFCOs)
+
def compare2(project1, project2):
toProcess1=[]
toProcess2=[]
@@ -44,7 +62,7 @@
for index in range(len(toProcess2)):
current2 = gme.cast(toProcess2[index])
namesEqual = current1.Name == current2.Name
- kindsEqual = current1.Meta.Name == current2.Meta.Name
+ kindsEqual = _get_Meta(current1).Name == _get_Meta(current2).Name
connectionEndpointsEqual = True
if current1.ObjType == 4 and current2.ObjType == 4:
def mapConnpoints(conn):
@@ -70,7 +88,7 @@
print "'%s' has differing object types" % current1.AbsPath
return False
- if current1.Meta.Name != current2.Meta.Name:
+ if _get_Meta(current1).Name != _get_Meta(current2).Name:
print "'%s' has differing kinds" % current1.AbsPath
return False
@@ -149,15 +167,15 @@
continue
- childrenSet1=current1.children()
- childrenSet2=current2.children()
+ childrenSet1 = _get_children(current1)
+ childrenSet2 = _get_children(current2)
toProcess1.extend(childrenSet1)
toProcess2.extend(childrenSet2)
if len(childrenSet1)!= len(childrenSet2):
print "LENGTH of childrenSet FAILED for " + fco_path(current1)
- print "\t" + "File 1: " + ", ".join([child.Name for child in current1.children()])
- print "\t" + "File 2: " + ", ".join([child.Name for child in current2.children()])
+ print "\t" + "File 1: " + ", ".join([child.Name for child in _get_children(current1)])
+ print "\t" + "File 2: " + ", ".join([child.Name for child in _get_children(current2)])
return False
if current1.ObjType == 6 and current2.ObjType == 6:
More information about the gme-commit
mailing list