sforkowany z mirror/rnsutils
1
0
Forkuj 0

Prevent accidental overwrite of destination xrni

master
Olivier Jolly 2016-02-01 17:59:37 +01:00
rodzic 334d8e5241
commit 47bb4ccad7
1 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -1,9 +1,11 @@
import logging
import math
import pkgutil
import pprint
from zipfile import ZipFile, ZIP_DEFLATED
import io
import os
from lxml import etree, objectify
from lxml.objectify import ObjectifiedElement
@ -139,11 +141,15 @@ class RenoiseInstrument(object):
self.sample_data = [z.read(sample_filename) for sample_filename in sorted(z.namelist()) if
sample_filename.startswith('SampleData')]
def save(self, filename, cleanup=True):
def save(self, filename, overwrite=False, cleanup=True):
if cleanup:
self.cleanup()
if os.path.isfile(filename) and not overwrite:
logging.error("Destination file %s exists and overwrite was not forced", filename)
return
with ZipFile(filename, 'w', compression=ZIP_DEFLATED) as z:
objectify.deannotate(self.root, cleanup_namespaces=True, xsi_nil=True)
z.writestr("Instrument.xml", etree.tostring(self.root, pretty_print=True))