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()
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()
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()
#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()
#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)
theOther(associationRole).name, theOther(associationRole).target.name)) else: pass if class_.baseTypes: print_('{} Base Classes:'.format(indent)) for baseType in class_.baseTypes: if baseType in bases: print_('{} {}'.format(indent, baseType.name)) else: bases.add(baseType) print_uml_info(baseType, indent=indent + ' ', bases=bases) if __name__ == '__main__': meta_dn = udm.SmartDataNetwork(uml_diagram) with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Software\META") as software_meta: meta_path, _ = winreg.QueryValueEx(software_meta, "META_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, "") CyPhyML = udm.map_uml_names(meta_dn.root) print_uml_info(CyPhyML.Component) print_uml_info(CyPhyML.Property) print_uml_info(CyPhyML.ValueFlow, print_=lambda x: print(x, file=sys.stdout)) # print_uml_info(CyPhyML.ValueFlow.type) # aka Uml.Class