g ddlZddlZddlZddlmZddlmZddlZddlm Z ddl m Z eddZ d Z d Zd Zd Zd ZdS)N)contextmanager)Iterable)CRASH_LOG_PATH)PackageMissingErrorTc#K|dz} t|dd5}|V|r:|tj|dddn #1swxYwYtj|| tj|dS#ttf$rYdSwxYw# tj|w#ttf$rYwwxYwxYw)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.tmpwutf-8encodingN) openflushosfsyncfilenorenameremoveIOErrorOSError)filepathrtmppathfs E/opt/cloudlinux/venv/lib64/python3.11/site-packages/clwizard/utils.py atomic_writersKG  '3 1 1 1 %QGGG % $$$  % % % % % % % % % % % % % % % '8$$$  Ig     !    DD   Ig    !    D seB7AA( B7(A,,B7/A,0B7 BB43B47C%9C C%C"C%!C""C%cd}tjD]H} t|}n#tj$rY6wxYw||rdSIdS)zQ Detects if the process installing modules is running in the background. cVhdt|kphdt|kS)N>/usr/sbin/cloudlinux-wizardinstall --no-async>/sbin/cloudlinux-wizardrr)set)cmdlines r_is_wizard_cmdlinez9is_background_process_running.._is_wizard_cmdline0s8 E D DG T TCCCs7||S TF)psutil process_iterlistr" NoSuchProcess)r#procr"s ris_background_process_runningr*+s    #%%    4<<>>**GG#    H   g & & 44  5s!<A Actttdd}tj|tj||S)Nr r r )stdinstdoutstderr)r r subprocessPopenDEVNULL)cmd log_crashs rrun_backgroundr4Es?^S7;;;I        r$cl ddlm}n"#t$r}td|d}~wwxYw||S)Nr)"interpreter_versions_short_summary lvemanager)clselect.clselectctlr6 ImportErrorr) interpreterr6es rinstalled_interpreters_listr<Os\7KKKKKKK 777!,//Q67 - -k : ::s (#(cbd|dd|S)z Format version string e.g: 3.6.0 -> 3.6 if version size = 2 9.11.3 -> 9 if version size = 1 :param version given version to convert :param version_size expected size of result version string .N)joinsplit)version version_sizes rconvert_package_versionrCWs+ 88GMM#&&} }5 6 66r$ctj|}|tj tj|}tjd|_||n#t$rYnwxYw|S)z3 Logger setup for all modules :return: z*[%(levelname)s | %(asctime)s]: %(message)s) logging getLoggersetLevelINFO FileHandler Formatter formatter addHandlerr) logger_namelog_file app_loggerfhs r setup_loggerrQcs ";//J %%%"   * *( 8:: b!!!!      sA88 BB)T)rErr/ contextlibrtypingrr% constantsr exceptionsrrr*r4r<rCrQr$rrWs %%%%%% %%%%%%++++++,4;;; 7 7 7r$