Create an XML file (or MXL if compressed) for a given composition.
(composition, filename, zip=False)
| 315 | |
| 316 | |
| 317 | def 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() |
nothing calls this directly
no test coverage detected