
                             S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	J
r
  SSKr " S S	\R                  5      rg)
zconfig format resource printer.    )absolute_import)division)unicode_literalsN)resource_printer_base)	platformsc                   f   ^  \ rS rSrSrU 4S jrS rS r\S 5       r	SS jr
SS jrSS	 jrS
rU =r$ )ConfigPrinter   a5  Prints a dictionary of dictionaries in config style.

A dictionary of dictionaries in config style.

Printer attributes:
  export: Display the dictionary as a list of system specific
    environment export commands.
  unset: Display the dictionary as a list of system specific
    environment unset commands.
c                   > [         [        U ]
  " USS0UD6  SU R                  ;   aD  U R                  U l        [        R                  R                  5       (       a  SU l	        OmSU l	        OeSU R                  ;   aD  U R                  U l        [        R                  R                  5       (       a  SU l	        OSU l	        OU R                  U l        S	U R                  ;   a,  U R                  R                  U R                  S	   S
-   5        g g )Nretain_none_valuesTexportzset {name}={value}
zexport {name}={value}
unsetzset {name}=
zunset {name}
title
)superr	   __init__
attributes_PrintEnvExport
_add_itemsr   OperatingSystem	IsWindows_env_command_format_PrintEnvUnset_PrintConfig_outwrite)selfargskwargs	__class__s      2lib/googlecloudsdk/core/resource/config_printer.pyr   ConfigPrinter.__init__+   s    	-' 2$ 2*024??",,do		"	"	,	,	.	.#9 #< 	DOO	#++do		"	"	,	,	.	.#2 #3 ))do$//!
iioodoog.56 "    c                 t   [         R                  " 5       n[         R                  " 5       n[        U5       HH  u  pg[        R                  " U5      n [        R
                  " U5      nU R                  XRU/-   U5        MJ     UR                  5       n	UR                  5       n
U(       aS  U	(       d  U
(       aE  U
R                  S5      (       d/  UR                  SR                  SR                  U5      5      5        U	(       a  UR                  U	5        U
(       a  UR                  U
5        gg! [         a     Of = fUc!  UR                  SR                  US95        GM,  [        U[        5      (       a"  U R                  XRU/-   [        U5      5        GMc  UR                  SR                  XgS95        GM  )	zPrints config items in the label category.

Args:
  out: The output stream for this category.
  label: A list of label strings.
  items: The items to list for label, either dict iteritems, an enumerated
    list, or a scalar value.
N{name} (unset)
namez{name} = {value}
r'   value[z[{0}]
.)ioStringIOsortedsix	text_type	iteritems_PrintCategoryAttributeErrorr   format
isinstancelist	enumerategetvalue
startswithjoin)r   outlabelitemstopsubr'   r)   valuestop_contentsub_contents              r!   r2   ConfigPrinter._PrintCategory@   sM    ++-C
++-Ce}]]4 du%C$8 % ,,.K,,.K+k&<&<S&A&A	ii	  %12	ii	ii   			$+++67eT""C$51AB		&--4-EFs   ,D..
D;:D;c                 >    U R                  U R                  / U5        g)zoPrints config items in the root category.

Args:
  items: The current record dict iteritems from _AddRecord().
N)r2   r   )r   r=   s     r!   r   ConfigPrinter._PrintConfigc   s     			2u-r#   c                 l    [        U[        5      (       a  S[        R                  " U5      -   nX-   S-   $ )z.Returns a new prefix based on prefix and name.I_)r5   intr/   r0   )prefixr'   s     r!   _PrefixConfigPrinter._Prefixk   s1     $3==&&d=3r#   c           	      *   [        U5       GH  u  p4[        R                  " U5      n[        U[        5      (       a5  U R                  [        R                  " U5      U R                  X#5      S9  Mf  Uc,  U R                  R                  SR                  X#-   S95        M  [        U[        5      (       az  [        U5       Hh  u  pV[        U[        5      (       d  S[        R                  " U5      -   U0nU R                  [        R                  " U5      U R                  X#5      S9  Mj     GM$  [        R                  " [        R                  " U5      5      nU R                  R                  U R                  R                  X#-   US95        GM     g)a'  Prints the environment export commands for items.

Environment variable names have '_' instead of '.'.  Array values have
subscripts expanded as names *_I0, *_I1, ...

Args:
  items: The current record dict iteritems from _AddRecord().
  prefix: Parent name prefix, prepended to each item name.
rJ   Nr%   r&   rG   r(   )r.   r/   r0   r5   dictr   r1   rK   r   r   r4   r6   r7   shlexquoter   r   r=   rJ   r'   r)   ivs          r!   r   ConfigPrinter._PrintEnvExportr   s6    e}]]4 d	E4	 	 S]]51$(LL$> 	 	@=		*11v}1EFeT""e$DAAt$$s}}Q''+A


s}}Q/&*ll6&@  B % CMM%01		0077e 8 - 	. %r#   c           	      t   [        U5       GH(  u  p4[        R                  " U5      n[        U[        5      (       a5  U R                  [        R                  " U5      U R                  X#5      S9  Mf  [        U[        5      (       ay  [        U5       Hh  u  pV[        U[        5      (       d  S[        R                  " U5      -   U0nU R                  [        R                  " U5      U R                  X#5      S9  Mj     M  U R                  R                  U R                  R                  X#-   S95        GM+     g)zPrints the environment unset commands for items.

Args:
  items: The current record dict iteritems from _AddRecord().
  prefix: Parent name prefix, prepended to each item name.
rN   rG   r&   N)r.   r/   r0   r5   rO   r   r1   rK   r6   r7   r   r   r   r4   rR   s          r!   r   ConfigPrinter._PrintEnvUnset   s     e}]]4 d	E4	 	 CMM%0#'<<#= 	 	?eT""e$DAAt$$s}}Q''+A


cmmA.%)\\&%?  A % 			0077V]7KL %r#   c                 p     U R                  [        R                  " U5      5        g! [         a     gf = f)zDispatches to the specific config printer.

Nothing is printed if the record is not a JSON-serializable dict.

Args:
  record: A JSON-serializable dict.
  delimit: Ignored.
N)r   r/   r1   r3   )r   recorddelimits      r!   
_AddRecordConfigPrinter._AddRecord   s.    
oocmmF+, 
s   %( 
55)r   r   ) )F)__name__
__module____qualname____firstlineno____doc__r   r2   r   staticmethodrK   r   r   r[   __static_attributes____classcell__)r    s   @r!   r	   r	      sA    	7*!F.  .8M* r#   r	   )rb   
__future__r   r   r   r,   rP   googlecloudsdk.core.resourcer   googlecloudsdk.core.utilr   r/   ResourcePrinterr	    r#   r!   <module>rk      s7     & &  ' 	  > . 
P)99 Pr#   