
    A                     p    d Z ddlZddlZddlZddlZddlmZmZ ddlm	Z	 ddl
mZ d Zedk(  r e        yy)	aD  
This script recursively converts hcl2 files to json

Usage:
    hcl2tojson [-s] PATH [OUT_PATH]

Options:
    -s          Skip un-parsable files
    PATH        The path to convert
    OUT_PATH    The path to write files to
    --with-meta If set add meta parameters to the output_json like __start_line__ and __end_line__
    N)UnexpectedCharactersUnexpectedToken   )load)__version__c            	      	   t        j                  d      } | j                  dddd       | j                  dd	
       | j                  ddd       | j                  ddt               | j                  ddd       | j	                         }t
        t        t        f}t        j                  j                  |j                        rt        |j                  dd      5 }|j                  t        j                  nt        |j                  dd      }t!        |j                  t        j"                  d       t%        j&                  t)        ||j*                        |       |j                  !|j-                  d       |j/                          ddd       yt        j                  j1                  |j                        r^t3               }|j                  t5        d      t        j                  j7                  |j                        st        j8                  |j                         t        j:                  |j                        D ]  \  }}}t        j                  j=                  |j                  |g      }	t        j                  j?                  ||	      }
t        j                  jA                  t        j                  jC                  |j                  |
            }t        j                  j7                  |      st        j8                  |       |D ]  }t        j                  jC                  ||      }t        j                  jC                  ||      }t        j                  jE                  |      d   d z   }||v s||v rq|jG                  |       |jG                  |       t        |dd      5 }t!        |t        j"                  d       	 t)        |      }t        |dd      5 }t%        j&                  ||       ddd       ddd         yt5        d!|j                        # 1 sw Y   yxY w# |$ r |jH                  rY ddd       D w xY w# 1 sw Y   [xY w# 1 sw Y   _xY w)"z!The `console_scripts` entry pointz3This script recursively converts hcl2 files to json)descriptionz-sskip
store_truezSkip un-parsable files)destactionhelpPATHz The file or directory to convert)r   OUT_PATH?zwThe path where to write files to. Optional when parsing a single file. Output is printed to stdout if OUT_PATH is blank)nargsr   z	--versionversion)r   r   z--with-metazRIf set add meta parameters to the output_json like __start_line__ and __end_line__)r   r   rzutf-8)encodingNwT)fileflush)	with_meta
z0Positional OUT_PATH parameter shouldn't be emptyr   z.jsonzInvalid Path)%argparseArgumentParseradd_argumentr   
parse_argsr   r   UnicodeDecodeErrorospathisfiler   openr   sysstdoutprintstderrjsondumpr   r   writecloseisdirsetRuntimeErrorexistsmkdirwalk
commonpathrelpathnormpathjoinsplitextaddr
   )parserargsskippable_exceptionsin_fileout_fileprocessed_filescurrent_dir_files
dir_prefixrelative_current_dircurrent_out_path	file_namein_file_pathout_file_pathparsed_datas                    lib/third_party/hcl2/__main__.pymainrI      s    $$IF 6,5M   %GH
;   I{K
a   D+-ACUV	ww~~dii $))S73w ==( 

$--w? 
 $))#**D9IId7dnn=xH}}$t$  43 
tyy	!%== QRRww~~dmm,HHT]]#%'WWTYY%7!KE++TYY,DEJ#%77??;
#K !ww//T]],@A  77>>"23)*"	!ww||KC "-=y I " 0 0 ? BW L  ?2m6V##L1##M2,g>',SZZtD&*7m
 mS7Cx		+x8 D ?> # &8> >49955c 43T 0 99$ ?>  DC ?>sU   !B3P; Q4Q)Q47Q(	Q4;QQ%	Q4#Q%	%Q4(Q1-Q44Q>__main__)__doc__r   r(   r    r$   larkr   r    r   r   r   rI   __name__     rH   <module>rQ      s<      	 
 6   M6` zF rP   