<s> import subprocess <EOL> import os <EOL> from os import path <EOL> import re <EOL> import traceback <EOL> import sys <EOL> error_msg = """<STR_LIT>""" <EOL> def run ( cmd ) : <EOL> print '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( cmd ) <EOL> try : <EOL> result = subprocess . Popen ( <EOL> cmd , <EOL> stderr = subprocess . PIPE , <EOL> stdout = subprocess . PIPE <EOL> ) <EOL> except Exception : <EOL> _ , error , _ = sys . exc_info ( ) <EOL> print_error ( [ ] , traceback . format_exc ( error ) . split ( '<STR_LIT:\n>' ) ) <EOL> raise SystemExit ( <NUM_LIT:1> ) <EOL> if result . wait ( ) : <EOL> print_error ( result . stdout . readlines ( ) , result . stderr . readlines ( ) ) <EOL> return result . returncode <EOL> def print_error ( stdout , stderr ) : <EOL> print '<STR_LIT:*>' * <NUM_LIT> <EOL> print error_msg <EOL> for line in stdout : <EOL> print line <EOL> for line in stderr : <EOL> print line <EOL> print '<STR_LIT:*>' * <NUM_LIT> <EOL> def vendor_library ( name , version , cmd = None ) : <EOL> this_dir = path . dirname ( path . abspath ( __file__ ) ) <EOL> vendor_dest = path . join ( this_dir , '<STR_LIT>' % name ) <EOL> vendor_init = path . join ( vendor_dest , '<STR_LIT>' ) <EOL> vendor_src = path . join ( this_dir , name ) <EOL> vendor_module = path . join ( vendor_src , name ) <EOL> current_dir = os . getcwd ( ) <EOL> if path . exists ( vendor_src ) : <EOL> run ( [ '<STR_LIT>' , '<STR_LIT>' , vendor_src ] ) <EOL> if path . exists ( vendor_init ) : <EOL> module_file = open ( vendor_init ) . read ( ) <EOL> metadata = dict ( re . findall ( r"<STR_LIT>" , module_file ) ) <EOL> if metadata . get ( '<STR_LIT:version>' ) != version : <EOL> run ( [ '<STR_LIT>' , '<STR_LIT>' , vendor_dest ] ) <EOL> if not path . exists ( vendor_dest ) : <EOL> rc = run ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % name ] ) <EOL> if rc : <EOL> print "<STR_LIT>" % ( path . basename ( __file__ ) , rc ) <EOL> run ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % name ] ) <EOL> os . chdir ( vendor_src ) <EOL> run ( [ '<STR_LIT>' , '<STR_LIT>' , version ] ) <EOL> if cmd : <EOL> run ( cmd ) <EOL> run ( [ '<STR_LIT>' , vendor_module , vendor_dest ] ) <EOL> os . chdir ( current_dir ) <EOL> def clean_vendor ( name ) : <EOL> """<STR_LIT>""" <EOL> this_dir = path . dirname ( path . abspath ( __file__ ) ) <EOL> vendor_dest = path . join ( this_dir , '<STR_LIT>' % name ) <EOL> run ( [ '<STR_LIT>' , '<STR_LIT>' , vendor_dest ] ) <EOL> def vendorize ( vendor_requirements ) : <EOL> """<STR_LIT>""" <EOL> for library in vendor_requirements : <EOL> if len ( library ) == <NUM_LIT:2> : <EOL> name , version = library <EOL> cmd = None <EOL> elif len ( library ) == <NUM_LIT:3> : <EOL> name , version , cmd = library <EOL> vendor_library ( name , version , cmd ) </s>
