def py(sfn, string=False, **kwargs):
 if (not os.path.isfile(sfn)):
  return {}
 mod = imp.load_source(os.path.basename(sfn).split('.')[0], sfn)
 if (('__env__' not in kwargs) and ('saltenv' in kwargs)):
  setattr(mod, '__env__', kwargs['saltenv'])
  builtins = ['salt', 'grains', 'pillar', 'opts']
  for builtin in builtins:
   arg = '__{0}__'.format(builtin)
   setattr(mod, arg, kwargs[builtin])
 for kwarg in kwargs:
  setattr(mod, kwarg, kwargs[kwarg])
 try:
  data = mod.run()
  if string:
   return {'result': True, 'data': data}
  tgt = salt.utils.files.mkstemp()
  with salt.utils.fopen(tgt, 'w+') as target:
   target.write(data)
  return {'result': True, 'data': tgt}
 except Exception:
  trb = traceback.format_exc()
  return {'result': False, 'data': trb}

def py ( sfn , string = False , ** kwargs ) : if ( not os . path . isfile ( sfn ) ) : return { } mod = imp . load_source ( os . path . basename ( sfn ) . split ( '.' ) [ 0 ] , sfn ) if ( ( '__env__' not in kwargs ) and ( 'saltenv' in kwargs ) ) : setattr ( mod , '__env__' , kwargs [ 'saltenv' ] ) builtins = [ 'salt' , 'grains' , 'pillar' , 'opts' ] for builtin in builtins : arg = '__{0}__' . format ( builtin ) setattr ( mod , arg , kwargs [ builtin ] ) for kwarg in kwargs : setattr ( mod , kwarg , kwargs [ kwarg ] ) try : data = mod . run ( ) if string : return { 'result' : True , 'data' : data } tgt = salt . utils . files . mkstemp ( ) with salt . utils . fopen ( tgt , 'w+' ) as target : target . write ( data ) return { 'result' : True , 'data' : tgt } except Exception : trb = traceback . format_exc ( ) return { 'result' : False , 'data' : trb }
evaluate a python expression .