
    g                         d dl Z d dlZd dlmZ  ej                  e      Zej                  ej                          G d de	      Z
 G d de
      Z G d de
      Zy)	    N)Pathc                   z    e Zd Zd Zd Zd Zd Zd ZddZd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)	BaseStorec                 2    | j                  di fdi fg       y )Nuser_propertiessession_parameters)updateselfs     /opt/Tautulli/lib/ga4mp/store.py__init__zBaseStore.__init__	   s    ',.BB-GHI    c                     t        d      )NzYSubclass should be using this function, but it was called through the base class instead.)NotImplementedErrorr
   s    r   savezBaseStore.save   s    !"}~~r   c                 4    || j                         vri | |<   y y N)keys)r   keys     r   _check_existszBaseStore._check_exists   s    diik!DI "r   c                 8    | j                  |       || |   |<   y N)r   )r   )r   
param_typenamevalues       r   _setzBaseStore._set   s"    z*!&Zr   c                 P    | j                  |       | |   j                  |d       S r   )r   get)r   r   r   s      r   _get_onezBaseStore._get_one   s+    z*J##D$//r   Nc                     || |   S | S r    )r   r   s     r   _get_allzBaseStore._get_all   s    !
##Kr   c                 ,    | j                  d||       y )Nr   r   r   r   r   r   r   r   s      r   set_user_propertyzBaseStore.set_user_property&   s    		.T	Gr   c                 (    | j                  d|      S )Nr   r   r   r   r   r   s     r   get_user_propertyzBaseStore.get_user_property)   s    }}(9}EEr   c                 &    | j                  d      S )Nr   r   r"   r
   s    r   get_all_user_propertiesz!BaseStore.get_all_user_properties,   s    }}(9}::r   c                     i | d<   y )Nr   r!   r
   s    r   clear_user_propertieszBaseStore.clear_user_properties/   s    "$r   c                 ,    | j                  d||       y )Nr   r$   r%   r&   s      r   set_session_parameterzBaseStore.set_session_parameter2   s    		1E	Jr   c                 (    | j                  d|      S )Nr   r)   r*   r+   s     r   get_session_parameterzBaseStore.get_session_parameter5   s    }}(<4}HHr   c                 &    | j                  d      S )Nr   r.   r/   r
   s    r   get_all_session_parametersz$BaseStore.get_all_session_parameters8   s    }}(<}==r   c                     i | d<   y )Nr   r!   r
   s    r   clear_session_parametersz"BaseStore.clear_session_parameters;   s    %'!"r   c                 ,    | j                  d||       y )Notherr$   r%   r&   s      r   set_other_parameterzBaseStore.set_other_parameter?   s    		W4u	=r   c                 (    | j                  d|      S )Nr<   r)   r*   r+   s     r   get_other_parameterzBaseStore.get_other_parameterB   s    }}d};;r   c                 &    | j                  d      S )Nr<   r.   r/   r
   s    r   get_all_other_parametersz"BaseStore.get_all_other_parametersE   s    }}}00r   c                     i | d<   y )Nr<   r!   r
   s    r   clear_other_parametersz BaseStore.clear_other_parametersH   s    Wr   r   )__name__
__module____qualname__r   r   r   r   r   r"   r'   r,   r0   r2   r4   r6   r8   r:   r=   r?   rA   rC   r!   r   r   r   r      sb    J
'
0
HF;%KI>(><1r   r   c                   ,     e Zd Zddef fdZd Z xZS )	DictStoredatac                 J    t         |           |r| j                  |       y y r   )superr   r	   )r   rI   	__class__s     r   r   zDictStore.__init__M   s"    KK r   c                 $    | j                          y r   r/   r
   s    r   r   zDictStore.saveR   s    r   r   )rD   rE   rF   dictr   r   __classcell__rL   s   @r   rH   rH   K   s    T 
r   rH   c                   2     e Zd Zddef fdZd Zd Z xZS )	FileStoredata_locationc                     t         |           || _        	 | j                  |       y #  t        j                  d|        Y y xY w)Nz!Failed to find file at location: )rK   r   rS   
_load_fileloggerinfo)r   rS   rL   s     r   r   zFileStore.__init__X   sD    *	MOOM*	MKK;M?KLs	   * Ac                    t        | j                        j                         r5t        | j                  d      5 }t	        j
                  |      } d d d        y d}t	        j                  |      }t        | j                        j                          t        | j                  d      5 }t	        j                  ||       d d d        y # 1 sw Y   y xY w# 1 sw Y   y xY w)Nrz/{"user_properties":{}, "session_parameters":{}}w)	r   rS   existsopenjsonloadloadstouchdumps)r   	json_filestarter_dictstarter_jsons       r   rU   zFileStore._load_file`   s     ""#**,d((#. ,)yy+, , ML::l3L##$**,d((#. 4)

<34 4, ,4 4s   C	)C	CCc                     	 t        | j                  d      5 }t        j                  | |       d d d        y # 1 sw Y   y xY w#  t        j                  d| j                          Y y xY w)NrZ   z!Failed to save file at location: )r\   rS   r]   dumprV   rW   )r   outfiles     r   r   zFileStore.saven   s_    	Rd((#. )'		$() ) )	RKK;D<N<N;OPQs$   A 8A AA A $A*r   )rD   rE   rF   strr   rU   r   rO   rP   s   @r   rR   rR   V   s    Mc M4Rr   rR   )r]   loggingpathlibr   	getLoggerrD   rV   setLevelINFOrN   r   rH   rR   r!   r   r   <module>rn      sY      			8	$  A AF		 	R	 Rr   