def delete_data(self, varname: str): with self.metadataset.lock_data(varname): if varname not in self.varset: raise NotFoundError(f'{varname} not found') self.recyclebin.discard(varname, self.varset[varname]) self.varset.pop(varname) self.metadataset.delete_data(varname)
def delete_data(self, key: str, provider='unknown'): with self.metadataset.lock_data(key): if key not in self.varset: raise NotFoundError(f'{key} not found') self.recyclebin.discard(key, self.varset[key]) self.varset.pop(key) self.metadataset.delete_data(key)
def modify_data(self, key: str, modified_by: str): if key not in self: raise NotFoundError(f'no such data {key}') info = self[key] info['modification_time'].append(time.time()) info['modified_by'].append(modified_by) info['synchronised'] = False info['deleted'] = False
def read_data(self, key: str) -> dict: with self.metadataset.lock_data(key): if key not in self.metadataset or self.metadataset[key]['deleted']: raise NotFoundError(f'{key} not found') metadata = self.metadataset[key] if not metadata['synchronised']: data = self.converter.convert_to_data( self.varset.get_var(key)) self.dataset.synchronise(key, data) self.metadataset.synchronise_data(key) return self.dataset.read(key)
def restore(self, index: int, var_to_discard=None) -> tuple: # for the case where variables with same name # exist in workspace and recycle bin, if you # restore the variable in recycle bin, you have # to discard the variable in the workspace if index >= len(self): raise NotFoundError(f'{index} out of limit') varname, var_to_restore = self[index] self.pop(index) if var_to_discard is not None: self.discard(varname, var_to_discard) return varname, var_to_restore
def read_data(self, varname: str) -> dict: with self.metadataset.lock_data(varname): if varname not in self.metadataset or self.metadataset[varname][ 'deleted']: raise NotFoundError(f'{varname} not found') metadata = self.metadataset[varname] if not metadata['synchronised']: data = self.converter.convert_to_data( self.varset.get_var(varname)) self.dataset.synchronise(varname, data) self.metadataset.synchronise_data(varname) return self.dataset.read(varname)
def redo(self, key): with self.metadataset.lock_data(key): if key not in self.historyset: raise NotFoundError(f'{key} has no history') variable = self.historyset.stepforward(key) self.varset.set_var(key, variable)
def cancel(self, key): with self.metadataset.lock_data(key): if key not in self.historyset: raise NotFoundError(f'{key} has no history') variable = self.historyset.stepback(key, self.varset[key]) self.varset.set_var(key, variable)
def get_var(self, varname: str): if varname not in self.varset: raise NotFoundError(f'{varname} not found') return self.varset[varname]
def update(self, key: str, **info): if key not in self or self[key]['deleted']: raise NotFoundError(f'no such data {key}') self[key].update(info)
def synchronise_data(self, key: str): if key not in self or self[key]['deleted']: raise NotFoundError(f'no such data {key}') self[key]['synchronised'] = True
def restore_data(self, key: str): if key not in self: raise NotFoundError(f'no such data {key}') self[key]['deleted'] = False
def get_data_info(self, key: str) -> dict: if key not in self.metadataset: raise NotFoundError(f'{key} not found') return self.metadataset[key]
def get_data_info(self, varname: str) -> dict: if varname not in self.metadataset: raise NotFoundError(f'{varname} not found') return self.metadataset[varname]
def stepforward(self, key: str): if key not in self: raise NotFoundError(f'{key} not found in history') history = self[key] return history.stepforward()
def stepback(self, key: str, var): if key not in self: raise NotFoundError(f'{key} not found in history') history = self[key] return history.stepback(var)
def cancel(self, varname): with self.metadataset.lock_data(varname): if varname not in self.historyset: raise NotFoundError(f'{varname} has no history') variable = self.historyset.stepback(varname, self.varset[varname]) self.varset.set_var(varname, variable)
def update_data_info(self, varname: str, **info): with self.metadataset.lock_data(varname): if varname not in self.metadataset: raise NotFoundError(f'{varname} not found') self.metadataset.update(varname, **info)
def get_var(self, key: str): if key not in self.varset: raise NotFoundError(f'{key} not found') return self.varset[key]
def get_varname(self, index: int): if index >= len(self): raise NotFoundError(f'{index} out of limit') return self[index][0]
def update_data_info(self, key: str, **info): with self.metadataset.lock_data(key): if key not in self.metadataset: raise NotFoundError(f'{key} not found') self.metadataset.update(key, **info)
def redo(self, varname): with self.metadataset.lock_data(varname): if varname not in self.historyset: raise NotFoundError(f'{varname} has no history') variable = self.historyset.stepforward(varname) self.varset.set_var(varname, variable)