# -*- coding: utf-8 -*-## This file is subject to the terms and conditions defined in# file 'LICENSE.txt', which is part of this source code package.#"""Universal file writer"""
[docs]defWriteMesh(filename,outmesh,binary=None,writer=None):# pragma: no coverfromMuscat.IO.IOFactoryimportCreateWriterifwriterisNone:writer=CreateWriter("."+filename.split(".")[-1])writer.SetFileName(filename)ifnot(binaryisNone):writer.SetBinary(binary)writer.Open()PointFields=NonePointFieldsNames=Noneifhasattr(outmesh,"nodeFields"):PointFieldsNames=list(outmesh.nodeFields.keys())PointFields=list(outmesh.nodeFields.values())CellFields=NoneCellFieldsNames=Noneifhasattr(outmesh,"elemFields"):CellFieldsNames=list(outmesh.elemFields.keys())CellFields=list(outmesh.elemFields.values())writer.Write(outmesh,PointFieldsNames=PointFieldsNames,PointFields=PointFields,CellFieldsNames=CellFieldsNames,CellFields=CellFields)writer.Close()
[docs]defCheckIntegrity(GUI:bool=False)->str:fromMuscat.Helpers.CheckToolsimportMustFailFunctionfromMuscat.IO.IOFactoryimportCreateWriter,RegisterWriterClassInitAllWriters()print(CreateWriter(".geof"))print(CreateWriter(".msh"))print(CreateWriter(".mesh"))print(CreateWriter(".xdmf"))MustFailFunction(CreateWriter,"toto")# normally this class must have the same API as#fromMuscat.IO.WriterBaseimportWriterBaseasWriterBaseclassMyCustomWriter(WriterBase):passRegisterWriterClass(".myDummyExtension",MyCustomWriter,withError=False)print(CreateWriter(".myDummyExtension"))return"ok"
if__name__=="__main__":print((CheckIntegrity()))# pragma: no cover