overwriting datasets makes sense in special cases
but prevent user from accidently doing that and store the information
This commit is contained in:
parent
b6812d58b0
commit
b9e16ea951
|
@ -89,6 +89,8 @@ class Result:
|
||||||
|
|
||||||
self.fname = os.path.abspath(fname)
|
self.fname = os.path.abspath(fname)
|
||||||
|
|
||||||
|
self._allow_overwrite = False
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""Show selected data."""
|
"""Show selected data."""
|
||||||
|
@ -163,6 +165,16 @@ class Result:
|
||||||
self.selection[what] = diff_sorted
|
self.selection[what] = diff_sorted
|
||||||
|
|
||||||
|
|
||||||
|
def enable_overwrite(self):
|
||||||
|
print(util.bcolors().WARNING,util.bcolors().BOLD,
|
||||||
|
'Warning: Enabled overwrite of existing datasets!',
|
||||||
|
util.bcolors().ENDC)
|
||||||
|
self._allow_overwrite = True
|
||||||
|
|
||||||
|
def disable_overwrite(self):
|
||||||
|
self._allow_overwrite = False
|
||||||
|
|
||||||
|
|
||||||
def incs_in_range(self,start,end):
|
def incs_in_range(self,start,end):
|
||||||
selected = []
|
selected = []
|
||||||
for i,inc in enumerate([int(i[3:]) for i in self.increments]):
|
for i,inc in enumerate([int(i[3:]) for i in self.increments]):
|
||||||
|
@ -1015,8 +1027,13 @@ class Result:
|
||||||
continue
|
continue
|
||||||
lock.acquire()
|
lock.acquire()
|
||||||
with h5py.File(self.fname, 'a') as f:
|
with h5py.File(self.fname, 'a') as f:
|
||||||
try: # ToDo: Replace if exists?
|
try:
|
||||||
dataset = f[result[0]].create_dataset(result[1]['label'],data=result[1]['data'])
|
if self._allow_overwrite and result[0]+'/'+result[1]['label'] in f:
|
||||||
|
dataset = f[result[0]+'/'+result[1]['label']]
|
||||||
|
datset = result[1]['data']
|
||||||
|
dataset.attrs['Overwritten'] = True
|
||||||
|
else:
|
||||||
|
dataset = f[result[0]].create_dataset(result[1]['label'],data=result[1]['data'])
|
||||||
now = datetime.datetime.now().astimezone()
|
now = datetime.datetime.now().astimezone()
|
||||||
dataset.attrs['Created'] = now.strftime('%Y-%m-%d %H:%M:%S%z').encode()
|
dataset.attrs['Created'] = now.strftime('%Y-%m-%d %H:%M:%S%z').encode()
|
||||||
for l,v in result[1]['meta'].items():
|
for l,v in result[1]['meta'].items():
|
||||||
|
|
Loading…
Reference in New Issue