관리-도구
편집 파일: notifications_helper.cpython-311.pyc
� �Cg� � �Z � d dl Z d dlZd dlZd dlZd dlmZmZmZ dZ G d� de � � Z dS )� N)�Dict�Iterable�UnionzAleksandr Shyshatskyc �r � e Zd ZdZdZdZd� Zd� Zd� Zd� Z d� Z ed � � � Zd � Z d� Zd� Zd � Zd� Zd� ZdS )�NotificationsHelperza Helper for our StatsNotifier plugin, contains logic related to notification periods z/var/lve/statsnotifier_last.tsz%/var/lve/statsnotifier_timestamps.binc � � i | _ i | _ d| _ t j t � � | _ | � � � d S )N���)�_users_notification_info�_resellers_notification_info�_admin_notify_time�logging� getLogger�__name__�_log�_load_from_persistent_storage��selfs ��/builddir/build/BUILDROOT/lve-stats-4.2.10-1.el8.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/lib/notifications_helper.py�__init__zNotificationsHelper.__init__ sF � �(*��%�,.��)�"$����%�h�/�/�� � �*�*�,�,�,�,�,� c � � | � � � | _ t j � | j � � sdS t | j d� � 5 }t j |� � \ | _ | _ ddd� � dS # 1 swxY w Y dS # t t f$ r | j � d� � Y dS w xY w)z� Load information about periods from persistent storage. Admin timestamp contains in separate file, in order to make it backwards-compatible with old logic N�rbz(Cannot load data from persistent storage)�_read_ts_from_filer �os�path�exists�RESELLERS_NOTIFICATIONS_STORAGE�open�pickle�loadr r �IOError�EOFErrorr � exception�r �fs r r z1NotificationsHelper._load_from_persistent_storage# s# � � #'�"9�"9�";�";����w�~�~�d�B�C�C� ��F� L��d�:�D�A�A� b�Q�SY�S^�_`�Sa�Sa�P��-�t�/P� b� b� b� b� b� b� b� b� b� b� b� b���� b� b� b� b� b� b����"� L� L� L��I��� J�K�K�K�K�K�K� L���s6 �B �"B�8B �B � B �B � B �+C� Cc �4 � | � | j � � t | j d� � 5 }t j | j | j f|d�� � ddd� � dS # 1 swxY w Y dS # t $ r | j � d� � Y dS w xY w)z� Save information about periods on disk. Admin timestamp contains in separate file, plain text. Resellers info is pickle'd and saved into other file. �wb� )�protocolNz+Unable to save resellers timestamps to file)�_save_ts_to_filer r r r �dumpr r r! r �warningr$ s r �save_to_persistent_storagez.NotificationsHelper.save_to_persistent_storage4 s � � ���d�5�6�6�6� M��d�:�D�A�A� o�Q���T�:�D�<]�^�`a�lm�n�n�n�n� o� o� o� o� o� o� o� o� o� o� o� o���� o� o� o� o� o� o��� M� M� M��I���K�L�L�L�L�L�L� M���s4 �A/ �$A"�A/ �"A&�&A/ �)A&�*A/ �/$B�Bc � � t | j dd�� � 5 }|� t |� � � � d d d � � d S # 1 swxY w Y d S # t $ r | j � d� � Y d S w xY w)N�w�utf-8��encodingz&Unable to save admin timestamp to file)r �STATSNOTIFIER_LAST_TS�write�strr! r r, )r �tsr% s r r* z$NotificationsHelper._save_ts_to_fileC s� � � H��d�0�#��H�H�H� !�A�����B��� � � � !� !� !� !� !� !� !� !� !� !� !� !���� !� !� !� !� !� !��� H� H� H��I���F�G�G�G�G�G�G� H���s3 �A �#A �A � A � A �A �A �$A>�=A>c �t � t | j dd�� � 5 }t |� � � � � � � � }|cd d d � � S # 1 swxY w Y d S # t $ r Y dS t $ r9}| j � d| j t |� � � � Y d }~dS d }~ww xY w)N�rr0 r1 r zUnable to read %s (%s)) r r3 �float�readline�rstripr! � ValueErrorr r, r5 )r r% r6 �es r r z&NotificationsHelper._read_ts_from_fileK s � � ��d�0�#��H�H�H� �A��1�:�:�<�<�.�.�0�0�1�1��� � � � � � � � � � � � ���� � � � � � �� � � � ��2�2�� � � ��I���6��8R�TW�XY�TZ�TZ�[�[�[��2�2�2�2�2����� ���s@ �A( �5A�A( �A�A( �"A�#A( �( B7�5 B7�>.B2�2B7c �( � t j � � S )zr Get current timestamp. In future, we may do some things here, like "round(time / 60**2)" )�time� r r �_get_current_timestampz*NotificationsHelper._get_current_timestampW s � � �y�{�{�r c � � | � � � }|D ](}| j � d||� � || j |<