<s> import os <EOL> import subprocess <EOL> class GitHandler ( object ) : <EOL> """<STR_LIT>""" <EOL> folder = None <EOL> remotes = [ ] <EOL> def __init__ ( self , repo_dir ) : <EOL> self . folder = repo_dir <EOL> def command ( self , command ) : <EOL> """<STR_LIT>""" <EOL> if type ( command ) is str : <EOL> command = command . split ( '<STR_LIT:U+0020>' ) <EOL> _command = [ '<STR_LIT>' ] + command <EOL> process = subprocess . Popen ( _command , <EOL> cwd = self . folder , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> shell = False ) <EOL> ( output , error ) = process . communicate ( ) <EOL> if len ( output ) > <NUM_LIT:0> : <EOL> return output <EOL> else : <EOL> return error <EOL> def status ( self ) : <EOL> output = self . command ( [ '<STR_LIT:status>' ] ) <EOL> return output <EOL> def add ( self , file_name = None , all_files = True , track = True ) : <EOL> if file_name : <EOL> output = self . command ( '<STR_LIT>' % file_name ) <EOL> else : <EOL> if all_files : <EOL> output = self . command ( '<STR_LIT>' ) <EOL> if track : <EOL> output = self . command ( '<STR_LIT>' ) <EOL> return output <EOL> def commit ( self , message ) : <EOL> output = self . command ( [ '<STR_LIT>' , '<STR_LIT>' % message ] ) <EOL> return output <EOL> def log ( self , n = <NUM_LIT:10> ) : <EOL> output = self . command ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % n ] ) <EOL> return output <EOL> def diff ( self , mode = '<STR_LIT>' ) : <EOL> output = self . command ( [ '<STR_LIT>' , '<STR_LIT>' % mode ] ) <EOL> return output <EOL> def remote ( self ) : <EOL> output = self . command ( '<STR_LIT>' ) <EOL> remotes = output . split ( ) <EOL> return remotes <EOL> def push ( self , remote = None , branch = None ) : <EOL> if ( branch and remote ) is None : <EOL> output = self . command ( '<STR_LIT>' ) <EOL> else : <EOL> if remote : <EOL> if branch : <EOL> output = self . command ( [ '<STR_LIT>' , remote , branch ] ) <EOL> else : <EOL> output = self . command ( [ '<STR_LIT>' , remote ] ) <EOL> return output </s>
