<s> """<STR_LIT>""" <EOL> from fabric . api import env , local , require , settings <EOL> from fabric . colors import green <EOL> import os <EOL> def compare_versions ( x , y ) : <EOL> """<STR_LIT>""" <EOL> def version_to_tuple ( version ) : <EOL> version_list = version [ <NUM_LIT:1> : ] . split ( '<STR_LIT:.>' , <NUM_LIT:2> ) <EOL> if len ( version_list ) <= <NUM_LIT:3> : <EOL> [ version_list . append ( <NUM_LIT:0> ) for _ in range ( <NUM_LIT:3> - len ( version_list ) ) ] <EOL> try : <EOL> return tuple ( ( int ( version ) for version in version_list ) ) <EOL> except ValueError : <EOL> return ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> x_major , x_minor , x_bugfix = version_to_tuple ( x ) <EOL> y_major , y_minor , y_bugfix = version_to_tuple ( y ) <EOL> return ( cmp ( x_major , y_major ) or cmp ( x_minor , y_minor ) <EOL> or cmp ( x_bugfix , y_bugfix ) ) <EOL> def store_deployed_version ( ) : <EOL> if env . sha_url_template : <EOL> env . deployed_version = None <EOL> with settings ( warn_only = True ) : <EOL> env . deployed_version = local ( '<STR_LIT>' % sha_url ( ) , capture = True <EOL> ) . strip ( '<STR_LIT:">' ) <EOL> if env . deployed_version and len ( env . deployment_type ) > <NUM_LIT:10> : <EOL> env . deployed_version = None <EOL> else : <EOL> print ( green ( "<STR_LIT>" <EOL> % env ) ) <EOL> def sha_url ( ) : <EOL> require ( '<STR_LIT>' ) <EOL> if env . deployment_type == '<STR_LIT>' : <EOL> subdomain = '<STR_LIT>' <EOL> else : <EOL> subdomain = env . deployment_type . lower ( ) + '<STR_LIT:.>' <EOL> return env . sha_url_template % subdomain <EOL> def absolute_release_path ( ) : <EOL> require ( '<STR_LIT:path>' ) <EOL> require ( '<STR_LIT>' ) <EOL> return os . path . join ( env . path , env . current_release_path ) <EOL> def branch ( ref = None ) : <EOL> """<STR_LIT>""" <EOL> ref = ref or "<STR_LIT>" <EOL> return local ( "<STR_LIT>" <EOL> % ref , capture = True ) <EOL> def sha_for_file ( input_file , block_size = <NUM_LIT:2> ** <NUM_LIT:20> ) : <EOL> import hashlib <EOL> sha = hashlib . sha256 ( ) <EOL> with open ( input_file , '<STR_LIT:rb>' ) as f : <EOL> for chunk in iter ( lambda : f . read ( block_size ) , '<STR_LIT>' ) : <EOL> sha . update ( chunk ) <EOL> return sha . hexdigest ( ) </s>
