Re%@sdZddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZmZddlmZejeZGd d d ejZGd d d eZGd ddejZGdddeZddZdS)zBase option parser setup)absolute_importN) strtobool) string_types) UNKNOWN_ERROR) ConfigurationConfigurationError)get_terminal_sizec@s|eZdZdZddZddZdddd Zd d Zd d ZddZ ddZ ddZ dS)PrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.cOsCd|dz, cCsg}|jr#|j|jd|jr@|j|jdt|dkrb|jd||jr|jp|jj}|j|j |jdj |S)z Return a comma-separated list of option strings and metavars. :param option: tuple of (short opt, long opt), e.g: ('-f', '--format') :param mvarfmt: metavar format string :param optsep: separator rr ) _short_optsappend _long_optsleninsert takes_valuemetavardestlowerformatjoin)rrmvarfmtoptsepoptsr"rrrr$s   z*PrettyHelpFormatter._format_option_stringscCs|dkrdS|dS)NOptionsrz: r)rheadingrrrformat_heading;s z"PrettyHelpFormatter.format_headingcCs(dj|jtj|d}|S)zz Ensure there is only one newline between usage and the first heading if there is no description. z Usage: {} z )r% indent_linestextwrapdedent)rusagemsgrrr format_usage@sz PrettyHelpFormatter.format_usagecCs{|rst|jdr!d}nd}|jd}|j}|jtj|d}dj||}|SdSdS)NmainCommands Description z z{}: {} r)hasattrparserlstriprstripr-r.r/r%)r descriptionlabelrrrformat_descriptionIs  z&PrettyHelpFormatter.format_descriptioncCs|r |SdSdS)Nrr)repilogrrr format_epilog[sz!PrettyHelpFormatter.format_epilogcs/fdd|jdD}dj|S)Ncsg|]}|qSrr).0line)indentrr cs z4PrettyHelpFormatter.indent_lines..r6)splitr&)rtextrB new_linesr)rBrr-bs"z PrettyHelpFormatter.indent_linesN) __name__ __module__ __qualname____doc__rrrr,r2r=r?r-rrrrr s      r c@s"eZdZdZddZdS)UpdatingDefaultsHelpFormatterzCustom help formatter for use in ConfigOptionParser. This is updates the defaults before expanding them, allowing them to show up correctly in the help listing. cCs8|jdk r%|jj|jjtjj||S)N)r8_update_defaultsdefaultsrrexpand_default)rrrrrrNnsz,UpdatingDefaultsHelpFormatter.expand_defaultN)rGrHrIrJrNrrrrrKgs rKc@s.eZdZddZeddZdS)CustomOptionParsercOs6|j||}|jj|jj|||S)z*Insert an OptionGroup at a given position.)add_option_group option_groupspopr )ridxrrgrouprrrinsert_option_groupvs z&CustomOptionParser.insert_option_groupcCs;|jdd}x!|jD]}|j|jqW|S)zs zGConfigOptionParser._get_ordered_configuration_items..z7Ignoring configuration key '%s' as it's value is empty..r )r]r_itemsloggerdebugrDr)roverride_order section_items section_keyrisectionrhrrr _get_ordered_configuration_itemss  z3ConfigOptionParser._get_ordered_configuration_itemsc stjj_t}xnjD]`\}jddkrYq+jd kryt|}Wq~t k rt j|}j |Yq~Xnjdkr|j }fdd|D}njd kri|j jj}j||}jp8f}jpGi}j||||nj|}||j.callback)rwrxry)rValuesrMvaluessetrv get_optionactionr ValueErrorinvalid_config_error_messageerrorrDaddr#get_opt_string convert_value callback_argscallback_kwargsr{rkgetattr)rrM late_evalri error_msgopt_strrrr)rhrrrrLs:    "   z#ConfigOptionParser._update_defaultscCs|jstj|jSy|jjWn;tk rg}z|jtt |WYdd}~XnX|j |jj }xZ|j D]L}|j |j}t|tr|j}|j||||js     P w