| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
| 5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
| 6 | 6 |
| 7 import glob | 7 import glob |
| 8 import gsutil | 8 import gsutil |
| 9 import imp | 9 import imp |
| 10 import optparse | 10 import optparse |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 targetFile, | 1180 targetFile, |
| 1181 os.path.basename(directory)], | 1181 os.path.basename(directory)], |
| 1182 os.path.dirname(directory)) | 1182 os.path.dirname(directory)) |
| 1183 | 1183 |
| 1184 | 1184 |
| 1185 def UploadApiDocs(dirName): | 1185 def UploadApiDocs(dirName): |
| 1186 apidocs_namer = bot_utils.GCSNamerApiDocs(CHANNEL) | 1186 apidocs_namer = bot_utils.GCSNamerApiDocs(CHANNEL) |
| 1187 apidocs_destination_gcsdir = apidocs_namer.docs_dirpath(REVISION) | 1187 apidocs_destination_gcsdir = apidocs_namer.docs_dirpath(REVISION) |
| 1188 apidocs_destination_latestfile = apidocs_namer.docs_latestpath(REVISION) | 1188 apidocs_destination_latestfile = apidocs_namer.docs_latestpath(REVISION) |
| 1189 | 1189 |
| 1190 # Delete the old revision specific apidocs directory if present. | 1190 # Return early if the documents have already been uploaded. |
| 1191 Gsutil(['-m', 'rm', '-R', '-f', apidocs_destination_gcsdir]) | 1191 # (This can happen if a build was forced, or a commit had no changes in the |
| 1192 # dart repository (e.g. DEPS file update).) |
| 1193 if GsutilExists(apidocs_destination_gcsdir): |
| 1194 print ("Not uploading api docs, since %s is already present." |
| 1195 % apidocs_destination_gcsdir) |
| 1196 return |
| 1192 | 1197 |
| 1193 # Upload everything inside the built apidocs directory. | 1198 # Upload everything inside the built apidocs directory. |
| 1194 Gsutil(['-m', 'cp', '-R', '-a', 'public-read', dirName, | 1199 Gsutil(['-m', 'cp', '-R', '-a', 'public-read', dirName, |
| 1195 apidocs_destination_gcsdir]) | 1200 apidocs_destination_gcsdir]) |
| 1196 | 1201 |
| 1197 # Update latest.txt to contain the newest revision. | 1202 # Update latest.txt to contain the newest revision. |
| 1198 with utils.TempDir('latest_file') as temp_dir: | 1203 with utils.TempDir('latest_file') as temp_dir: |
| 1199 latest_file = join(temp_dir, 'latest.txt') | 1204 latest_file = join(temp_dir, 'latest.txt') |
| 1200 with open(latest_file, 'w') as f: | 1205 with open(latest_file, 'w') as f: |
| 1201 f.write('%s' % REVISION) | 1206 f.write('%s' % REVISION) |
| 1202 | 1207 |
| 1203 Gsutil(['cp', '-a', 'public-read', latest_file, | 1208 Gsutil(['cp', '-a', 'public-read', latest_file, |
| 1204 apidocs_destination_latestfile]) | 1209 apidocs_destination_latestfile]) |
| 1205 | 1210 |
| 1206 | |
| 1207 def Gsutil(cmd): | 1211 def Gsutil(cmd): |
| 1208 gsutilTool = join(DART_PATH, 'third_party', 'gsutil', 'gsutil') | 1212 gsutilTool = join(DART_PATH, 'third_party', 'gsutil', 'gsutil') |
| 1209 ExecuteCommand([sys.executable, gsutilTool] + cmd) | 1213 ExecuteCommand([sys.executable, gsutilTool] + cmd) |
| 1210 | 1214 |
| 1215 def GsutilExists(gsu_path): |
| 1216 gsutilTool = join(DART_PATH, 'third_party', 'gsutil', 'gsutil') |
| 1217 (_, stderr, returncode) = bot_utils.run( |
| 1218 [gsutilTool, 'ls', gsu_path], |
| 1219 throw_on_error=False) |
| 1220 # If the returncode is nonzero and we can find a specific error message, |
| 1221 # we know there are no objects with a prefix of [gsu_path]. |
| 1222 missing = (returncode and 'CommandException: No such object' in stderr) |
| 1223 # Either the returncode has to be zero or the object must be missing, |
| 1224 # otherwise throw an exception. |
| 1225 if not missing and returncode: |
| 1226 raise Exception("Failed to determine whether %s exists" % gsu_path) |
| 1227 return not missing |
| 1211 | 1228 |
| 1212 def EnsureDirectoryExists(f): | 1229 def EnsureDirectoryExists(f): |
| 1213 d = os.path.dirname(f) | 1230 d = os.path.dirname(f) |
| 1214 if not os.path.exists(d): | 1231 if not os.path.exists(d): |
| 1215 os.makedirs(d) | 1232 os.makedirs(d) |
| 1216 | 1233 |
| 1217 | 1234 |
| 1218 def StartBuildStep(name): | 1235 def StartBuildStep(name): |
| 1219 print "@@@BUILD_STEP %s@@@" % name | 1236 print "@@@BUILD_STEP %s@@@" % name |
| 1220 sys.stdout.flush() | 1237 sys.stdout.flush() |
| 1221 | 1238 |
| 1222 | 1239 |
| 1223 def BuildStepFailure(): | 1240 def BuildStepFailure(): |
| 1224 print '@@@STEP_FAILURE@@@' | 1241 print '@@@STEP_FAILURE@@@' |
| 1225 sys.stdout.flush() | 1242 sys.stdout.flush() |
| 1226 | 1243 |
| 1227 | 1244 |
| 1228 def FileDelete(f): | 1245 def FileDelete(f): |
| 1229 """delete the given file - do not re-throw any exceptions that occur""" | 1246 """delete the given file - do not re-throw any exceptions that occur""" |
| 1230 if os.path.exists(f): | 1247 if os.path.exists(f): |
| 1231 try: | 1248 try: |
| 1232 os.remove(f) | 1249 os.remove(f) |
| 1233 except OSError: | 1250 except OSError: |
| 1234 print 'error deleting %s' % f | 1251 print 'error deleting %s' % f |
| 1235 | 1252 |
| 1236 | |
| 1237 if __name__ == '__main__': | 1253 if __name__ == '__main__': |
| 1238 sys.exit(main()) | 1254 sys.exit(main()) |
| OLD | NEW |