%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/clwpos/user/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/clwpos/user/__pycache__/config.cpython-37.pyc

B

�4Lb�$�@s�ddlmZddlZddlZddlZddlZddlmZmZddl	m
Z
ddlmZddl
mZmZmZddlmZddlmZdd	lmZdd
lmZGdd�de�ZGd
d�de�ZdS)�)�absolute_importN)�Iterable�Optional)�ALL_OPTIMIZATION_MODULES)�
setup_logging)�get_relative_docroot�create_clwpos_dir_if_not_exists�is_run_under_user)�
is_wp_path)�	constants)�	WposError)�gettextc@seZdZdZdS)�ConfigErrorz^
    Used for all exceptions during handling clwpos user config
    in UserConfig methods
    N)�__name__�
__module__�__qualname__�__doc__�rr�C/opt/alt/python37/lib/python3.7/site-packages/clwpos/user/config.pyrsrc@s�eZdZdZej�dejej	�Z
ej�d�Zied�Zdd�Z
dd�Zed	�d
d�Zdd
�Zed�dd�Zd!eeeeeed�dd�Zeeedd�dd�Zeeedd�dd�Zdd�Zeeed�dd�Zdd �ZdS)"�
UserConfigzQ
    Class to manage clwpos user config - read, write, set params in config.
    z	{homedir}Zmb)�docrootsZmax_cache_memorycCsNt�sttd���||_t�|�j|_|jj	|jd�|_
tt�|_
t|�dS)Nz&Trying to use UserConfig class as root)�homedir)r	r�_�username�pwd�getpwnam�pw_dirr�CONFIG_PATH�format�config_pathrr�_loggerr)�selfrrrr�__init__-s
zUserConfig.__init__c	Cs`y&t|jd��}t�|���SQRXWn4tk
rZt��}tt	d�|j|d�d��YnXdS)z4
        Reads config from self.config_path
        �rNz@Error while reading config %(config_path)s: %(exception_string)s)rZexception_string)�message�context)
�openr�json�loads�read�	Exception�	traceback�
format_excrr)r!�fZ
exc_stringrrr�read_config7szUserConfig.read_config)�configc
Csry6tj|ddd�}t|jd��}|�|�WdQRXWn6tk
rl}zttd�d|id��Wdd}~XYnXdS)	z=
        Writes config (as json) to self.config_path
        �T)�indentZ	sort_keys�wNzDAttempt of writing to config file failed due to error:
%(exception)s�	exception)r$r%)r'�dumpsr&r�writer*rr)r!r/Zconfig_jsonr-�errr�write_configEszUserConfig.write_configcCsLtj�|j�s|jSy|��}Wntk
r6|jSXt|t�rF|S|jS)zP
        Returns default config or config content from self.config_path
        )	�os�path�existsr�DEFAULT_CONFIGr.r�
isinstance�dict)r!r/rrr�
get_configSszUserConfig.get_config)�paramscCs4|��}x|��D]\}}|||<qW|�|�dS)a�
        Set outer (not "docroots") params in config.
        Example:
        Old config:
        {
            "docroots": ...,
            "max_cache_memory": "123mb",
        }
        Input params:
        {
            "max_cache_memory": "1024mb",
            "param": "value"
        }
        New config:
        {
            "docroots": ...,
            "max_cache_memory": "1024mb",
            "param": "value"
        }
        N)r>�itemsr7)r!r?r/�key�valuerrr�
set_paramscszUserConfig.set_paramsN)�domain�wp_path�moduler/�returnc	
Cs8|p
|��}yt||j�}WnJtk
rf}z,|jj|dd�ttd�||jd�d��Wdd}~XYnXtt	j
�|j||��s�ttd�d|id��|tkr�ttd�|td	�d��y$|d
}|�
|i��
|g�}||kStttfk
�r2}z8|jjd|j�d|��dd�ttd
�d|jid��Wdd}~XYnXdS)NT)�exc_infozDCan't find docroot for domain '%(domain)s' and homedir '%(homedir)s')rDr)r$r%z)Wrong wordpress path '%(wp_path)s' passedrEz9Invalid module %(module)s, available choices: %(choices)s)rF�choicesrzconfig z is broken: z@Config is broken.
Repair %(config_path)s or restore from backup.r)r>rrr*r Zwarningrrr
r8r9�joinr�get�KeyError�AttributeError�	TypeErrorr)	r!rDrErFr/�docrootr6rZmodule_inforrr�is_module_enabled}s2"zUserConfig.is_module_enabled)rDrErFrGc
Csyt||j�}WnBtk
rR}z$|j�|�ttd�d|id��Wdd}~XYnXttj	�
|j||��s~ttd�d|id��|tkr�ttd�|td�d��|��}|�
||||�s�dS|d||�|�|d||s�|d||=|d|�s|d|=|�|�dS)	Nz,Docroot for domain '%(domain)s' is not foundrD)r$r%z)Wrong wordpress path '%(wp_path)s' passedrEz9Invalid module %(module)s, available choices: %(choices)s)rFrIr)rrr*r r3rrr
r8r9rJrr>rP�remover7)r!rDrErFrOr6r/rrr�disable_module�s0
zUserConfig.disable_modulec
Cs&yt||j�}WnBtk
rR}z$|j�|�ttd�d|id��Wdd}~XYnXttj	�
|j||��s~ttd�d|id��|tkr�ttd�|td�d��|��}|�
||||�r�dSd|kr�i|d<||dkr�i|d|<||d|k�rg|d||<|d||�|�|�|�dS)	Nz,Docroot for domain '%(domain)s' is not foundrD)r$r%z)Wrong wordpress path '%(wp_path)s' passedrEz9Invalid module %(module)s, available choices: %(choices)s)rFrIr)rrr*r r3rrr
r8r9rJrr>rP�appendr7)r!rDrErFrOr6r/rrr�
enable_module�s4zUserConfig.enable_moduleccsRxL|��d��D]8\}}x.|��D]"\}}x|D]}|||fVq2Wq$WqWdS)Nr)r>r@)r!�doc_root�
doc_root_inforE�module_names�namerrr�enabled_modules�s
zUserConfig.enabled_modules)�module_namerGccs8x2|��D]&\}}}||kr
tj�|j||�Vq
WdS)zI
        Return absolute WP paths with specified module enabled.
        N)rYr8r9rJr)r!rZrUrErXrrr�wp_paths_with_enabled_module�sz'UserConfig.wp_paths_with_enabled_modulecsZd}xP|���di���D]8\}}x.|��D]"\}�|t�fdd�|D��7}q,WqW|S)z<
        Returns count of sites with enabled module
        rrc3s|]}|�kVqdS)Nr)�.0Zchecked_module_name)rWrr�	<genexpr>sz@UserConfig.get_enabled_sites_count_by_modules.<locals>.<genexpr>)r>rKr@�any)r!Zchecked_module_namesZsites_countrrVr)rWr�"get_enabled_sites_count_by_modules�s
"z-UserConfig.get_enabled_sites_count_by_modules)N)rrrrr8r9rJrZ
USER_WPOS_DIRZUSER_CLWPOS_CONFIGrZDEFAULT_MAX_CACHE_MEMORYr;r"r.r=r7r>rC�strr�boolrPrRrTrYrr[r_rrrrr%s

"('r)Z
__future__rr'r8rr+�typingrrZclwpos.optimization_modulesrZclwpos.logsetuprZclwpos.utilsrrr	Zclcommon.clwpos_libr
ZclwposrZclwpos.cl_wpos_exceptionsrr
rr�objectrrrrr�<module>s

Zerion Mini Shell 1.0