Edit File: utils.cpython-37.opt-1.pyc
B 5/9e: � @ s� d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ ddl m Z ddlmZ d dl Z edd d ��Zdd� Zd d� Zdd� Zdd� Zdd� ZdS )� )�absolute_importN)�contextmanager)�Iterable� )�CRASH_LOG_PATH)�PackageMissingErrorTc c s~ | d }zFt |d��&}|V |r6|�� t�|�� � W dQ R X t�|| � W dyt�|� W n ttfk rv Y nX X dS )z� Writeable file object that atomically updates a file (using a temporary file). :param filepath: the file path to be opened :param fsync: whether to force write the file to disk z.tmp�wN) �open�flush�os�fsync�fileno�rename�remove�IOError�OSError)�filepathr Ztmppath�f� r �py/clwizard/utils.py�atomic_write s r c C sT dd� } xFt �� D ]:}yt|�� �}W n t jk r> wY nX | |�rdS qW dS )zQ Detects if the process installing modules is running in the background. c S s$ dddht | �kp"dddht | �kS )Nz/usr/sbin/cloudlinux-wizardZinstallz --no-asyncz/sbin/cloudlinux-wizard)�set)�cmdliner r r �_is_wizard_cmdline2 s z9is_background_process_running.<locals>._is_wizard_cmdlineTF)�psutilZprocess_iter�listr Z NoSuchProcess)r �procr r r r �is_background_process_running- s r c C s( t tjd�}t td�}tj| |||d�S )Nr )�stdin�stdout�stderr)r r �devnullr � subprocess�Popen)�cmdZfnullZ log_crashr r r �run_backgroundG s r% c C s6 yddl m} W n tk r, td��Y nX || �S )Nr )�"interpreter_versions_short_summaryZ lvemanager)Zclselect.clselectctlr&