def upload_template(filename, destination, context=None, use_jinja=False, template_dir=None, use_sudo=False, backup=True, mirror_local_mode=False, mode=None, pty=None, keep_trailing_newline=False, temp_dir=''):
 func = ((use_sudo and sudo) or run)
 if (pty is not None):
  func = partial(func, pty=pty)
 with settings(hide('everything'), warn_only=True):
  if func(('test -d %s' % _expand_path(destination))).succeeded:
   sep = ('' if destination.endswith('/') else '/')
   destination += (sep + os.path.basename(filename))
 if (mirror_local_mode and (mode is None)):
  mode = os.stat(apply_lcwd(filename, env)).st_mode
  mirror_local_mode = False
 text = None
 if use_jinja:
  try:
   template_dir = (template_dir or os.getcwd())
   template_dir = apply_lcwd(template_dir, env)
   from jinja2 import Environment, FileSystemLoader
   jenv = Environment(loader=FileSystemLoader(template_dir), keep_trailing_newline=keep_trailing_newline)
   text = jenv.get_template(filename).render(**(context or {}))
   text = text.encode('utf-8')
  except ImportError:
   import traceback
   tb = traceback.format_exc()
   abort((tb + '\nUnable to import Jinja2 -- see above.'))
 else:
  if template_dir:
   filename = os.path.join(template_dir, filename)
  filename = apply_lcwd(filename, env)
  with open(os.path.expanduser(filename)) as inputfile:
   text = inputfile.read()
  if context:
   text = (text % context)
 if (backup and exists(destination)):
  func(('cp %s{,.bak}' % _expand_path(destination)))
 return put(local_path=StringIO(text), remote_path=destination, use_sudo=use_sudo, mirror_local_mode=mirror_local_mode, mode=mode, temp_dir=temp_dir)

def upload_template ( filename , destination , context = None , use_jinja = False , template_dir = None , use_sudo = False , backup = True , mirror_local_mode = False , mode = None , pty = None , keep_trailing_newline = False , temp_dir = '' ) : func = ( ( use_sudo and sudo ) or run ) if ( pty is not None ) : func = partial ( func , pty = pty ) with settings ( hide ( 'everything' ) , warn_only = True ) : if func ( ( 'test -d %s' % _expand_path ( destination ) ) ) . succeeded : sep = ( '' if destination . endswith ( '/' ) else '/' ) destination += ( sep + os . path . basename ( filename ) ) if ( mirror_local_mode and ( mode is None ) ) : mode = os . stat ( apply_lcwd ( filename , env ) ) . st_mode mirror_local_mode = False text = None if use_jinja : try : template_dir = ( template_dir or os . getcwd ( ) ) template_dir = apply_lcwd ( template_dir , env ) from jinja2 import Environment , FileSystemLoader jenv = Environment ( loader = FileSystemLoader ( template_dir ) , keep_trailing_newline = keep_trailing_newline ) text = jenv . get_template ( filename ) . render ( ** ( context or { } ) ) text = text . encode ( 'utf-8' ) except ImportError : import traceback tb = traceback . format_exc ( ) abort ( ( tb + '\nUnable to import Jinja2 -- see above.' ) ) else : if template_dir : filename = os . path . join ( template_dir , filename ) filename = apply_lcwd ( filename , env ) with open ( os . path . expanduser ( filename ) ) as inputfile : text = inputfile . read ( ) if context : text = ( text % context ) if ( backup and exists ( destination ) ) : func ( ( 'cp %s{,.bak}' % _expand_path ( destination ) ) ) return put ( local_path = StringIO ( text ) , remote_path = destination , use_sudo = use_sudo , mirror_local_mode = mirror_local_mode , mode = mode , temp_dir = temp_dir )
upload a template file .