Edit File: helpers.cpython-37.pyc
B �e� � @ s� d dl mZ d dl mZ d dl mZ d dlZd dlZd dlZd dlZd dlZd dl Z d dl mZ d dlm Z d dlmZ e�e�ZdZe d d � �Zdd� ZdS ) � )�absolute_import)�division)�print_functionN)�StringIO)�contextmanager)�wrapsz&/usr/share/cloudlinux/hooks/listeners/c c sB t j}t j}z"| pt� t _|p"t� t _d V W d |t _|t _X d S )N)�sys�stdout�stderrr )ZstdoZstder r � r ��/builddir/build/BUILDROOT/alt-python27-cllib-3.3.5-1.el8.cloudlinux.x86_64/opt/alt/python37/lib/python3.7/site-packages/clcommon/public_hooks/lib/helpers.py�capture_output s r c s t � �� fdd��}d|_|S )a, Magic decorator that calls all subclass methods that override base decorated one. Requirements: - subclass must be defined in .py file in LISTENERS_DIRECTORY - subclass must NOT start with '_' char - subclass must override base event method (the one with '@hook_method') c s� �x�| j �� D �]�}tj�t�|�j�}tj�t �tj�|�krRt �d|t |� q|j� d�r`qt|� � j�}t|dd�r�t �d� j|j� qt �d� j|j� t�� }t� t� }}z�y$t||�� |||� W d Q R X W nV tk �r2 tjjjd|j� jg|�� |�� d�d � t jd |j� jdd� Y nX W d t�� | } |�� } | �rft �d � j|j| � |�� }|�r�t �d� j|j|� t �d� j| � X qW t �d� jt�� t�� � t �d� j||� d S )Nz,%s is not in %s directory; it is in %s, skip�_�is_magic_methodFz skip %s is not implemented in %szexecuting %s:%sz {{ default }})r r )ZfingerprintZextrazlistener %s:%s crashed� )�exc_infoz8captured stdout of %s:%s ~BEGIN OUTPUT~ %s ~END OUTPUT~ z8captured stderr of %s:%s ~BEGIN OUTPUT~ %s ~END OUTPUT~ zrunning %s: %.4f elapsedz.%s executed by the user with uid %s and gid %szended %s(%s, %s))� __class__�__subclasses__�os�path�dirname�inspectZ getmodule�__file__�normpath�LISTENERS_DIRECTORY�loggerZwarning�__name__� startswith�getattr�debug�info�timer r � Exception�raven�baseZRavenZcaptureException�getvalue�geteuid�getegid)�self�args�kwargs�subclassZ listener_pathZlistenerZnowr r �elapsedZ stdout_strZ stderr_str)�funcr r �_wrapped1 sJ zhook_method.<locals>._wrappedT)r r )r- r. r )r- r �hook_method( s 3r/ )Z __future__r r r r Zloggingr r r# r! �ior � contextlibr � functoolsr Z getLoggerr r r r r/ r r r r �<module> s