MCPcopy Create free account
hub / github.com/bspaans/python-mingus / write_Composition

Function write_Composition

mingus/extra/musicxml.py:317–342  ·  view source on GitHub ↗

Create an XML file (or MXL if compressed) for a given composition.

(composition, filename, zip=False)

Source from the content-addressed store, hash-verified

315
316
317def write_Composition(composition, filename, zip=False):
318 """Create an XML file (or MXL if compressed) for a given composition."""
319 text = from_Composition(composition)
320 if not zip:
321 f = open(filename + ".xml", "w")
322 f.write(text)
323 f.close()
324 else:
325 import zipfile
326 import os
327
328 zf = zipfile.ZipFile(
329 filename + ".mxl", mode="w", compression=zipfile.ZIP_DEFLATED
330 )
331 zi = zipfile.ZipInfo("META-INF" + os.sep + "container.xml")
332 zi.external_attr = 0o660 << 16
333 zf.writestr(
334 zi,
335 "<?xml version='1.0' encoding='UTF-8'?>"
336 "<container><rootfiles><rootfile full-path='{0}.xml'/>"
337 "</rootfiles></container>".format(filename),
338 )
339 zi = zipfile.ZipInfo(filename + ".xml")
340 zi.external_attr = 0o660 << 16
341 zf.writestr(zi, text)
342 zf.close()

Callers

nothing calls this directly

Calls 1

from_CompositionFunction · 0.70

Tested by

no test coverage detected