ó
b=0Yc           @   s  d  Z  d d l Z d d l m Z d d l Z d d l Z d d l m Z m Z m Z d d l	 m
 Z
 d Z e ƒ  Z e j e ƒ d Z d Z d Z e j d	 d
 d d ƒ rÇ e j d	 d
 d d ƒ Z n  e j j e j j e ƒ d ƒ Z d „  Z e d „ Z d S(   s   
Library to work with plug-ins
iÿÿÿÿN(   t   ConfigParser(   t   CACHE_CPNAMEt   UNKNOWN_CP_NAMEt   UNKNOWN_CP_IMPORT(   t   PluginImportErrors   /etc/sysconfig/cloudlinuxt
   __cpname__t   detectt   sectiont   cpapit   optiont	   plugindirs
   apilink.pyc   	      B   s  e  j j e  j j e ƒ |  ƒ } g  e j e  j j | d ƒ ƒ D]( } e  j j e  j j | ƒ ƒ d ^ q@ } x¥ | D] } | d k r qu n  d } d |  | f } y | d UWn e	 d | f ƒ ‚ n Xe
 | e d ƒ } | ru e
 | e d ƒ } | r| ƒ  r| | f Squ qu Wd S(   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   *.pyi    t   __init__s   from %s import %s as apiNs   Can not import %s plugin(   NN(   t   ost   patht   joint   dirnamet   __file__t   globt   splitextt   basenamet   NoneR   t   getattrt   CONTROLPANELNAME_VARt   DETECTFUNCNAME_VAR(	   t   plugin_packt
   plugin_dirt   py_full_patht   modulest   mod_namet   apit   import_stringt   controlpanelnamet   detect_func(    (    s<   /usr/lib/python2.7/site-packages/clcommon/cpapi/pluginlib.pyt   detectplugin    s"    !Mc   
      C   sÁ  d } d } t  j j t  j j t ƒ | ƒ } t j | ƒ |  re t  j j |  ƒ re t j |  | ƒ n t  j	 | ƒ t  j
 | d ƒ t  j j | d ƒ } t | d ƒ j ƒ  y t | ƒ \ } } Wn. t k
 rð } d	 \ } } d t | ƒ GHn X| d  k r?t j | ƒ t  j	 | ƒ t | d ƒ j ƒ  t | ƒ \ } } n  | d  k rdt t } } d | GHn  | r½t t d ƒ } | j | ƒ | j ƒ  t t d ƒ }	 |	 j | d ƒ |	 j ƒ  n  d  S(
   Nt   cachet   pluginsií  s   __init__.pyt   ws   WARNING:sH   WARNING: can not detect control panel; the control panel is set to "%s" s   
(   NN(   R   R   R   R   R   t   shutilt   rmtreet   isdirt   copytreet   mkdirt   chmodt   opent   closeR!   R   R   t   strR   R   R   t   writet   API_LINK_PATH(
   t   pludins_dirt	   CACHE_DIRt   PLUGINS_PATHt	   cache_dirt	   init_pathR   t   cpnamet   et   cpname_cachet   api_link_stream(    (    s<   /usr/lib/python2.7/site-packages/clcommon/cpapi/pluginlib.pyt   rebuild_cacheC   s<    !
(   t   __doc__R   R    R   R%   t   constR   R   R   t   cpapiexceptionsR   t   CLSYSCONFIGt   clsysconfigt   readR   R   R   t   PLUGINS_DIRt
   has_optiont   getR   R   R   R   R/   R!   R9   (    (    (    s<   /usr/lib/python2.7/site-packages/clcommon/cpapi/pluginlib.pyt   <module>   s"   	!	#