ó
b=0Yc           @   s„   d  d l  Z  d  d l Z d Z d Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d	 d d d
 „ Z
 d	 d d d d „ Z d S(   iÿÿÿÿNs   /etc/cagefs/cagefs.mps   /usr/sbin/cagefsctlt   CagefsMpConflictc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   d | t  | f |  _ d  S(   NsU   Conflict in adding '%s' to %s because of pre-existing alternative specification: '%s'(   t   CAGEFS_MP_FILENAMEt   _msg(   t   selft   new_itemt   existing_item(    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   __init__
   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   __str__   s    (   t   __name__t
   __module__R   R   (    (    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyR    	   s   	t   CagefsMpItemc           B   s¶   e  Z d  Z d Z d Z d „  Z d „  Z d „  Z d „  Z e	 e ƒ Z d „  Z
 d „  Z d	 „  Z d
 „  Z e	 e ƒ Z d „  Z e	 e ƒ Z d „  Z e	 e ƒ Z d „  Z d „  Z RS(   s   @!%t    t   !c         C   sG   | d  d k r d |  _ n' | j ƒ  d k r: d |  _ n	 | |  _ d S(   s¾   Constructor

        :param arg: Is either path to add to cagefs.mp or a raw line is read from cagefs.mp
        :param prefix: The same as adding prefix '!' to arg before passing it to ctori   t   #R   N(   t   Nonet
   _path_spect   strip(   R   t   arg(    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyR      s
    c         C   s;   |  j  ƒ  d k r7 | d k	 r7 d |  j | f |  _ n  |  S(   s%   Specify mode as in fluent constructort   @s   %s,%03oN(   t   prefixR   R   (   R   t   mode(    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyR   %   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyR   -   s    c         C   s,   |  d k r d S|  d d k r( |  d S|  S(   NR   t   /iÿÿÿÿ(    (   t   path(    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt
   _add_slash/   s
    c         C   sb   t  j | ƒ } |  j ƒ  s' | j ƒ  r+ t St  j |  j ƒ  ƒ } t  j | j ƒ  ƒ } | j | ƒ S(   N(   R
   t   _adoptt   is_dummyt   FalseR   R   t
   startswith(   R   t   anothert   adoptedt	   this_patht   test_preexist_in_path(    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   pre_exist_in7   s    c         C   s…   t  j | ƒ } |  j ƒ  s' | j ƒ  r+ t S|  j ƒ  | j ƒ  k rG t Si t  j g t  j 6} g  } |  j ƒ  | j | j ƒ  | ƒ k S(   N(	   R
   R   R   R   R   t   Truet   _PREFIX_MOUNT_ROt   _PREFIX_MOUNT_RWt   get(   R   t   existingR   t   prefix_compatibility_mapt   null_options(    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   is_compatible_by_prefix_withC   s    c         C   s   |  j  d  k S(   N(   R   R   (   R   (    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyR   S   s    c         C   s!   t  |  t ƒ r |  St |  ƒ Sd  S(   N(   t
   isinstanceR
   (   t   x(    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyR   U   s    c         C   s   |  j  d ƒ d S(   sj   Cut off mode from path spec like @/var/run/screen,777

        Only one comma per path spec is allowed ;-)t   ,i    (   t   split(   t	   path_spec(    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   _cut_off_mode\   s    c         C   s   |  j  t j ƒ S(   N(   t   lstripR
   t   _PREFIX_LIST(   R-   (    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   _cut_off_prefixd   s    c         C   s   t  j t  j |  j ƒ ƒ S(   N(   R
   R1   R.   R   (   R   (    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyR   g   s    c         C   s(   |  j  |  j ƒ  k r  |  j  d Sd Sd  S(   Ni    R   (   R   R   (   R   (    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyR   j   s    (   R   R	   R0   R#   R"   R   R   R   R   t   staticmethodR    R(   R   R   R.   R1   R   R   (    (    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyR
      s&   											c           C   s"   t  j j t ƒ o! t  j j t ƒ S(   N(   t   osR   t   existsR   t   CAGEFSCTL_TOOL(    (    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   is_cagefs_presentp   s    ií  c         C   ss   t  j j |  ƒ s" t  j |  ƒ n  | d  k	 rA t  j |  | ƒ n  | d  k	 ro | d  k	 ro t  j |  | | ƒ n  d  S(   N(   R3   R   t   isdirt   mkdirR   t   chmodt   chown(   R   R   t   owner_idt   group_id(    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   _mk_mount_dir_setup_permt   s    R   c   	         s  t  |  | | | ƒ t j t d g ƒ t t d ƒ } zÐ t | |  ƒ j | ƒ ‰  d „  | Dƒ } t ‡  f d †  | ƒ } | sÛ | j	 d d ƒ | j
 d d ƒ } | d	 I| IJ| ˆ  IJ| j ƒ  t j t d
 g ƒ n) ˆ  j | d ƒ st ˆ  | d ƒ ‚ n  Wd | j ƒ  Xd S(   sm  Add mount point to /etc/cagefs/cagefs.mp

    :param path: Directory path to be added in cagefs.mp and mounted
                 from within setup_mount_dir_cagefs().
                 If this directory does not exist, then it is created.

    :param added_by: package or component, mount dir relates to, or whatever will
                     stay in cagefs.mp with "# added by..." comment

    :param mode: If is not None: Regardless of whether directory exists or not prior this call,
                 it's permissions will be set to mode.

    :param owner_id: If group_id is also provided along:
                     Regardless of whether directory exists or not prior this call,
                     it's owner id will be set to.

    :param group_id: If owner_id is also provided along:
                     Regardless of whether directory exists or not prior this call,
                     it's group id will be set to.

    :param prefix: Mount point prefix. Default is mount as RW.
                   Pass '!' to add read-only mount point.
                   Refer CageFS section at http://docs.cloudlinux.com/ for more options.

    :returns: None

    Propagates native EnvironmentError if no CageFS installed or something else goes wrong.

    Raises CagefsMpConflict if path is already specified in cagefs.mp, but in a way which is opposite
    to mount_as_readonly param.
    s
   --check-mps   r+c         s   s   |  ] } | j  ƒ  Vq d  S(   N(   t   rstrip(   t   .0t	   file_line(    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pys	   <genexpr>¬   s    c            s   ˆ  j  |  ƒ S(   N(   R    (   R*   (   R   (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   <lambda>­   s    i    i   s   
t    s   # next line is added bys   --remount-alliÿÿÿÿN(   R=   t
   subprocesst   callR5   t   openR   R
   R   t   filtert   seekt   replacet   closeR(   R    (	   R   t   added_byR   R;   R<   R   t	   cagefs_mpt   trim_nl_itert   pre_exist_option(    (   R   s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   setup_mount_dir_cagefs   s"    "

(   R3   RC   R   R5   t	   ExceptionR    t   objectR
   R6   R   R=   RN   (    (    (    s5   /usr/lib/python2.7/site-packages/clcommon/clcagefs.pyt   <module>   s   	^	