gddlZddlZddlZddlmZmZmZddlmZm Z m Z ddl m Z m Z ddlmZmZGddZdS) N)DictAnyOptional) ModuleStatusMODULES_STATUS_FILE MAIN_LOG_PATH) atomic_write setup_logger) NoSuchModuleMalformedConfigErrorceZdZdZdZdZedZdZdZ dZ dZ ed Z e j d Z d Zd Zd ZdZedZdS)Configz; Low-level logic of interaction with 'states' file cGdd}||_tdt|_|dS)NceZdZdZiZdS)Config.__init__..CfgN)__name__ __module__ __qualname__ worker_pidmodulesM/opt/cloudlinux/venv/lib64/python3.11/site-packages/clwizard/config/config.pyCfgrsJGGGrrz wizard.config)rr rlogreload)selfrs r__init__zConfig.__init__sU        ?? rci|j_|D]5\}}tj|did|jj|<6dS)a Forget about the previous config and create a new one with specified modules and instructions. {'cagefs': {'options': {'enable_for_new_users': True, 'enable_for_existing_users': True}}, 'mod_lsapi': {'options': {'use_beta_for_da': True}}, 'mysql_governor': {'options': {'mode': 'single'}}, 'php': {'options': {'install_versions': ['5.2', '5.3'], 'install_modules': False, 'default_version': '5.3'}}, 'nodejs': {'options': {'versions': ['7.4', '8.9'], 'default_version': '8.9'}}, 'python': {'options': {'versions': ['2.7', '3.6']}}, 'ruby': {'options': {'versions': ['2.7']}}} options)statusr!N)rritemsrPENDINGget)rr module_name instructionss r set_moduleszConfig.set_modules&sf)0   %K&.'++Ir::--DH [ ) )  rcRd|jjDS)z$Get dictionary with modules statusesc&i|]\}}||dS)r"r).0moduler!s r z#Config.statuses..@s#ZZZofg)ZZZr)rrr#rs rstatuseszConfig.statuses<s*[ZAQAWAWAYAYZZZZrc |jj|diS#t$r}t ||d}~wwxYw)z Get modules options (dictionary)r!Nrrr%KeyErrorr rr&es rget_module_optionszConfig.get_module_optionsBsV 38#K044YCC C 3 3 3{++ 2 3s%( AAAcx |jj|dS#t$r}t||d}~wwxYw)/Get modules states in format (see ModuleStatus)r"N)rrr2r r3s rget_module_statuszConfig.get_module_statusJsK 38#K0: : 3 3 3{++ 2 3s 949c |jj|dS#t$r}t ||d}~wwxYw)r7 status_timeNr1r3s rget_module_status_timezConfig.get_module_status_timeRsT 38#K044]CC C 3 3 3{++ 2 3s$' AAAc||jjvrt|||jj|d<tj|jj|d<dS)zSet new module stater"r:N)rrr time)rr& new_states rset_module_statuszConfig.set_module_statusZsV dh. . .{++ +2;%h/7;y{{%m444rc|jjS)z Get background worker process idrrr.s rrzConfig.worker_pidbsx""rc||j_dS)z$Set new background worker process idNrA)rnew_pids rrzConfig.worker_pidhs&rc|jjD]0\}}|dst |j|d1i|j_dS)z Reset self.Cfg object to default values before it will be loaded from file as a part of self.reload() __N)r__dict__r# startswithsetattrr)rkvs r _reset_cfgzConfig._reset_cfgnsa H%++-- + +DAq<<%% +!T***rcB||}|dS|d|j_|dD]E\}}|d|d|did|jj|<FdS)z Reset config object and load data from json config. :raises MalformedConfigError: cannot parse json config Npidrr"r:r!)r"r:r!)rK_read_json_configrrr#r%r)r json_datar&infos rrz Config.reloadys **,,   F'.!*9!5!;!;!=!=   Kx.#xx 6688Ir22--DH [ ) )  rcb|jj|jjd}||dS)z Dump python object state to file)rMrN)rrr_write_json_config)rstates rsavez Config.saves<8&x'   &&&&&rc tjtsdS t td5}t j|cdddS#1swxYwYdS#ttf$r3}|j dt|Yd}~dSd}~wttf$rC}|j dt|tt|d}~wwxYw)z{ Load state config and parse it using json :raises MalformedConfigError: cannot parse json config Nzutf-8)encodingz*Unable to load config file due to error %sz#Unable to load json config file, %s) config_path)ospathexistsropenjsonloadIOErrorOSErrorrerrorstr TypeError ValueErrorr )rfr4s rrNzConfig._read_json_configsDw~~122 4 O)G<<< $y|| $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $!    HNNGQ P P P44444:& O O O HNN@#a&& I I I&3FGGGQ N OsFA,A A,A##A,&A#'A,,D=(B++D?>C==Dctt5}tj||dddddS#1swxYwYdS)z%Write data to file using atomic write)indentN)r rr\dump)schemards rrRzConfig._write_json_configs- . . +! Ifa * * * * + + + + + + + + + + + + + + + + + +s :>>N)rrr__doc__rr(propertyr/r5r8r;r?rsetterrKrrTrN staticmethodrRrrrrrs-,[[X[ 333333333CCC##X# &&&   ('''OOO(++\+++rr)r\rXr=typingrrrclwizard.constantsrrrclwizard.utilsr r exceptionsr r rrrrrrs &&&&&&&&&&OOOOOOOOOO55555555 W+W+W+W+W+W+W+W+W+W+r