%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/
Upload File :
Create Path :
Current File : //opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyc

�
i�B^c@`srddlmZddlmZddlmZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
Z
ddlmZmZddlmZdd	lmZmZmZdd
lmZddlmZmZmZddlmZdd
lm Z de!fd��YZ"de!fd��YZ#defd��YZ$e%d�Z&dS(i(tprint_function(tdivision(tabsolute_importN(tAnyStrtOptional(t	iteritems(tget_abs_reltrun_process_in_cagefs(tdrop_privileges(tBaseSelectorErrortMissingVirtualenvErrortMissingAppRootError(t	WSGI_PATH(tClSelectExcepttclpassengertclselectctl(tBaseApplicationsManager(t
PythonManagertPythonAppFormatVersioncB`seZdZdZdZRS(s@
    Class represents possible python application versions.
    ii(t__name__t
__module__t__doc__tLEGACYtSTABLE(((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyR#stPythonVenvFormatVersioncB`seZdZdZdZRS(sJ
    Class represents possible python application venv path versions.
    ii(RRRRR(((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyR.stApplicationsManagercB`s�eZdZdZdZdZdZdZdZdZ	d�Z
dd�Zed	��Z
d
�Zd�Zdd�Zdd
�Zd�Zd�Zd�Zd�Zdd�Zd�Zdd�Zd�Zeed�Zdd�ZRS(s!.cl.selector/python-selector.jsons/var/lve/.py.migration.statuss!.cl.selector/.py.migration.statuss//var/log/cloudlinux/py-selector/app_imports.logsimported_pip_requirements.txttpythont
virtualenvcC`stt|�jt��dS(N(tsuperRt__init__R(tself((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyRDscC`stt|�j||d|�S(Ntpatterns(RRt_find_config_files(Rt	user_namet
app_directoryR((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyR HscC`sdj|�g}|S(s�
        Return lines for htaccess that are specific to the python interpreter
        :param binary_path: path to the environment's python binary
        :param app_config: application's config dictionary
        sPassengerPython "{}"
(tformat(tbinary_patht
app_configtspecific_lines((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyt(get_interpreter_specific_passenger_linesLscC`s-ddlm}i}i}|j|�}x�ttj|��D]�\}}|d|jkrfqAnyutjj	|dtj
�}	tjj|	�s�|jd|�wAnt
|	��}
|
j�}WdQX|j|�}|r|j�}
|
d}|
d}n
d	}}tjjtjjtjj|d
���}|dd}y||d}Wntk
rztj}nXi	|d
6|d6|d6|dd6dd6|p�t
d6gd6id6|p�dd6}|||<WqAtk
r|jd|�|j|g�jd|�qAqAXqAW||fS(s
        Search server for old applications (created in old python selector)
        and add them to new config.
        :param user: user to search applications
        :param logger: logger to write messages to
        :return: tuple(list[applications], list[errors])
        i(tWSGI_PATTERNtinterpretert	directorysIApplication %s was skipped during import, because wsgi file was not foundNtscripttcallablettbinarytdomainsuapp_versionupython_versionudomaintaliasuapp_uritstartedu
app_statusustartup_fileuconfig_filesuenv_varstapplicationuentry_pointsUnable to import application %ss�Unexpected issue during application "%s" import. Your python app will work as before, but you wo't be able to control it from Python Selector UI. Please, ask your system administrator to contact CloudLinux support to resolve this issue.(tclselect.clselectctlpythonR(tget_user_config_dataRRtsummarytINTERPRETERtostpathtjoinRtisfiletwarningtopentreadtsearcht	groupdicttbasenametdirnametKeyErrorRRt	Exceptiont	exceptiont
setdefaulttappend(RtusertloggerR(tapplicationsterrorstuser_config_dataR*tdatatapp_wsgitft	wsgi_conftmatchR?t	wsgi_pathtcallable_objectt
py_versiontdomaintapp_vertapp_info((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyt_get_legacy_applicationsVs\"	






cC`sptjd�}|jtj�tj|j�}tjd�|_tj�}|jtj	�|j
|�|S(s6
        Setup logger for application import.
        timport_appss*[%(levelname)s | %(asctime)s]: %(message)s(tloggingt	getLoggertsetLeveltDEBUGtFileHandlert_IMPORT_LOG_FILEt	Formattert	formattert
StreamHandlertINFOt
addHandler(Rt
app_loggertfhtcl((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyt_setup_import_logger�s
cC`sW|j�}|j|�}tjdt|j���g}d}d}x�t|�D]�\}}tj	j
|jd�}tj	j|�s�|d7}|j
d||f�qVn|jd|�y�t|��xtj��ey"|j|j|j|j�}	Wntk
ri}	nX|j||�\}
}|
s@wVnWdQXWdQXx�t|
�D]�\}}||	kr�|	|d|d<|	|d	|d	<n|j|||�tj	j
|j||j�}
tj	j|
�r|j|dkr|dj|j�n||	|<qYWt|	j��t|
j��}x|D]}|	j|�q<Wt|��Atj��.|j||	�|j|d
td|�WdQXWdQXWqVt k
r%}dd
d}|j!|||�t|��1tj��|j|d
t"d|�WdQXWdQX|j|�qVXqVW|j#|�|dkrS|j
d�ndS(s�
        Scan users for legacy applications (created by old python selector)
        and import them into config file. Done automatically by spec file.
        s&Start applications import for users %sis.cl.selectoris-User %s is skipped due to %s directory absentsImporting user %sNtconfig_filestenv_varstis_import_failedtapps_errorss3Unable to import user `%s` to new python selector. s-Already created applications work as before, s5but user won't be able to manage them. Error is: `%s`s$Some users skipped... see import log($Rgtget_users_dictRYtdebugtlisttkeystNoneRR7R8R9tpw_dirtisdirR;tinfoRtsecureiot
disable_quotatread_user_selector_config_jsontpw_uidtpw_gidR	RWtgenerate_pip_requirementst_IMPORT_REQUIREMENTS_FILER:RFtsettpoptwrite_full_user_config_datat_set_user_legacy_import_statustFalseRCRDtTruet_set_admin_legacy_import_status(RRGRdt
users_infotfailed_userstskipped_users_countRktpwtcl_selector_dirtconfigtappstapp_rootR%trequirements_filetdestroyed_appstetimport_error((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyt$import_legacy_applications_to_config�sh




"


)

%
cC`s�|dkrMtjj|j�s%dSt|j��}tj|�SWdQXnbtj	|�}tjj
|j|j�}tjj
|�s�dSt|��}tj|�SWdQXdS(sz
        Read import log which contains information about
        failed users or apps depending on current user.
        N(RpR7R8texistst_IMPORT_STATUS_ADMINR<tjsontloadtpwdtgetpwnamR9Rqt_IMPORT_STATUS_USERR:(RRGRNtuser_pwtmarker((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyt_get_legacy_import_status�scC`s�tjjtjj|jd��s(dSyItjj|j|j�}tjtj	i|d6|d6�|d�Wn$t
tfk
r�tj
d�nXdS(s�
        Save information that some applications were not imported automatically
        to show warning for user in the future.
        s.cl.selectorNRjtapps_lookup_failedi�s$Unable to save migration status file(R7R8R�R9RqR�Rttwrite_file_via_tempfileR�tdumpstIOErrortOSErrorRYRD(RR�RjRkR�((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyR~s$
cC`s0tji|d6�}tj||jd�dS(s�
        Save information that some users were not imported automatically
        to show warning for admin in the future.
        R�i�N(R�R�RtR�R�(RR�tpacked((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyR�scC`s\|j�}|dks#|dr'dSdjddj|d�d|jd|j�}|S(NR�s�Unexpected issue(s) happened during importing python applications for the following users: "{users}". Everything will work as before, but listed users wo't be able to control applications from Python Selector UI. Please, contact CloudLinux support and send them log file located at `{log_file_path}` to investigate and resolve this issue. Also you can hide this warning by deleting `{import_warning_marker}` filetuserst,t
log_file_pathtimport_warning_marker(R�RpR#R9R^R�(RR�twarning_msg((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyt _get_admin_legacy_import_warning$s		cC`sr|jd|�}|dkr"dSdjd|j�}|drId|S|drnddj|d�|fSdS(	NRGsEverything will work as before, but you won't be able to control listed applications from Python Selector UI. Please, ask you hoster to contact CloudLinux support to investigate and resolve this issue.
Also you can hide this warning by deleting `~/{import_warning_marker}` file.R�RjsEUnexpected issue(s) happened during importing python applications. %sR�sUUnexpected issue(s) happened during importing following python applications: "%s". %sR�(R�RpR#R�R9(RtusernameR�twhat_to_do_msg((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyt_get_user_legacy_import_warning6s	

cC`s'|dkr|j�S|j|�SdS(N(RpR�R�(RRG((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyt"_get_legacy_import_warning_or_noneNs
cC`s�ddlm}|j||�}|d	krDtjd|��n|dtjkrmtjd|��n|||d|�}y|jdt	�Wn,t
k
r�}tjd||f��nXtj|d<|j|||�d	S(
so
        Update environment of specific application to support
        features of new python selector
        i(t_get_environmentsApplication %s does not existtapp_versionsCApplication %s is already new version and does not need any updatestapps_managertauto_restores�Unable to migrate application %s. Error is '%s', everything restored to work as before migration. Try again later or ask your hoster to contact CloudLinux support if the issue persists.N(R3R�tget_app_configRpR
t	WrongDataRRtconfigure_environmentR�RCtadd_app_to_config(RRGR�R�R2tenvironmentR�((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pytmigrate_applicationTs"

cC`sDtt|�j|�}|j|�}|dk	r@||d<n|S(NR;(RRtget_applications_users_infoR�Rp(RRGtresultR;((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyR�qs	
cC`srt||�\}}tjj||j�}tjj|�rCdSddlm}t|��&|||d|�}|j	�}	WdQXt
j|�j}
i|
d6}d}t
||	ddgd	|�}
|
d
dkr|jdt|
d��tj|
d��n|
d
s"|
d}nt|��>tj��+t|d�}|j|�|j�WdQXWdQXdS(s�
        Generates requirements file from python apps
        :param user: username
        :param app_root: app root
        :param app_logger: app logger
        Ni(R�R�tHOMER-tfreezes-lRit
returncodes/Error during generation pip requirements file. toutputtfailedtw(RR7R8R9RzR�R3R�RtpipR�R�RqRR;tstrR
tExternalProgramFailedRtRuR<twritetclose(RRGR�Rdtapp_patht_treq_pathR�R�tpip_patht	user_homeRitmodulesR�RN((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyRyys.






c	C`s�|jj|�j}t||�\}}tjj||�}|rgtjj|�rgt|��ntjj||�}|r�tjj|�r�t	|��n||fS(s
        Calculate, check exists and return application folders
        This method does not check that application exists in config.
        :raises: NoSuchUserException, MissingVirtualenvError, MissingAppRootError
        :return: tuple(app_root, app_venv) with absolute paths
        (
t_pwdtget_pw_by_nameRqtget_venv_rel_pathR7R8R9R�R
R(	RR�R�tchk_envtchk_app_rootR�R�trel_pathtapp_venv((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pytget_app_folders�scC`s[|j||�}|dkr*|j}nt||�\}}tjj|||d|�S(s�
        Return a path to the environment's interpreter binary
        Get interpreter path for application
        :param user: owner of the application
        :param app_root: app path relative to user home (app-root)
        :param user_dir: User's home directory
        :param binary_name: name of binary in virtual environemnt (python, npm, node)
        :return: path to interpreter binary in virtual environment
        tbinN(tget_interpreter_version_for_appRptBINARY_NAMER�R7R8R9(RRGR�tuser_dirtbinary_nametversionR�R�((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pytget_binary_path�s

(N(RRt_USER_CONFIGR�R�R^RzR6tVENV_DIRR�RR tstaticmethodR'RWRgRpR�R�R~R�R�R�R�R�R�RyR�R�R�(((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyR:s2	
	F	L						&cC`s�t|tjjtj|��\}}t|tjjtjtj|���\}}|dkr�tjj	|�r�|tj|�kr�t
j|fSt
j|fS|t
jkr�t
j|fS|t
jkr�t
j|fSt
d|��dS(s6
    Get path to users VENV relative to home dir.
    Old python selector transforms app_root using get_prefix() method
    before creating venv directory. We should handle both cases:
     - when app is from old selector
     - when app is from new selector
    and return right env directory.
    If both old and new vevns exist we use old one.
    Return tuple with two values:
    - detected version of venv path (LEGACY for
      path with replacements "/" -> "_" & "_" => "__"
      and STABLE in other case)
    - path to venv relative to user's home dir
    sunknown version `%s`N(RR7R8R9RR�Rt
get_prefixRpR�RRRt
ValueError(RGR*R�R�tnew_rel_dirtold_abs_dirtold_rel_dir((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyR��s'-'



('t
__future__RRRRYR7R�R�ttypingRRtfuture.utilsRRttclselect.utilsRRtclcommon.clpwdRtclselect.baseclselectR	R
Rtclselect.clpassengerRtclselectR
RRt"clselect.baseclselect.apps_managerRt&clselect.clselectpython.python_managerRtobjectRRRRpR�(((sU/opt/alt/python27/lib/python2.7/site-packages/clselect/clselectpython/apps_manager.pyt<module>s*��

Zerion Mini Shell 1.0