• File: clselectctlnodejsuser.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/clselect/__pycache__/clselectctlnodejsuser.cpython-37.pyc
  • Date Modified: 06/05/2023 11:47 AM
  • File size: 14.33 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

UdR@sddlmZddlmZddlmZddlZddlZddlZddlmm	m
ZddlZddl
mZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlm Z m!Z!ddl"m#Z#m$Z$ddl%m&Z&dZ'e#Z(d6ddZ)d7ddZ*ddZ+ddZ,d8ddZ-d9dd Z.d!d"Z/d:d#d$Z0d;d%d&Z1d<d'd(Z2d=d)d*Z3d>d+d,Z4d?d-d.Z5d@d0d1Z6d2d3Z7d4d5Z8dS)A)print_function)absolute_import)divisionN)ConnectionError)	iteritems)
basestring)clpassenger)clselectctl)utils)userdomains)mod_makedirs)ClSelectExcept)ApplicationsManager)environmentsinterpreters)APP_STARTED_CONSTAPP_STOPPED_CONST)clprintzapp.jsFcCsrt||}|s|}t|||}|r,|rnytjdd|}Wntk
r^t|YnX|j||d|S)Nversion)key)
destroy_first)	_get_prefixrEnvironmentexistsrKeyErrorrNoSuchAlternativeVersioncreate)user	directoryrenv_namerprefixenvironmentinterpreterr$O/opt/alt/python37/lib/python3.7/site-packages/clselect/clselectctlnodejsuser.py_create_environment$s
r&cCst||}|dkrRt|}yt|||}Wn"tk
rPtd|YnX|d}tj	
tj	tj	|}t
|||}|S)Nz8No such application (or application not configured) "%s"binary)rr	summaryrget_using_realpath_keysrrNoSuchApplicationospathbasenamedirnamerr)rrapp_summaryr!user_summaryr'r r"r$r$r%_get_environment2s

r1cCs t||\}}tjtj|S)N)rget_abs_relr+r,joinrZDEFAULT_PREFIX)rr_rel_dirr$r$r%rBsrcCs,ddlm}||s(t||ddS)z
    Check whether particular interpreter version is enabled and raises
    exception if not
    :param user: user to include in exception
    r)node_managerzversion is not enabledN)Zclselectnodejsr6ZNodeManageris_version_enabledrUnableToSetAlternative)rrr6r$r$r%_ensure_version_enabledGsr9cCsh|dkrt}t||\}}||}x:|D].}t||\}}|tj|tjr2|Sq2WdS)z
    Return None if new_app_directory is not nested inside an existing
    user application, and the name of conflicting application otherwise
    N)rrr2get_user_config_datakeysr+sep
startswith)Znew_app_directoryrapps_managerZabs_app_pathr4Zfull_configZexisting_appZexisting_app_abs_pathr$r$r%_get_existing_nesting_app_forSs
r?c
Cs\|	dkrt}	|dkr tdt|||dkr6t}|dkrBi}|dkrNd}t|||	}|dk	rlt|t|}t	|||}|
j}
tj
||||	j|
|||
dt|||st|}t|||}|d}|||t||g|d}|
r|
|d<|	|||y|	||||Wn:tk
rV}ztdd	t|d
Wdd}~XYnXdS)a
    Create application
    :param user: unix user name
    :param directory: application path in user's home (app-root)
    :param alias: alias (app-uri)
    :param version: version of interpreter
    :param doc_root: doc_root
    :param app_mode: application mode for nodejs
    :param env_vars: dict with enviroment variables
    :param startup_file: main application file
    :param domain_name: domain name
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :param passenger_log_file: Passenger log filename to write to app's .htaccess
    :return: None
    NzNot passed version as argument
production)doc_rootstartup_filepassenger_log_filedomain)nodejs_versionrDapp_uri
app_statusrBapp_modeZconfig_filesenv_varsrCtextERROR)statusmessage)rr	WrongDatar9DEFAULT_STARTUP_FILEr?BusyApplicationRootr
Z	get_aliasr&r#r'r	Z	configureINTERPRETERrestartr(rr)DEFAULT_APP_STATEZadd_app_to_configadd_env_vars_for_htaccess	Exceptionr
print_diagstr)rraliasrrArHrIrBdomain_namer>rCZconflicting_appr"r'Zsummary_datar/app_dataerrr$r$r%rfsP





rcCsd}tjt|j|d}tj|r`yt|Wqvtk
r\t	
dd|iYqvXntj|rvt	|tj|d}tj|st
|dyt||Wn"tk
rt	d|YnXdS)	z
    Creates symlink to app's node_modules in app_root
    :param username: user name
    :param environment_path: Path to app's virtual environment
    :param app_root: Application root
    :return: None
    zCloudlinux NodeJS Selector demands to store node modules for application in separate folder (virtual environment) pointed by symlink called "node_modules". That`s why application should not contain folder/file with such name in application rootZnode_modulesz"Can`t remove symlink %(link_name)s	link_namezlib/node_modulesizError creating symlink. N)r+r,r3pwdgetpwnampw_dirislinkremoveOSErrorrRemoveSymlinkErrorrSymlinkErrorr
symlinkCreateSymlinkError)usernameZenvironment_pathZapp_rootrMr\link_tor$r$r%_create_symlink_to_node_moduless$


ric
Cs|dkrt}|||}y|dk	r4|||d|Wn8tk
rn}ztddt|dWdd}~XYnX|dtkrt	
|j}d|d|g}yt
|Wntk
rYnX|dk	r||||}t||||yt||Wntjk
rYnXdSt||}	t||	\}
}yt
|
Wntk
rXYnXt|}|||}
yt|||Wn.tk
r|
rdStd|YnXt||yt||Wntjk
rYnXdS)	aa
    Destroy web app with specified directory for specified user
    :param user: username
    :param app_directory: application directory
    :param doc_root: Document root for selected domain
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :return: None
    NrJrK)rLrMrG/Znodevenvz8No such application (or application not configured) "%s")rget_app_configrTrUrrVrWgetrr]r^r_r3shutilrmtreerbget_htaccess_by_appdirr	$remove_passenger_lines_from_htaccessZremove_app_from_configrRrMissingApprootDirectoryrrr2r(r)rrNZunconfigure)r
app_directoryrAr>
app_configr[Z	user_homeZ
nodevenv_pathhtaccess_filenamer!abs_dirr4r0Z
app_in_configr$r$r%destroysX(


rvcCsn|dkrt}|||}|dkr0td||dtkrBdS|||||||tt	||dS)a`
    Starts web app with specified directory for specified user
    :param user: username
    :param app_directory: application directory
    :param doc_root: Document root for selected domain
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :return: None
    Nz8No such application (or application not configured) "%s"rG)
rrkrrNrlrZupdate_htaccess_fileset_app_statusr	rR)rrrrAr>rsr$r$r%startsrxcCs\|dkrt}|||}|dkr0td||dtkrLt|||nt||dS)ab
    Restarts web app with specified directory for specified user
    :param user: username
    :param app_directory: application directory
    :param doc_root: Document root for selected domain
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :return: None
    Nz8No such application (or application not configured) "%s"rG)	rrkrrNrlrrxr	rR)rrrrAr>rsr$r$r%rR:srRcCsz|dkrt}|||}|dkr0td||dtkrBdS|||||}t||	||tt
||dS)a_
    Stops web app with specified directory for specified user
    :param user: username
    :param app_directory: application directory
    :param doc_root: Document root for selected domain
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :return: None
    Nz8No such application (or application not configured) "%s"rG)rrkrrNrlrror	rprwrR)rrrrAr>rsrtr$r$r%stopSs
ryc
Csd}d}d}tjjtjt|s.tddj	||d}ddi}ytj
|d	|d
}WnXtk
r|dd}ytj
|d	|d
}Wn"tk
rt
||YnXYnX|j
d
}	|j
d}
|ytj
|d	|d
}Wn$tk
rt
||YnX|j
d
}|j
d}|	|ksv|
|krZ|
dk	rZ|
dddksv|dk	r|dddkrt
|||	|fdS)a@
    Check response from user's webapp before and after calling action.
    Also compare both responses
    :param domain: domain associated with webapp
    :param alias: URI associated with webapp
    :param action: called action, that make something with webapp: install modules, transit it, etc
    :return: None
    zTWeb application is inaccessible by its address "%s". The operation wasn't performed.zThe operation was performed, but check availability of application has failed. Web application is inaccessible by its address "%s" after the operation.zThe operation was performed, but check availability of application has failed. Web application responds, but its return code "%s" or content type before operation "%s" doesn't equal to contet type after operation "%s".z+Wrong action for calling in checking webappzhttps://{domain}/{alias})rDrXz
User-AgentzjMozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 CentOS/3.6-2.el5.centos Firefox/3.6.13F)verifyheaderszhttps://zhttp://zContent-TypeZStatusN500)requestspackagesurllib3disable_warningsurllib_exceptionsInsecureRequestWarningcallablerrNformatrlrreplaceWebAppErrorr{lower)
rDrXactionZapp_is_inaccessible_beforeZapp_is_inaccessible_afterZ
app_is_brokenZ
webapp_urlr{requestZbefore_mime_typeZ
before_statusZafter_mime_typeZafter_statusr$r$r%check_response_from_webappqs>

&rcsndkrtddkr$tdd}t}fdd|D}t|dkr^td|d}||fS)	z
    Get info (alias and domain) about user's web application
    :param app_summary: dict -> summary info about user's web application
    :param user: str -> name of unix user
    :return: tuple -> (alias, domain)
    Nz3Was passed incorrect summary info about applicationz!Was passed incorrect name of userrXcs&g|]\}}t|dr|qS)docroot)rrealpaths_are_equal).0rDrA)r/rr$r%
<listcomp>sz*_get_info_about_webapp.<locals>.<listcomp>rz-Can not found suitable domain for application)rrNrlen)r/rrXZuser_domainsZ
found_domains
app_domainr$)r/rr%_get_info_about_webapps


r-c

s|dkrt}|}yt|}Wn$tk
rNtdYnX|dtkrbd}n|d}|d}|d}	t	\}
t
|	fdd	}|syt|||d
Wqtjk
r}ztd|Wdd}~XYqXn|dS)a
    Install nodejs extension to user's webapp
    :param user: name os unix user
    :param directory: directory with webapp (app-root)
    :param extension: name and version of extension
    :param skip_web_check: skip check web application after change it's properties
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :return: None
    Nz%Record about application {} is absentrGTrFrDrEcsjdtdS)N)	extensioncwd)Zextension_installr	rRr$)rrr"rrr$r%rszinstall.<locals>.action)rDrXrz3An error occured during installation of modules. %s)
rr:rr)rrrNrrr2r&rr)
rrrZskip_web_checkr>user_configrZrXrrEr4rr[r$)rrr"rrr%installs0
"rcCsi}xtt|D]r\}}|dtjkr,qt|||}|d|d|d|dd||<d|krt|ddkr|d||d<qW|S)Nr#rDrXname)rDrXr"r#domainsr)rr	r(rrQr1Zas_deepdictr)rZsummrdatar"r$r$r%r(sr(cCs4t|tk	rtx|D]}t||tstqW|S)N)typedict	TypeError
isinstancer)rIitemr$r$r%validate_env_varss
r)NF)N)N)NNNNNNNN)N)N)N)N)N)NN)rFN)9
__future__rrrr+r]r~Z$requests.packages.urllib3.exceptionsrr
exceptionsrrmZrequests.exceptionsrfuture.utilsr
past.builtinsrr	r
rclcommon.cpapirclcommon.utilsr
clselectexceptrZclselectnodejs.apps_managerrZclselectnodejsuserrrZbaseclselectrr
clselectprintrrOrSr&r1rr9r?rrirvrxrRryrrrr(rr$r$r$r%<module>sN



E"
O



9

/