6060
6161import os
6262import re
63- import sets
63+ try :
64+ from sets import Set as set # For Python 2.3 compatibility
65+ except ImportError :
66+ pass
6467import sys
6568
6669# We assume that this file is in the scripts/ directory in the Google
@@ -90,10 +93,10 @@ def VerifyFileExists(directory, relative_path):
9093 """
9194
9295 if not os .path .isfile (os .path .join (directory , relative_path )):
93- print 'ERROR: Cannot find %s in directory %s.' % (relative_path ,
94- directory )
95- print ('Please either specify a valid project root directory '
96- 'or omit it on the command line.' )
96+ print ( 'ERROR: Cannot find %s in directory %s.' % (relative_path ,
97+ directory ))
98+ print ('Please either specify a valid project root directory '
99+ 'or omit it on the command line.' )
97100 sys .exit (1 )
98101
99102
@@ -119,11 +122,11 @@ def VerifyOutputFile(output_dir, relative_path):
119122 # TODO([email protected] ): The following user-interaction doesn't 120123 # work with automated processes. We should provide a way for the
121124 # Makefile to force overwriting the files.
122- print ('%s already exists in directory %s - overwrite it? (y/N) ' %
123- (relative_path , output_dir ))
125+ print ('%s already exists in directory %s - overwrite it? (y/N) ' %
126+ (relative_path , output_dir ))
124127 answer = sys .stdin .readline ().strip ()
125128 if answer not in ['y' , 'Y' ]:
126- print 'ABORTED.'
129+ print ( 'ABORTED.' )
127130 sys .exit (1 )
128131
129132 # Makes sure the directory holding the output file exists; creates
@@ -146,8 +149,8 @@ def ValidateOutputDir(output_dir):
146149def FuseGTestH (gtest_root , output_dir ):
147150 """Scans folder gtest_root to generate gtest/gtest.h in output_dir."""
148151
149- output_file = file (os .path .join (output_dir , GTEST_H_OUTPUT ), 'w' )
150- processed_files = sets . Set () # Holds all gtest headers we've processed.
152+ output_file = open (os .path .join (output_dir , GTEST_H_OUTPUT ), 'w' )
153+ processed_files = set () # Holds all gtest headers we've processed.
151154
152155 def ProcessFile (gtest_header_path ):
153156 """Processes the given gtest header file."""
@@ -159,7 +162,7 @@ def ProcessFile(gtest_header_path):
159162 processed_files .add (gtest_header_path )
160163
161164 # Reads each line in the given gtest header.
162- for line in file (os .path .join (gtest_root , gtest_header_path ), 'r' ):
165+ for line in open (os .path .join (gtest_root , gtest_header_path ), 'r' ):
163166 m = INCLUDE_GTEST_FILE_REGEX .match (line )
164167 if m :
165168 # It's '#include "gtest/..."' - let's process it recursively.
@@ -175,7 +178,7 @@ def ProcessFile(gtest_header_path):
175178def FuseGTestAllCcToFile (gtest_root , output_file ):
176179 """Scans folder gtest_root to generate gtest/gtest-all.cc in output_file."""
177180
178- processed_files = sets . Set ()
181+ processed_files = set ()
179182
180183 def ProcessFile (gtest_source_file ):
181184 """Processes the given gtest source file."""
@@ -187,7 +190,7 @@ def ProcessFile(gtest_source_file):
187190 processed_files .add (gtest_source_file )
188191
189192 # Reads each line in the given gtest source file.
190- for line in file (os .path .join (gtest_root , gtest_source_file ), 'r' ):
193+ for line in open (os .path .join (gtest_root , gtest_source_file ), 'r' ):
191194 m = INCLUDE_GTEST_FILE_REGEX .match (line )
192195 if m :
193196 if 'include/' + m .group (1 ) == GTEST_SPI_H_SEED :
@@ -218,7 +221,7 @@ def ProcessFile(gtest_source_file):
218221def FuseGTestAllCc (gtest_root , output_dir ):
219222 """Scans folder gtest_root to generate gtest/gtest-all.cc in output_dir."""
220223
221- output_file = file (os .path .join (output_dir , GTEST_ALL_CC_OUTPUT ), 'w' )
224+ output_file = open (os .path .join (output_dir , GTEST_ALL_CC_OUTPUT ), 'w' )
222225 FuseGTestAllCcToFile (gtest_root , output_file )
223226 output_file .close ()
224227
@@ -242,7 +245,7 @@ def main():
242245 # fuse_gtest_files.py GTEST_ROOT_DIR OUTPUT_DIR
243246 FuseGTest (sys .argv [1 ], sys .argv [2 ])
244247 else :
245- print __doc__
248+ print ( __doc__ )
246249 sys .exit (1 )
247250
248251
0 commit comments