� b=0Yc@sdZddlZddlmZddlZddlZddlmZmZmZddl m Z dZ e�Z e j e �dZdZdZe jd d d d �r�e jd d d d �Znejjejje�d �Zd�Zed�ZdS(s Library to work with plug-ins i����N(t ConfigParser(t CACHE_CPNAMEtUNKNOWN_CP_NAMEtUNKNOWN_CP_IMPORT(tPluginImportErrors/etc/sysconfig/cloudlinuxt __cpname__tdetecttsectiontcpapitoptiont plugindirs apilink.pyc Bsejjejje�|�}gejejj|d��D](}ejjejj|��d^q@}x�|D]�}|dkr�qund}d||f}y |dUWne d|f��nXe |e d�}|rue |e d�}|r|�r||fSququWdS(s� Scan directory for the presence of plugins. Plugin is considered a file with the extension "py", and with a non-empty variable "__cpname__" inside (the name of the control panel). Also in the file must be a function "detect" which returns True in the case of the presence of the control panel. >>> detectplugin('plugins') ('from .plugins import cpanel as api', 'cPanel') :param plugin_pack: package name or the name of the plug-ins directory ('cache' - cache plugins users; 'plugins' - officially supported plug-ins) :rtype: tuple :return: a pair of values​​: (line to import the package, the name of the control panel) s*.pyit__init__sfrom %s import %s as apiNsCan not import %s plugin(NN( tostpathtjointdirnamet__file__tglobtsplitexttbasenametNoneRtgetattrtCONTROLPANELNAME_VARtDETECTFUNCNAME_VAR( t plugin_packt plugin_dirt py_full_pathtmodulestmod_nametapit import_stringtcontrolpanelnamet detect_func((s</usr/lib/python2.7/site-packages/clcommon/cpapi/pluginlib.pyt detectplugin s"!M   c Cs�d}d}tjjtjjt�|�}tj|�|retjj|�retj||�n tj |�tj |d�tjj|d�}t |d�j �yt |�\}}Wn.tk r�}d \}}dt|�GHnX|dkr?tj|�tj |�t |d�j �t |�\}}n|dkrdtt}}d|GHn|r�t td�}|j|�|j �t td�} | j|d�| j �ndS( Ntcachetpluginsi�s __init__.pytwsWARNING:sHWARNING: can not detect control panel; the control panel is set to "%s" s (NN(R R RRRtshutiltrmtreetisdirtcopytreetmkdirtchmodtopentcloseR!RRtstrRRRtwritet API_LINK_PATH( t pludins_dirt CACHE_DIRt PLUGINS_PATHt cache_dirt init_pathRtcpnametet cpname_cachetapi_link_stream((s</usr/lib/python2.7/site-packages/clcommon/cpapi/pluginlib.pyt rebuild_cacheCs<!           (t__doc__R RRR%tconstRRRtcpapiexceptionsRt CLSYSCONFIGt clsysconfigtreadRRRt PLUGINS_DIRt has_optiontgetR RRRR/R!R9(((s</usr/lib/python2.7/site-packages/clcommon/cpapi/pluginlib.pyt<module>s"     ! #