<s> import logging <EOL> import os <EOL> import subprocess <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def execute ( command , cwd = None , exit = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> original_dir = None <EOL> if cwd : <EOL> original_dir = os . getcwd ( ) <EOL> os . chdir ( cwd ) <EOL> LOG . debug ( "<STR_LIT>" , cwd ) <EOL> LOG . info ( "<STR_LIT>" , command ) <EOL> process = subprocess . Popen ( command , <EOL> cwd = os . getcwd ( ) , <EOL> stdin = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> shell = True ) <EOL> ( out , err ) = process . communicate ( ) <EOL> exitcode = process . wait ( ) <EOL> LOG . debug ( "<STR_LIT>" % <EOL> ( exitcode , out , err ) ) <EOL> if cwd : <EOL> os . chdir ( original_dir ) <EOL> LOG . debug ( "<STR_LIT>" , original_dir ) <EOL> if exitcode != exit : <EOL> raise Exception ( "<STR_LIT>" % <EOL> ( command , exitcode , out , err ) ) <EOL> return out <EOL> def relative_pathify ( path ) : <EOL> if path . startswith ( '<STR_LIT:/>' ) : <EOL> return path [ <NUM_LIT:1> : ] <EOL> return path </s>
