
¡\\£  ã               @   sŸ   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l j	 j
 Z e j e ƒ Z d d „  Z d d „  Z d	 d
 „  Z d d „  Z d S)z*Contains UI methods for Apache operations.é    N)Úerrors)Ú
interfacesc             C   sš   |  s t  ƒ  Sd d „  |  Dƒ } t | ƒ rD | d	 d d
 … | d <t j j t j ƒ j d d | d d ƒ\ } } | t j	 k r– t
 | |  ƒ } | Sg  S)zóSelect multiple Vhosts to install the certificate for

    :param vhosts: Available Apache VirtualHosts
    :type vhosts: :class:`list` of type `~obj.Vhost`

    :returns: List of VirtualHosts
    :rtype: :class:`list`of type `~obj.Vhost`
    c             S   s    g  |  ] } | j  ƒ  d  ‘ q S)Ú
)Údisplay_repr)Ú.0Úvhost© r   ú</usr/lib/python3/dist-packages/certbot_apache/display_ops.pyú
<listcomp>   s   	 z)select_vhost_multiple.<locals>.<listcomp>é   NzJWhich VirtualHosts would you like to install the wildcard certificate for?ZtagsÚforce_interactiveTéÿÿÿÿr   r   )ÚlistÚlenÚzopeÚ	componentÚ
getUtilityr   ÚIDisplayZ	checklistÚdisplay_utilÚOKÚ_reversemap_vhosts)ÚvhostsZ	tags_listÚcodeÚnamesÚreturn_vhostsr   r   r	   Úselect_vhost_multiple   s    	r   c             C   sZ   t  ƒ  } xJ |  D]B } x9 | D]1 } | j ƒ  j ƒ  | j ƒ  k r | j | ƒ q Wq W| S)zmHelper function for select_vhost_multiple for mapping string
    representations back to actual vhost objects)r   r   ÚstripÚappend)r   r   r   Z	selectionr   r   r   r	   r   '   s    	r   c             C   s>   | s
 d St  |  | ƒ \ } } | t j k r6 | | Sd Sd S)zØSelect an appropriate Apache Vhost.

    :param vhosts: Available Apache VirtualHosts
    :type vhosts: :class:`list` of type `~obj.Vhost`

    :returns: VirtualHost or `None`
    :rtype: `~obj.Vhost` or `None`

    N)Ú_vhost_menur   r   )Údomainr   r   Útagr   r   r	   Úselect_vhost2   s    
r!   c             C   sÙ  t  j t d ƒ t d ƒ d } | d k  rI t j d ƒ d } d } n t | d ƒ } | | } g  } xà | D]Ø } t | j ƒ  ƒ d k r© t t | j ƒ  ƒ ƒ } n' t | j ƒ  ƒ d k rÊ d	 } n d
 } | j	 d j
 d t j j | j ƒ d | … d | d | … d | j rd n d	 d | j r2d n d	 d | d | ƒ ƒ qp Wy@ t j j t j ƒ j d j
 |  t j ƒ | d d ƒ\ } }	 Wn@ t j k
 rÎd j
 |  ƒ }
 t j |
 ƒ t j |
 ƒ ‚ Yn X| |	 f S)zÓSelect an appropriate Apache Vhost.

    :param vhosts: Available Apache Virtual Hosts
    :type vhosts: :class:`list` of type `~obj.Vhost`

    :returns: Display tuple - ('code', tag')
    :rtype: `tuple`

    ZHTTPSZEnabledé	   é   zFDisplay size is too small for certbot_apache.display_ops._vhost_menu()r   g333333ã?r   Ú zMultiple Namesz@{fn:{fn_size}s} | {name:{name_size}s} | {https:5s} | {active:7s}ÚfnNÚnameZhttpsZactiveZfn_sizeZ	name_sizezrWe were unable to find a vhost with a ServerName or Address of {0}.{1}Which virtual host would you like to choose?r   TzÝEncountered vhost ambiguity when trying to find a vhost for {0} but was unable to ask for user guidance in non-interactive mode. Certbot may need vhosts to be explicitly labelled with ServerName or ServerAlias directives.)r   ZWIDTHr   ÚloggerÚdebugÚintZ	get_namesÚnextÚiterr   ÚformatÚosÚpathÚbasenameZfilepZsslÚenabledr   r   r   r   r   ZmenuÚlinesepr   ZMissingCommandlineFlagZwarning)r   r   Z
free_charsZfilename_sizeZdisp_name_sizeÚchoicesr   Z	disp_namer   r    Úmsgr   r   r	   r   D   sB    !	
			r   )Ú__doc__Zloggingr-   Zzope.componentr   Zcertbotr   r   Zcertbot.display.utilZdisplayÚutilr   Z	getLoggerÚ__name__r'   r   r   r!   r   r   r   r   r	   Ú<module>   s   