<s> import re <EOL> from subprocess import check_call , Popen , PIPE , STDOUT <EOL> from kokki . providers . package import PackageProvider <EOL> VERSION_RE = re . compile ( r'<STR_LIT>' ) <EOL> BEST_MATCH_RE = re . compile ( r'<STR_LIT>' ) <EOL> class EasyInstallProvider ( PackageProvider ) : <EOL> def get_current_status ( self ) : <EOL> proc = Popen ( [ "<STR_LIT>" , "<STR_LIT:-c>" , "<STR_LIT>" % ( self . resource . package_name , self . resource . package_name ) ] , stdout = PIPE , stderr = STDOUT ) <EOL> path = proc . communicate ( ) [ <NUM_LIT:0> ] <EOL> if proc . wait ( ) != <NUM_LIT:0> : <EOL> self . current_version = None <EOL> else : <EOL> match = VERSION_RE . search ( path ) <EOL> if match : <EOL> self . current_version = match . group ( <NUM_LIT:3> ) <EOL> else : <EOL> self . current_version = "<STR_LIT>" <EOL> @ property <EOL> def candidate_version ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> proc = Popen ( [ self . easy_install_binary_path , "<STR_LIT>" , self . resource . package_name ] , stdout = PIPE , stderr = STDOUT ) <EOL> out = proc . communicate ( ) [ <NUM_LIT:0> ] <EOL> res = proc . wait ( ) <EOL> if res != <NUM_LIT:0> : <EOL> self . log . warning ( "<STR_LIT>" % ( res , self . resource ) ) <EOL> match = BEST_MATCH_RE . search ( out ) <EOL> if not match : <EOL> self . _candidate_version = None <EOL> else : <EOL> self . _candidate_version = match . group ( <NUM_LIT:2> ) <EOL> return self . _candidate_version <EOL> @ property <EOL> def easy_install_binary_path ( self ) : <EOL> return "<STR_LIT>" <EOL> def install_package ( self , name , version ) : <EOL> check_call ( [ self . easy_install_binary_path , "<STR_LIT>" , "<STR_LIT>" % ( name , version ) ] , stdout = PIPE , stderr = STDOUT ) <EOL> def upgrade_package ( self , name , version ) : <EOL> self . install_package ( name , version ) <EOL> def remove_package ( self , name ) : <EOL> check_call ( [ self . easy_install_binary_path , "<STR_LIT>" , name ] ) <EOL> def purge_package ( self , name ) : <EOL> self . remove_package ( name ) </s>
