#NEWLINE# def py( sfn , string = False , **kwargs ) : #NEWLINE# #INDENT# "\n    Render a template from a python source file\n\n    Returns::\n\n        {'result': bool,\n         'data': <Error data or rendered file path>}\n    " #NEWLINE# if ( not os . path . isfile ( sfn ) ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# mod = imp . load_source ( os . path . basename ( sfn ) . split ( '.' ) [ 0 ] , sfn ) #NEWLINE# if ( ( '__env__' not in kwargs ) and ( 'saltenv' in kwargs ) ) : #NEWLINE# #INDENT# setattr ( mod , '__env__' , kwargs [ 'saltenv' ] ) #NEWLINE# builtins = [ 'salt' , 'grains' , 'pillar' , 'opts' ] #NEWLINE# for builtin in builtins : #NEWLINE# #INDENT# arg = '__{0}__' . format ( builtin ) #NEWLINE# setattr ( mod , arg , kwargs [ builtin ] ) #NEWLINE# #UNINDENT# #UNINDENT# for kwarg in kwargs : #NEWLINE# #INDENT# setattr ( mod , kwarg , kwargs [ data ] ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# data = mod . run ( ) #NEWLINE# if string : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'result' : True , #NEWLINE# 'data' : data , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# tgt = salt . utils . mkstemp ( ) #NEWLINE# with salt . utils . fopen ( tgt , 'w+' ) as target : #NEWLINE# #INDENT# target . write ( data ) #NEWLINE# #UNINDENT# return { #NEWLINE# #INDENT# 'result' : True , #NEWLINE# 'data' : tgt , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# trb = traceback . format_exc ( ) #NEWLINE# return { #NEWLINE# #INDENT# 'result' : False , #NEWLINE# 'data' : trb , #NEWLINE# #UNINDENT# }