Example #1
0
 def set_changes(self, data):
     """Set the given data structure as changes, so that changes() would return that exact structure
     This will also discard any previous changes that might currently exist.
     @return self"""
     if data:
         self._value_dict = merge_data(data, self._value_dict)
     # end handle re-apply changes
     return self
Example #2
0
 def __init__(self, data, settings_path_or_stream, take_ownership = True):
     """Initialize this instance to write its changes to the given path
     @param data dict-like objectwe should initialize our underlying kvstore with
     @param take_ownership if True, we will assume no one will change the 'data' from the outside
     @param settings_path_or_stream a file-like object to read from. If None, there are no changes applied to the base provided
     by 'data'. Can also be a path to the settings file to read.
     @note we do not support input paths, as we fill ourselves with the given data"""
     super(PersistentSettings, self).__init__(settings_path_or_stream and [settings_path_or_stream] or list(),
                                              take_ownership)
     
     # now we will have loaded the data at target path, if there was something stored already
     # It shouldn't be the value_data, but the base data
     if self._data():
         # target file was read and contained data 
         # The base data must data, the current_value must be data|target_data,
         if not take_ownership:
             data = deepcopy(data)
         # end handle data copy
         self._base_value_dict = data
         self._value_dict = merge_data(self._value_dict, data, delegate_type = _PersistentSettingsMergeDelegate)
     else:
         # just set the new data directly
         self._set_data(data, take_ownership = take_ownership)