�
�~�eLR � � � d dl Z d dlZd dlZd dlZd dlmZ g d�Z e� Z G d� de � Z
G d� de
� Z G d� d � Z G d
� d� Z
ej d� j Zd
� Zd� Z G d� d� Z G d� de� Z G d� de� Zy)� N)�
StringType)�Persist�
PickleBackend�BPickleBackend�path_string_to_tuple�path_tuple_to_string�
RootedPersist�PersistError�PersistReadOnlyErrorc � � e Zd Zy)r
N��__name__�
__module__�__qualname__� � �7/usr/lib/python3/dist-packages/landscape/lib/persist.pyr
r
, � � �r r
c � � e Zd Zy)r Nr
r r r r r 0 r r r c �� � e Zd ZdZdd�Zd� Zd� Zd� Z eee� Z ee� Z
d� Zd� Zd � Z
dd
�Zeefd�Zdd
�Zedddfd�Zdd�Zdd�Zdd�Zdd�Zeddfd�Zdd�Zd� Zy)r a Persist a hierarchical database of key=>value pairs.
There are three different kinds of option maps, regarding the
persistence and priority that maps are queried.
- hard - Options are persistent.
- soft - Options are not persistent, and have a higher priority
than persistent options.
- weak - Options are not persistent, and have a lower priority
than persistent options.
@ivar filename: The name of the file where persist data is saved
or None if no filename is available.
Nc � � |�
t � }|| _ |j � | _ i | _ i | _ d| _ d| _ | | _ || _ |�2t j j |� r| j |� yyy)a�
@param backend: The backend to use. If none is specified,
L{BPickleBackend} will be used.
@param filename: The default filename to save to and load from. If
specified, and the file exists, it will be immediately
loaded. Specifying this will also allow L{save} to be called
without any arguments to save the persist.
NF)r �_backend�new�_hardmap�_softmap�_weakmap� _readonly� _modified�_config�filename�os�path�exists�load)�self�backendr s r �__init__zPersist.__init__F sx � � �?�$�&�G���
����
��
���
���
���������� ��
���B�G�G�N�N�8�$<��I�I�h�� %=�r c � � | j S �N)r �r% s r �
_get_readonlyzPersist._get_readonly\ � � ��~�~�r c �$ � t |� | _ y r) )�boolr )r% �flags r �
_set_readonlyzPersist._set_readonly_ s
� ��d���r c � � | j S r) �r r* s r �
_get_modifiedzPersist._get_modifiedb r, r c � � d| _ y)z(Set the database status as non-modified.FNr2 r* s r �reset_modifiedzPersist.reset_modifiedh s � ���r c �2 � | j rt d� �y)zRAssert if the object is writable
@raise: L{PersistReadOnlyError}
z"Configuration is in readonly mode.N)r r r* s r �assert_writablezPersist.assert_writablel s � �
�>�>�&�'K�L�L� r c � � �� �� fd�}t j j �� �t j j �� s |� ryt d�� �� �t j j �� dk( r |� y � j j �� � _ y# t $ r |� rY yt d�� �� �w xY w)zLoad a persisted database.c � �� �dz } t j j | � rDt j j | � dkD r" �j j | � �_ yy# t $ r t d| � �� �w xY w)N�.oldr �Broken configuration file at TF) r! r" |