|9eddlmZddlZddlZddlZddlmZddlmZm Z m Z ddl m Z m Z mZddlmZmZddlmZmZGd d eZdS) )absolute_importN) iteritems)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.pyCfgr sJGGGrrz wizard.config)rr r logreload)selfrs r__init__zConfig.__init__sU        ?? rci|j_t|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)rrrrPENDINGget)r r module_name instructionss r set_moduleszConfig.set_modules(sf)27););   %K&.'++Ir::--DH [ ) )  rcHdt|jjDS)z$Get dictionary with modules statusesc&i|]\}}||dS)r$r).0moduler#s r z#Config.statuses..Bs#]]]ofg)]]]r)rrrr s rstatuseszConfig.statuses>s&^]48K[A\A\]]]]rc |jj|diS#t$rt |wxYw)z Get modules options (dictionary)r#rrr&KeyErrorrr r's rget_module_optionszConfig.get_module_optionsDsP ,8#K044YCC C , , ,{++ + ,s %(Acn |jj|dS#t$rt|wxYw)/Get modules states in format (see ModuleStatus)r$)rrr3rr4s rget_module_statuszConfig.get_module_statusLsE ,8#K0: : , , ,{++ + ,s4c |jj|dS#t$rt |wxYw)r7 status_timer2r4s rget_module_status_timezConfig.get_module_status_timeTsN ,8#K044]CC C , , ,{++ + ,s $'Ac||jjvrt|||jj|d<tj|jj|d<dS)zSet new module stater$r:N)rrrtime)r r' new_states rset_module_statuszConfig.set_module_status\sV dh. . .{++ +2;%h/7;y{{%m444rc|jjS)z Get background worker process idrrr/s rrzConfig.worker_piddsx""rc||j_dS)z$Set new background worker process idNrA)r new_pids rrzConfig.worker_pidjs&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__items startswithsetattrr)r kvs r _reset_cfgzConfig._reset_cfgpsa H%++-- + +DAq<<%% +!T***rc8||}|dS|d|j_t |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#)rL_read_json_configrrrr&r)r json_datar'infos rrz Config.reload{s **,,   F'.!*9Y+?!@!@   Kx.#xx 6688Ir22--DH [ ) )  rcb|jj|jjd}||dS)z Dump python object state to file)rNrN)rrr_write_json_config)r states rsavez Config.saves<8&x'   &&&&&rctjtsdS t t5}t j|cdddS#1swxYwYdS#ttf$r3}|j dt|Yd}~dSd}~wttf$rB}|j dt|ttd}~wwxYw)z{ Load state config and parse it using json :raises MalformedConfigError: cannot parse json config Nz*Unable to load config file due to error %sz#Unable to load json config file, %s) config_path)ospathexistsr openjsonloadIOErrorOSErrorrerrorstr TypeError ValueErrorr)r fes rrOzConfig._read_json_configs=w~~122 4 H)** $ay|| $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $!    HNNGQ P P P44444:& H H H HNN@#a&& I I I&3FGGG G HsFA*A A*A!!A*$A!%A**C?;(B))C?==C::C?ctt5}tj||dddddS#1swxYwYdS)z%Write data to file using atomic write)indentN)r r r\dump)schemards rrSzConfig._write_json_configs- . . +! Ifa * * * * + + + + + + + + + + + + + + + + + +s :>>N)rrr__doc__r!r)propertyr0r5r8r;r?rsetterrLrrUrO staticmethodrSrrrrrs-,^^X^ ,,,,,,,,,CCC##X# &&&   ('''HHH(++\+++rr) __future__rr\rXr= future.utilsrtypingrrrclwizard.constantsrr r clwizard.utilsr r exceptionsrrobjectrrrrrvs'&&&&& """"""&&&&&&&&&&OOOOOOOOOO55555555 W+W+W+W+W+VW+W+W+W+W+r