ó 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]}|dkrqund}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.pyts"     ! #