<s> """<STR_LIT>""" <EOL> import base64 <EOL> import os <EOL> import os . path <EOL> import re <EOL> import stat <EOL> import string <EOL> import subprocess <EOL> import sys <EOL> import zlib <EOL> def _FileMatches ( path , excl_regexps ) : <EOL> """<STR_LIT>""" <EOL> for r in excl_regexps : <EOL> if re . match ( r , path ) : <EOL> return False <EOL> return True <EOL> def _GetFilesRecursively ( path , excl_regexps = [ <EOL> r"<STR_LIT>" , <EOL> r"<STR_LIT>" , <EOL> r"<STR_LIT>" , <EOL> r"<STR_LIT>" , <EOL> r"<STR_LIT>" , <EOL> r"<STR_LIT>" ] ) : <EOL> """<STR_LIT>""" <EOL> entries = os . listdir ( path ) <EOL> dirs = [ e for e in entries if os . path . isdir ( os . path . join ( path , e ) ) <EOL> and _FileMatches ( e , excl_regexps ) ] <EOL> files = [ os . path . join ( path , e ) for e in entries if <EOL> os . path . isfile ( os . path . join ( path , e ) ) and _FileMatches ( e , excl_regexps ) ] <EOL> for d in dirs : <EOL> files += _GetFilesRecursively ( os . path . join ( path , d ) , excl_regexps ) <EOL> return files <EOL> def _ReadFile ( path ) : <EOL> return open ( path , '<STR_LIT:rb>' ) . read ( ) <EOL> def _Package ( template , package_out , files ) : <EOL> """<STR_LIT>""" <EOL> p = subprocess . Popen ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:->" ] + list ( files ) , <EOL> bufsize = <NUM_LIT> , stdout = subprocess . PIPE ) <EOL> ( tarball , stderr ) = p . communicate ( ) <EOL> out = open ( package_out , "<STR_LIT:w>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( base64 . b64encode ( tarball ) ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( template ) ) <EOL> out . close ( ) <EOL> os . chmod ( package_out , stat . S_IRWXU ) <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> deploy_template = sys . argv [ <NUM_LIT:1> ] <EOL> assert os . path . isfile ( deploy_template ) , "<STR_LIT>" . format ( deploy_template ) <EOL> exec ( open ( deploy_template , '<STR_LIT:rb>' ) ) <EOL> deploy_name = os . path . splitext ( os . path . basename ( deploy_template ) ) [ <NUM_LIT:0> ] <EOL> package_out = os . path . join ( os . path . dirname ( deploy_template ) , <EOL> deploy_name + "<STR_LIT>" ) <EOL> files = _GetFilesRecursively ( "<STR_LIT>" ) <EOL> _Package ( deploy_name , package_out , files ) <EOL> print "<STR_LIT>" . format ( <EOL> deploy_template , package_out ) <EOL> return <NUM_LIT:0> <EOL> except ( IndexError , AssertionError ) , err : <EOL> print ( "<STR_LIT>" . format ( <EOL> str ( err ) , os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) ) ) <EOL> return - <NUM_LIT:1> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( ) ) </s>
