Пример #1
0
    def setUpClass(cls):
        # Register the paradigm
        reg = __import__('win32com.client').client.DispatchEx(
            'Mga.MgaRegistrar')
        reg.RegisterParadigmFromDataDisp(
            'MGA=' + os.path.abspath(cls.PATH_MTA), 1)

        # Delete and reimport the GL model
        if os.path.exists(cls.PATH_MGA):
            os.remove(cls.PATH_MGA)
        xme2mga(cls.PATH_XME, cls.PATH_MGA)

        # Load the MGA and UDM. Let's only do this once okay?
        uml_diagram = udm.uml_diagram()
        meta_dn = udm.SmartDataNetwork(uml_diagram)
        meta_dn.open(cls.PATH_UDM_XML.encode("utf-8"), b"")
        cls.meta_dn = meta_dn

        dn = udm.SmartDataNetwork(meta_dn.root)
        dn.open(cls.PATH_MGA.encode("utf-8"), b"")
        cls.dn = dn

        cls.g = MgaRdfConverter.convert(dn.root, udm_xml=cls.PATH_UDM_XML)

        path_ttl_output = 'element_types_test_suite.ttl'
        print('Serializing converted TTL output to {}'.format(path_ttl_output))
        cls.g.serialize(path_ttl_output, format='turtle')

        cls.dn.close_no_update()
        cls.meta_dn.close_no_update()
Пример #2
0
def main():
    parser = ArgumentParser(
        description='Extract TTL-formatted RDF from a GME project')
    parser.add_argument(
        'project',
        type=str,
        nargs=1,
        help='the path of the GME project (XME or MGA) from which to extract')
    parser.add_argument(
        'udm_xml',
        type=str,
        nargs=1,
        help='the path of the UDM XML file defining the language')

    args = parser.parse_args()

    path_project = args.project[0]
    path_udm_xml = args.udm_xml[0]

    # Test for existence of file
    if not exists(path_project):
        raise ValueError('Cannot find GME project {}'.format(path_project))

    # Is it an MGA or an RDF?
    path_rootname, extension = splitext(path_project)
    # print (path_rootname, extension)

    if extension == '.xme':
        # Must convert to MGA first
        handle, path_mga = mkstemp(suffix='.mga')
        os.close(handle)
        print('creating a temporary MGA file at {}'.format(path_mga))

        xme2mga(path_project, path_mga)

    elif extension == '.mga':
        path_mga = path_project
    else:
        raise ValueError(
            'This project file needs to be either a .mga or .xme file: {}'.
            format(path_project))

    # Now let's load it.
    uml_diagram = udm.uml_diagram()
    meta_dn = udm.SmartDataNetwork(uml_diagram)
    meta_dn.open(path_udm_xml, b'')

    dn = udm.SmartDataNetwork(meta_dn.root)
    dn.open(path_mga, b'')

    g = MgaRdfConverter.convert(dn.root,
                                original_filename=path_project,
                                udm_xml=path_udm_xml)
    with open(path_rootname + '.ttl', 'w') as ttl:
        g.serialize(ttl, format='turtle')

    dn.close_no_update()
    meta_dn.close_no_update()
Пример #3
0
    def setUpClass(cls):
        # Delete and reimport the SF model
        if os.path.exists(cls.PATH_MGA):
            os.remove(cls.PATH_MGA)
        xme2mga(cls.PATH_XME, cls.PATH_MGA)

        # Load the MGA and UDM. Let's only do this once okay?
        uml_diagram = udm.uml_diagram()
        meta_dn = udm.SmartDataNetwork(uml_diagram)
        meta_dn.open(cls.PATH_UDM_XML.encode("utf-8"), b"")
        cls.meta_dn = meta_dn

        dn = udm.SmartDataNetwork(meta_dn.root)
        dn.open(cls.PATH_MGA.encode("utf-8"), b"")
        cls.dn = dn

        cls.g = MgaRdfConverter.convert(dn.root,
                                        udm_xml=cls.PATH_UDM_XML,
                                        original_filename=cls.PATH_XME)

        print(cls.g.serialize(format='turtle'))

        cls.dn.close_no_update()
        cls.meta_dn.close_no_update()
Пример #4
0
    #log_formatted("Output files are <a href=\"file:///{0}\" target=\"_blank\">{0}</a>.".format(output_dir))
    log("Output files are <a href=\"file:///{0}\" target=\"_blank\">{0}</a>.".format(output_dir))
    log('done')
    with open(os.path.join(output_dir, 'run_classifications.cmd'), 'w'):
        pass
    componentParameters['runCommand'] = 'run_classifications.cmd'
    #componentParameters['labels'] = 'Windows13.16'


# Allow calling this script with a .mga file as an argument
if __name__ == '__main__':
    import six.moves.winreg as winreg
    with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Software\META") as software_meta:
        meta_path, _ = winreg.QueryValueEx(software_meta, "META_PATH")

    # need to open meta DN since it isn't compiled in
    uml_diagram = udm.uml_diagram()
    meta_dn = udm.SmartDataNetwork(uml_diagram)
    import os.path
    CyPhyML_udm = os.path.join(meta_path, r"generated\CyPhyML\models\CyPhyML_udm.xml")
    if not os.path.isfile(CyPhyML_udm):
        CyPhyML_udm = os.path.join(meta_path, r"meta\CyPhyML_udm.xml")
    meta_dn.open(CyPhyML_udm, "")

    dn = udm.SmartDataNetwork(meta_dn.root)
    dn.open(sys.argv[1], "")
    # TODO: what should focusObject be
    # invoke(None, dn.root);
    dn.close_no_update()
    meta_dn.close_no_update()
Пример #5
0
#recursively print tree
def printTreeHelper(f, tree, numindents):
    total = 1
    indentation = ""
    if numindents != 0:
        for x in range(0, numindents):
            indentation = indentation + "\t"
    f.write("".join([indentation, tree.type.name, "\n"]))
    if len(tree.children()) != 0:
        for x in range(0, len(tree.children())):
            total += printTreeHelper(f, tree.children()[x], numindents + 1)
    return total


####################################################
#Finally, do some work

test_meta_dn = udm.SmartDataNetwork(udm.uml_diagram())
print "Reading xml meta model into udm..."
test_meta_dn.open(r"OpenFOAMPreProcessing.xml", "")
test_meta = udm.map_uml_names(test_meta_dn.root)
dn = udm.SmartDataNetwork(test_meta_dn.root)
print "Opening Model..."
dn.open(r"OpenFOAMExamples.mga", "")

print "Finding valid cases..."
processCases(dn.root, dn.root.name)

# print "Printing structure to file..."
# printTree("ModelStructure.txt",dn.root)
Пример #6
0
if __name__ == "__main__":
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog [options] input-uml.xml")
    parser.add_option("-o", "--output", dest="output", help="File or directory to output to.")
    parser.add_option("--impl_namespace", dest="impl_namespace")
    parser.add_option("--interface_namespace", dest="interface_namespace")
    (options, args) = parser.parse_args()
    if len(args) != 1:
        print parser.print_help()
        sys.exit()
    if options.impl_namespace:
        common.impl_namespace = options.impl_namespace + "."
    if options.interface_namespace:
        common.interface_namespace = options.interface_namespace + "."
    
    uml = udm.map_uml_names(udm.uml_diagram())
    dn = udm.SmartDataNetwork(udm.uml_diagram())
    dn.open(args[0], "")

    if options.output:
        if os.path.isdir(options.output):
            output = open(os.path.join(options.output, dn.root.name + ".cs"), "w")
        else:
            output = open(options.output, "w")
        # TODO: close this
    else:
        output = sys.stdout

    output.write("#pragma warning disable 0108\n"); # disable "'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended."

    def get_classes(dn):
Пример #7
0
Файл: test.py Проект: ksmyth/UDM
    
    if obj:
        
        obj.setIndent(indent_tabs)
        print obj
        generic_children = obj._get_children()
        if generic_children:
            print UdmPython.indent(indent_tabs) + "I have found the following children at this level: %d" % (len(generic_children))
            for child in generic_children:
                walk_hierarchy_udmp(child, indent_tabs+1)
    else:
        return



pdn = udm.SmartDataNetwork(udm.uml_diagram())
pdn.open(r"../../samples/LampDiagram_udm.xml","")
LampDiagram.initialize(pdn.root)  #for the moment, this takes as argument and Udm.Object and not Uml.Diagram



dn = udm.SmartDataNetwork(pdn.root)
dn.open(r"Lamp.mem","")


rf =LampDiagram.RootFolder(dn.root)

#walk_hierarchy_udm_o(dn.root)
#walk_hierarchy_udmp(UdmPython.UdmPython(dn.root))
walk_hierarchy_udmp(rf)
    print repr(rootObject.name)
    if focusObject:
        log("%s (%s) %s" % (focusObject.name, focusObject.type.name, udm.UdmId2GmeId(focusObject.id)))
        log(repr(dir(udm)))
        log(repr(dir(focusObject)))
        log(', '.join([test_component.name for test_component in focusObject.TestComponent_role_children]))
        log(', '.join(["%s=%s" % (param.name, param.Value) for param in focusObject.children() if param.type.name == 'Parameter']))
        #for child in focusObject.children():
        #    invoke(child, rootObject)

# Allow calling this script with a .mga file as an argument    
if __name__=='__main__':
    import _winreg as winreg
    with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Software\META") as software_meta:
        meta_path, _ = winreg.QueryValueEx(software_meta, "META_PATH")

    # need to open meta DN since it isn't compiled in
    uml_diagram = udm.uml_diagram()
    meta_dn = udm.SmartDataNetwork(uml_diagram)
    import os.path
    CyPhyML_udm = os.path.join(meta_path, r"generated\CyPhyML\models\CyPhyML_udm.xml")
    if not os.path.isfile(CyPhyML_udm):
        CyPhyML_udm = os.path.join(meta_path, r"meta\CyPhyML_udm.xml")
    meta_dn.open(CyPhyML_udm, "")

    dn = udm.SmartDataNetwork(meta_dn.root)
    dn.open(sys.argv[1], "")
    invoke(None, dn.root);
    dn.close_no_update()
    meta_dn.close_no_update()
Пример #9
0
    def testudmpython(self):
        # need to open meta DN since it isn't compiled in
        test_meta_dn= udm.SmartDataNetwork(udm.uml_diagram())
        test_meta_dn.open(r"UdmPythonTestMeta.xml", "")
        self.assertEquals(test_meta_dn.root.name, "UdmPythonTestMeta")
        test_meta = udm.map_uml_names(test_meta_dn.root)

        dn = udm.SmartDataNetwork(test_meta_dn.root)
        if _platform == "linux" or _platform == "linux2" or _platform == "darwin":
            dn.open(r"UdmPythonTest.xml", "")
        else:
            dn.open(r"UdmPythonTestModel.mga", "")

        container = dn.root.children()[0]
        self.assertTrue(container)
        # get children by type
        self.assertEquals(get_names(container.children(child_type=test_meta.AtomB)), [ "cmproleA1", "cmproleA2", "cmproleB1" ]) # also accepts child_role, parent_role
        # get children by child's composition role
        self.assertEquals(get_names(container.cmproleA_role_children), [ "cmproleA1", "cmproleA2" ])
        self.assertEquals(container.children(child_role="cmproleA"), container.cmproleA_role_children)
        self.assertEquals(get_names(container.cmproleB_role_children), [ "cmproleB1"] )
        self.assertEquals(container.type, test_meta.Container)
        def first(container): return next(container.__iter__())
        cmproleA1 = first(filter(lambda x: x.name =="cmproleA1", container.children()))
        cmproleA2 = first(filter(lambda x: x.name =="cmproleA2", container.children()))
        self.assertEquals(cmproleA1.dstConnection, [cmproleA2])
        self.assertEquals(cmproleA1.adjacent(dst_role="dstConnection"), [cmproleA2])
        self.assertEquals(cmproleA1.adjacent(src_role="srcConnection"), [cmproleA2])
        self.assertEquals(cmproleA2.adjacent(dst_role="dstConnection"), [])
        self.assertEquals(cmproleA2.adjacent(src_role="srcConnection"), [])
        AtomA1 = first(filter(lambda x: x.name =="AtomA1", container.children()))
        self.assertEquals(AtomA1.boolattr, True)
        self.assertEquals(AtomA1.stringattr, "teststring")
        self.assertEquals(AtomA1.intattr, 42)
        AtomA1.intattr = 60
        self.assertEquals(AtomA1.intattr, 60)
        AtomA1.stringattr = "test123"
        self.assertEquals(AtomA1.stringattr, "test123")
        unicode_teststring = u'\xc1rv\xedzt\u0171r\u0151 t\xfck\xf6rf\xfar\xf3g\xe9p\U0001d11e\u0393\u03b1\u03b6\u03ad\u03b5\u03c2 \u03ba\u03b1\u1f76 \u03bc\u03c5\u03c1\u03c4\u03b9\u1f72\u03c2 \u03b4\u1f72\u03bd \u03b8\u1f70 \u03b2\u03c1\u1ff6 \u03c0\u03b9\u1f70 \u03c3\u03c4\u1f78 \u03c7\u03c1\u03c5\u03c3\u03b1\u03c6\u1f76 \u03be\u03ad\u03c6\u03c9\u03c4\u03bf\u0ca0_\u0ca0\u30a6\u30f0\u30ce\u30aa\u30af\u30e4\u30de \u30b1\u30d5\u30b3\u30a8\u30c6 \u30a2\u30b5\u30ad\u30e6\u30e1\u30df\u30b7 \u30f1\u30d2\u30e2\u30bb\u30b9\u30f3\u0421\u044a\u0435\u0448\u044c \u0436\u0435 \u0435\u0449\u0451 \u044d\u0442\u0438\u0445 \u043c\u044f\u0433\u043a\u0438\u0445 \u0444\u0440\u0430\u043d\u0446\u0443\u0437\u0441\u043a\u0438\u0445 \u0431\u0443\u043b\u043e\u043a \u0434\u0430 \u0432\u044b\u043f\u0435\u0439 \u0447\u0430\u044e'
        AtomA1.stringattr = unicode_teststring
        self.assertEquals(AtomA1.stringattr, unicode_teststring)
        
        
        # trying to access nonexistant attribute raises an exception
        try:
            self.assertFalse(container.nonexistantattribute)
        except RuntimeError as e:
            # the error message should include the type's name and attribute name
            self.assertTrue(str(e).find("Container") != -1)
            self.assertTrue(str(e).find("nonexistantattribute") != -1)
        else:
            self.fail("Expected an exception")

        uml = udm.map_uml_names(udm.uml_diagram())
        for o in udm.uml_diagram().children():
            if get_names(o.children(child_type=uml.CompositionChildRole)) == ['namespaces'] and get_names(o.children(child_type=uml.CompositionParentRole)) == ['parent']:
                break
        else:
            self.fail()
        namespaces = o.children(child_type=uml.CompositionChildRole)[0] # i.e. CompositionChildRole in Composition Diagram<>---Namespace
        self.assertEquals(namespaces.min, 0)
        self.assertEquals(namespaces.max, -1)
        self.assertTrue(namespaces.isNavigable)
        self.assertEquals(namespaces.target, uml.Namespace)
        self.assertEquals(namespaces.adjacent(dst_role="target"), uml.Namespace)
        self.assertEquals(namespaces.adjacent(dst_role="target", src_role="childRoles"), uml.Namespace)
        # if we don't specify dst_role, adjacent() returns a list
        self.assertEquals(namespaces.adjacent(), [uml.Namespace])
        self.assertEquals(namespaces.adjacent(src_role="childRoles"), [uml.Namespace])

        self.assertEquals(get_names(test_meta_dn.root.children()[0].adjacent(dst_role="subTypes")), []) # also accepts dst_role, association_class
        self.assertTrue(test_meta_dn.root.children()[0].name)
        self.assertTrue(test_meta_dn.root.children()[0].stereotype)
        self.assertEqual(test_meta.AtomA.name, "AtomA")
        self.assertEquals(test_meta.AtomA, test_meta.AtomA)
        self.assertNotEqual(test_meta.AtomA, test_meta.AtomB)
        self.assertNotEqual(test_meta_dn.root, udm.uml_diagram())
        self.assertNotEqual(test_meta_dn, udm.uml_diagram()) # disparate types
        self.assertNotEqual(udm.uml_diagram(), test_meta_dn) # disparate types
        self.assertTrue(test_meta.AtomA.__hash__() > 0)
        self.assertTrue(test_meta.AtomA)

        #KMS: BUG: childRole_role_children should return a singleton, not a list
        self.assertEquals(test_meta.AtomA.childRoles[0].parent.childRole_role_children[0].target, test_meta.AtomA)

        dn.close_no_update()
        test_meta_dn.close_no_update()