ó
b=0Yc           @   sŽ   d  d l  Z  y d  d l Z Wn e k
 r5 d Z n Xd  d l m Z m Z d  d l m Z d Z	 d Z
 d   Z e	 d  Z d d d	  Z d e d
  Z d d d  Z d S(   i˙˙˙˙N(   t   NotSupportedt	   NoPackage(   t   ClPwds   /etc/psa/.psa.shadowt   Pleskc           C   s   t  j j d  S(   Ns   /usr/local/psa/version(   t   ost   patht   isfile(    (    (    s@   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/plesk.pyt   detect   s    c         C   sC   t    } d | d <t |   } | j   j   | d <| j   | S(   Nt   admint   logint   pass(   t   dictt   opent   readt   stript   close(   t
   _pass_patht   accesst   f(    (    s@   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/plesk.pyt	   db_access   s    	

t   psac      
   C   sž   t  s t d   n  |  p! t   } | j d d  } | d } | d } t  j d | d | d | d |  } | j   } d	 } | j |  g  | j   D] }	 |	 d
 ^ q }
 | j   |
 S(   Ns@   Can not connect to database; MySQL-python package not installed.t   hostt	   localhostR	   R
   t   usert   passwdt   dbs   SELECT login FROM sys_usersi    (	   t   MySQLdbR   R   t   gett   connectt   cursort   executet   fetchallR   (   t   _accsesst   _dbnameR   t   dbhostt   dblogint   dbpassR   R   t   sqlt   fetched_onet   cpusers_lst(    (    s@   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/plesk.pyt   cpusers!   s    

$#
c         C   s   t  d   d  S(   Ns|   Getting binding credentials in the database to the user name in the system is not currently supported. Is under development.(   R    (   t   cplogin_lstt   with_system_users(    (    s@   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/plesk.pyt   dblogin_cplogin_pairs1   s    c         C   sW  g  } | d k r< y t   } WqB t k
 r8 d } qB Xn | } g  } | d k	 ry g  | D] } | j d  ^ q[ } n  t d  } | j   } t |  t t f  rď d t	 f d     Y} i  } x* |  D] \ }	 }
 | |	 |
  | |	 <qÉ Wn  xa | D]Y } t
 |  r| | k rqö n  t j j | | j  } | | k rö | j |  qö qö W| S(   s  
    Detects and returns list of folders contained the home dirs of users of the DirectAdmin

    :param str|None _sysusers: for testing
    :param str|None _path: for testing
    :return: list of folders, which are parent of home dirs of users of the panel
    t   utf8i'  t   pwc           B   s   e  Z d    Z RS(   c         S   s   | |  _  | |  _ d  S(   N(   t   pw_namet   pw_dir(   t   selft   namet   dir(    (    s@   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/plesk.pyt   __init__S   s    	(   t   __name__t
   __module__R3   (    (    (    s@   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/plesk.pyR-   R   s   N(   t   NoneR(   R   t   encodeR   t   get_user_dictt
   isinstancet   listt   tuplet   objectt   lenR   R   t   dirnameR/   t   append(   t	   _sysuserst   _cpuserst   homedirst   resultst   userst   linet   clpwdt
   users_dictR-   R1   R2   t	   user_namet   homedir(    (    s@   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/plesk.pyRB   5   s0    	%(   R   R   t   ImportErrorR6   t   clcommon.cpapi.cpapiexceptionsR    R   t   clcommonR   t   PSA_SHADOW_PATHt
   __cpname__R   R   R(   t   FalseR+   RB   (    (    (    s@   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/plesk.pyt   <module>   s   
		