<s> import sys <EOL> import os <EOL> import subprocess <EOL> import httplib <EOL> import re <EOL> import shutil <EOL> import optparse <EOL> def Message ( str ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" , str <EOL> def FixupPath ( path ) : <EOL> """<STR_LIT>""" <EOL> return os . path . sep . join ( path . split ( "<STR_LIT:\\>" ) ) <EOL> def GetRevision ( ) : <EOL> """<STR_LIT>""" <EOL> HOST = "<STR_LIT>" <EOL> PATH = "<STR_LIT>" <EOL> EXPR = r"<STR_LIT>" <EOL> connection = httplib . HTTPConnection ( HOST ) <EOL> connection . request ( "<STR_LIT:GET>" , PATH ) <EOL> response = connection . getresponse ( ) <EOL> text = response . read ( ) <EOL> match = re . search ( EXPR , text ) <EOL> if match : <EOL> return int ( match . group ( <NUM_LIT:1> ) ) <EOL> return None <EOL> def SetRevisionForUpdate ( chrome_root ) : <EOL> """<STR_LIT>""" <EOL> rev = GetRevision ( ) <EOL> if rev == None : <EOL> Message ( "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> gclient_file = chrome_root + FixupPath ( "<STR_LIT>" ) <EOL> if not os . path . exists ( gclient_file ) : <EOL> Message ( "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> scope = { } <EOL> execfile ( gclient_file , scope ) <EOL> solutions = scope [ "<STR_LIT>" ] <EOL> for solution in solutions : <EOL> if solution [ "<STR_LIT:name>" ] == "<STR_LIT:src>" : <EOL> splitter = solution [ "<STR_LIT:url>" ] . split ( "<STR_LIT:@>" ) <EOL> if len ( splitter ) == <NUM_LIT:1> : <EOL> solution [ "<STR_LIT:url>" ] = splitter [ <NUM_LIT:0> ] + "<STR_LIT:@>" + str ( rev ) <EOL> else : <EOL> rev = int ( splitter [ <NUM_LIT:1> ] ) <EOL> break <EOL> gclient_override = gclient_file + "<STR_LIT>" <EOL> f = open ( gclient_override , "<STR_LIT:w>" ) <EOL> f . write ( "<STR_LIT>" + str ( solutions ) ) <EOL> f . close ( ) <EOL> os . environ [ "<STR_LIT>" ] = gclient_override <EOL> return rev <EOL> def DoUpdate ( chrome_root ) : <EOL> """<STR_LIT>""" <EOL> rev = SetRevisionForUpdate ( chrome_root ) <EOL> cmd = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> Message ( "<STR_LIT>" % ( rev , cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> return subprocess . call ( cmd , cwd = chrome_root ) <EOL> def DoClean ( chrome_root , type ) : <EOL> """<STR_LIT>""" <EOL> rv = [ <NUM_LIT:0> ] <EOL> def onError ( func , path , excinfo ) : <EOL> Message ( "<STR_LIT>" % ( path , excinfo ) ) <EOL> rv [ <NUM_LIT:0> ] = [ <NUM_LIT:1> ] <EOL> build_path = chrome_root + FixupPath ( "<STR_LIT>" + type ) <EOL> Message ( "<STR_LIT>" % build_path ) <EOL> shutil . rmtree ( build_path , False , onError ) <EOL> return rv [ <NUM_LIT:0> ] <EOL> def DoBuild ( chrome_root , chrome_sln , clean , type ) : <EOL> """<STR_LIT>""" <EOL> if clean : <EOL> rv = DoClean ( chrome_root , type ) <EOL> if rv != <NUM_LIT:0> : <EOL> Message ( "<STR_LIT>" ) <EOL> cmd = [ "<STR_LIT>" , chrome_sln , "<STR_LIT>" , type ] <EOL> Message ( "<STR_LIT>" % cmd ) <EOL> sys . stdout . flush ( ) <EOL> return subprocess . call ( cmd , cwd = chrome_root ) <EOL> def Main ( ) : <EOL> parser = optparse . OptionParser ( ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , default = False , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> options , args = parser . parse_args ( ) <EOL> if options . print_latest : <EOL> print GetRevision ( ) or "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if not args : <EOL> Message ( "<STR_LIT>" % sys . argv [ <NUM_LIT:0> ] ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> chrome_root = args [ <NUM_LIT:0> ] <EOL> if not os . path . isdir ( chrome_root ) : <EOL> Message ( "<STR_LIT>" % repr ( chrome_root ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if not options . nosync : <EOL> rv = DoUpdate ( chrome_root ) <EOL> if rv != <NUM_LIT:0> : <EOL> Message ( "<STR_LIT>" ) <EOL> sys . exit ( rv ) <EOL> chrome_sln = FixupPath ( options . solution ) <EOL> rv = DoBuild ( chrome_root , chrome_sln , options . clean , "<STR_LIT>" ) <EOL> if rv != <NUM_LIT:0> : <EOL> Message ( "<STR_LIT>" ) <EOL> if options . release : <EOL> rv = DoBuild ( chrome_root , chrome_sln , options . clean , "<STR_LIT>" ) <EOL> if rv != <NUM_LIT:0> : <EOL> Message ( "<STR_LIT>" ) <EOL> if rv != <NUM_LIT:0> : <EOL> sys . exit ( rv ) <EOL> Message ( "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> Main ( ) </s>
