From a1e42af8602a63f7c5d8fbaa1b71cdd5028f117a Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 17 Dec 2021 10:37:45 +0100 Subject: [PATCH] easier to understand --- python/damask/_result.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index 2453001a6..019f9c87d 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -156,7 +156,7 @@ class Result: self.fname = Path(fname).absolute() - self._allow_modification = False + self._protected = True def __copy__(self): @@ -349,20 +349,18 @@ class Result: """ v = _view_transition(what,datasets,increments,times,phases,homogenizations,fields) if protected is not None: - if v == None: + if v is None: dup = self.copy() else: what_,datasets_ = v dup = self._manage_view('set',what_,datasets_) + if protected is True: + print(util.warn('Warning: Modification of existing datasets allowed!')) + dup._protected = protected else: what_,datasets_ = v dup = self._manage_view('set',what_,datasets_) - if protected is False: - dup._allow_modification = True - if protected is True: - print(util.warn('Warning: Modification of existing datasets allowed!')) - dup._allow_modification = False return dup @@ -487,7 +485,7 @@ class Result: >>> r_unprotected.rename('F','def_grad') """ - if not self._allow_modification: + if self._protected: raise PermissionError('Renaming datasets not permitted') with h5py.File(self.fname,'a') as f: @@ -526,7 +524,7 @@ class Result: >>> r_unprotected.remove('F') """ - if not self._allow_modification: + if self._protected: raise PermissionError('Removing datasets not permitted') with h5py.File(self.fname,'a') as f: @@ -1417,7 +1415,7 @@ class Result: lock.acquire() with h5py.File(self.fname, 'a') as f: try: - if self._allow_modification and '/'.join([group,result['label']]) in f: + if not self._protected and '/'.join([group,result['label']]) in f: dataset = f['/'.join([group,result['label']])] dataset[...] = result['data'] dataset.attrs['overwritten'] = True