ok
Direktori : /opt/alt/python37/lib/python3.7/site-packages/clcommon/__pycache__/ |
Current File : //opt/alt/python37/lib/python3.7/site-packages/clcommon/__pycache__/utils.cpython-37.pyc |
B E!wd�n � @ sH d dl mZ d dl mZ d dl mZ d dlZd dlZd dlZd dlZd dlZd dl Z d dl Z d dlZd dlZd dl Z d dlmZ d dlmZmZ d dlmZmZmZmZmZmZ d dlZd dlmZ d dlZd d lmZ d d l m!Z!m"Z"m#Z#m$Z$ dZ%dZ&d Z'dd� Z(dpdd�Z)dd� Z*dd� Z+dd� Z,dd� Z-dqdd�Z.dd� Z/ee0 d �d!d"�Z1d#d$� Z2e3d �d%d&�Z4ee0 d �d'd(�Z5edd)�ee0 d �d*d+��Z6e7d,�d-d.�Z8e0e3d/�d0d1�Z9e3d �d2d3�Z:e3d �d4d5�Z;d6d7� Z<d8d9� Z=d:d;� Z>d<d=� Z?d>d?� Z@d@dA� ZAdBdC� ZBe0e3dD�dEdF�ZCe7e3dG�dHdI�ZDeee3 dJ�dKdL�ZEe7d �dMdN�ZFe0ee3e3f dO�dPdQ�ZGe0ee3e3f dO�dRdS�ZHe0ee3e3f dO�dTdU�ZIe0e3e3dV�dWdX�ZJee j e jKf e0dY�dZd[�ZLdre0e0e0e7ee7e0f d\�d]d^�ZMe0d �d_d`�ZNe3d �dadb�ZOe0ee7 dc�ddde�ZPe0df�dgdh�ZQe0df�didj�ZRdkdl� ZSe0e0dm�dndo�ZTdS )s� )�print_function)�absolute_import)�divisionN)� lru_cache)�ConfigParser�Error)�Dict�Any�AnyStr�Optional�Tuple�Union)�etree)� is_ubuntu)� check_command�run_command�exec_utility�ExternalProgramFailedz/etc/sysconfig/rhn/systemid)ZMonZTueZWedZThuZFriZSatZSunz /opt/cloudlinux/litespeed_statusc C sp d}t j�|�r4yt �|�}W n tk r2 Y nX | |krlyt �|� W n tk r^ Y nX t �| |� dS )a Create symlink link_path -> link_value if it does not exist or points to different location :param link_value: path that symlink should point to (symlink value) :type link_value: str :param link_path: path where to create symlink :type link_path: str N)�os�path�islink�readlink�OSError�unlink�symlink)Z link_valueZ link_pathZlink_to� r �?/opt/alt/python37/lib/python3.7/site-packages/clcommon/utils.py�create_symlink2 s r c C s6 g }t j�| �r2t| d|d��}|�� }W dQ R X |S )a Read file and return file's lines errors param may be passed to define how handle unicode errors, errors=None is default value of open() :param path: path to file :param unicode_errors_handle: how to handle unicode errors :return: list of file's lines �r)�errorsN)r r �isfile�open� readlines)r Zunicode_errors_handle�content�fr r r �get_file_linesI s r% c C s$ t | |��}|�|� W dQ R X dS )z� Write lines to file :param content: list of lines for writing to file :param path: path to file :param mode: open mode :return: None N)r! � writelines)r r# �moder$ r r r �write_file_linesZ s r( c s: t | �}� fdd�|D �}t|�t|�k}t| |d� |S )a Delete line from file. Return True when line(s) have been deleted, False otherwise (specified line is not found) :param path: path to file :type path: string :param line: line to delete without EOL (' ') :type line: string :rtype bool c s g | ]}� |� d �kr|�qS )� )�rstrip)�.0�item)�liner r � <listcomp>q s z)delete_line_from_file.<locals>.<listcomp>zw+)r% �lenr( )r r- Z file_linesZout_file_lines�foundr )r- r �delete_line_from_fileg s r1 c C sn t �� } | dkrjy,t�d�j}|t �� ks6t �� |kr:dS W n tk rP Y nX tdt j d� t �d� dS )zH Check whether current user is effectively root and exit if not r Z clsupergidNz'Error: root privileges required. Abort.)�file���)r �geteuid�grpZgetgrnam�gr_gid� getgroups�getegid�KeyError�print�sys�stderr�exit)Zeuidr6 r r r �is_root_or_exitx s r>