#NEWLINE# def main( args ) : #NEWLINE# #INDENT# 'Entrypoint of the whole application' #NEWLINE# if ( len ( args ) == 0 ) : #NEWLINE# #INDENT# stderr ( 'Error: Bad number of arguments.\n' ) #NEWLINE# die ( USAGE , errlvl = 1 , prefix = '' ) #NEWLINE# #UNINDENT# if ( ( len ( args ) == 1 ) and ( args [ 0 ] in ( '-h' , '--help' ) ) ) : #NEWLINE# #INDENT# stdout ( HELP ) #NEWLINE# exit ( 0 ) #NEWLINE# #UNINDENT# action = args [ 0 ] #NEWLINE# key_value = ( None if ( len ( args ) == 1 ) else args [ 1 ] ) #NEWLINE# default = ( args [ 2 ] if ( len ( args ) > 2 ) else None ) #NEWLINE# contents = yaml . load ( sys . stdin ) #NEWLINE# try : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# value = mget ( contents , key_value ) #NEWLINE# #UNINDENT# except ( IndexOutOfRange , MissingKeyError ) : #NEWLINE# #INDENT# if ( default is None ) : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# value = default #NEWLINE# #UNINDENT# #UNINDENT# except ( IndexOutOfRange , MissingKeyError , NonDictLikeTypeError , IndexNotIntegerError ) as exc : #NEWLINE# #INDENT# msg = str ( exc . message ) #NEWLINE# die ( ( 'invalid path %r, %s' % ( key_value , msg . replace ( 'list' , 'sequence' ) . replace ( 'dict' , 'struct' ) ) ) ) #NEWLINE# #UNINDENT# tvalue = type_name ( value ) #NEWLINE# termination = ( '\x00' if action . endswith ( '-0' ) else '\n' ) #NEWLINE# if ( action == 'get-value' ) : #NEWLINE# #INDENT# print ( dump ( value ) , end = '' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( action in ( 'get-values' , 'get-values-0' ) ) : #NEWLINE# #INDENT# if isinstance ( value , dict ) : #NEWLINE# #INDENT# for ( k , v ) in value . iteritems ( ) : #NEWLINE# #INDENT# stdout ( ( '%s%s%s%s' % ( dump ( k ) , termination , dump ( v ) , termination ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( value , list ) : #NEWLINE# #INDENT# for l in value : #NEWLINE# #INDENT# stdout ( ( '%s%s' % ( dump ( l ) , termination ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# die ( ( '%s does not support %r type. Please provide or select a sequence or struct.' % ( action , tvalue ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( action == 'get-type' ) : #NEWLINE# #INDENT# print ( tvalue ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( action in ( 'keys' , 'keys-0' , 'values' , 'values-0' , 'key-values' , 'key-values-0' ) ) : #NEWLINE# #INDENT# if isinstance ( value , dict ) : #NEWLINE# #INDENT# method = ( value . keys if action . startswith ( 'keys' ) else ( value . items if action . startswith ( 'key-values' ) else value . values ) ) #NEWLINE# output = ( ( lambda x : termination . join ( ( str ( dump ( e ) ) for e in x ) ) ) if action . startswith ( 'key-values' ) else dump ) #NEWLINE# for k in method ( ) : #NEWLINE# #INDENT# stdout ( ( '%s%s' % ( output ( k ) , termination ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# die ( ( '%s does not support %r type. Please provide or select a struct.' % ( action , tvalue ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# die ( ( 'Invalid argument.\n%s' % USAGE ) )