<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import zope . component <EOL> from certbot import errors <EOL> from certbot import interfaces <EOL> import certbot . display . util as display_util <EOL> logger = logging . getLogger ( __name__ ) <EOL> def select_vhost ( domain , vhosts ) : <EOL> """<STR_LIT>""" <EOL> if not vhosts : <EOL> return None <EOL> while True : <EOL> code , tag = _vhost_menu ( domain , vhosts ) <EOL> if code == display_util . HELP : <EOL> _more_info_vhost ( vhosts [ tag ] ) <EOL> elif code == display_util . OK : <EOL> return vhosts [ tag ] <EOL> else : <EOL> return None <EOL> def _vhost_menu ( domain , vhosts ) : <EOL> """<STR_LIT>""" <EOL> free_chars = display_util . WIDTH - len ( "<STR_LIT>" ) - len ( "<STR_LIT>" ) - <NUM_LIT:9> <EOL> if free_chars < <NUM_LIT:2> : <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> filename_size = <NUM_LIT:1> <EOL> disp_name_size = <NUM_LIT:1> <EOL> else : <EOL> filename_size = int ( free_chars * <NUM_LIT> ) <EOL> disp_name_size = free_chars - filename_size <EOL> choices = [ ] <EOL> for vhost in vhosts : <EOL> if len ( vhost . get_names ( ) ) == <NUM_LIT:1> : <EOL> disp_name = next ( iter ( vhost . get_names ( ) ) ) <EOL> elif len ( vhost . get_names ( ) ) == <NUM_LIT:0> : <EOL> disp_name = "<STR_LIT>" <EOL> else : <EOL> disp_name = "<STR_LIT>" <EOL> choices . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( <EOL> fn = os . path . basename ( vhost . filep ) [ : filename_size ] , <EOL> name = disp_name [ : disp_name_size ] , <EOL> https = "<STR_LIT>" if vhost . ssl else "<STR_LIT>" , <EOL> active = "<STR_LIT>" if vhost . enabled else "<STR_LIT>" , <EOL> fn_size = filename_size , <EOL> name_size = disp_name_size ) <EOL> ) <EOL> try : <EOL> code , tag = zope . component . getUtility ( interfaces . IDisplay ) . menu ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( domain , os . linesep ) , <EOL> choices , help_label = "<STR_LIT>" , ok_label = "<STR_LIT>" ) <EOL> except errors . MissingCommandlineFlag as e : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( e , os . linesep ) ) <EOL> raise errors . MissingCommandlineFlag ( msg ) <EOL> return code , tag <EOL> def _more_info_vhost ( vhost ) : <EOL> zope . component . getUtility ( interfaces . IDisplay ) . notification ( <EOL> "<STR_LIT>" . format ( <EOL> os . linesep , "<STR_LIT:->" * ( display_util . WIDTH - <NUM_LIT:4> ) , str ( vhost ) ) , <EOL> height = display_util . HEIGHT ) </s>
