| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import datetime | 6 import datetime |
| 7 import multiprocessing | 7 import multiprocessing |
| 8 import optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| 11 import sys | 11 import sys |
| 12 import tempfile |
| 12 | 13 |
| 13 from chromite.lib import cros_build_lib | 14 from chromite.lib import cros_build_lib |
| 14 """ | 15 """ |
| 15 This script is used to upload host prebuilts as well as board BINHOSTS to | 16 This script is used to upload host prebuilts as well as board BINHOSTS to |
| 16 Google Storage. | 17 Google Storage. |
| 17 | 18 |
| 18 After a build is successfully uploaded a file is updated with the proper | 19 After a build is successfully uploaded a file is updated with the proper |
| 19 BINHOST version as well as the target board. This file is defined in GIT_FILE | 20 BINHOST version as well as the target board. This file is defined in GIT_FILE |
| 20 | 21 |
| 21 | 22 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 False otherwise. | 184 False otherwise. |
| 184 """ | 185 """ |
| 185 for name in _FILTER_PACKAGES: | 186 for name in _FILTER_PACKAGES: |
| 186 if name in file_path: | 187 if name in file_path: |
| 187 print 'FILTERING %s' % file_path | 188 print 'FILTERING %s' % file_path |
| 188 return True | 189 return True |
| 189 | 190 |
| 190 return False | 191 return False |
| 191 | 192 |
| 192 | 193 |
| 194 def _ShouldFilterPackageFileSection(section): |
| 195 """Return whether an section in the package file should be filtered out. |
| 196 |
| 197 Args: |
| 198 section: The section, as a list of strings. |
| 199 |
| 200 Returns: |
| 201 True if the section should be excluded. |
| 202 """ |
| 203 |
| 204 for line in section: |
| 205 if line.startswith("CPV: "): |
| 206 package = line.replace("CPV: ", "").rstrip() |
| 207 if ShouldFilterPackage(package): |
| 208 return True |
| 209 else: |
| 210 return False |
| 211 |
| 212 |
| 213 def FilterPackagesFile(packages_filename): |
| 214 """Read a portage Packages file and filter out private packages. |
| 215 |
| 216 The new, filtered packages file is written to a temporary file. |
| 217 |
| 218 Args: |
| 219 packages_filename: The filename of the Packages file. |
| 220 |
| 221 Returns: |
| 222 filtered_packages: A filtered Packages file, as a NamedTemporaryFile. |
| 223 """ |
| 224 |
| 225 packages_file = open(packages_filename) |
| 226 filtered_packages = tempfile.NamedTemporaryFile() |
| 227 section = [] |
| 228 for line in packages_file: |
| 229 if line == "\n": |
| 230 if not _ShouldFilterPackageFileSection(section): |
| 231 # Looks like this section doesn't contain a private package. Write it |
| 232 # out. |
| 233 filtered_packages.write("".join(section)) |
| 234 |
| 235 # Start next section. |
| 236 section = [] |
| 237 |
| 238 section.append(line) |
| 239 else: |
| 240 if not _ShouldFilterPackageFileSection(section): |
| 241 filtered_packages.write("".join(section)) |
| 242 packages_file.close() |
| 243 |
| 244 # Flush contents to disk. |
| 245 filtered_packages.flush() |
| 246 filtered_packages.seek(0) |
| 247 |
| 248 return filtered_packages |
| 249 |
| 250 |
| 193 def _GsUpload(args): | 251 def _GsUpload(args): |
| 194 """Upload to GS bucket. | 252 """Upload to GS bucket. |
| 195 | 253 |
| 196 Args: | 254 Args: |
| 197 args: a tuple of two arguments that contains local_file and remote_file. | 255 args: a tuple of two arguments that contains local_file and remote_file. |
| 198 | 256 |
| 199 Returns: | 257 Returns: |
| 200 Return the arg tuple of two if the upload failed | 258 Return the arg tuple of two if the upload failed |
| 201 """ | 259 """ |
| 202 (local_file, remote_file) = args | 260 (local_file, remote_file) = args |
| 203 if ShouldFilterPackage(local_file): | 261 if ShouldFilterPackage(local_file): |
| 204 return | 262 return |
| 205 | 263 |
| 264 if local_file.endswith("/Packages"): |
| 265 filtered_packages_file = FilterPackagesFile(local_file) |
| 266 local_file = filtered_packages_file.name |
| 267 |
| 206 cmd = '%s cp -a public-read %s %s' % (_GSUTIL_BIN, local_file, remote_file) | 268 cmd = '%s cp -a public-read %s %s' % (_GSUTIL_BIN, local_file, remote_file) |
| 207 # TODO(scottz): port to use _Run or similar when it is available in | 269 # TODO(scottz): port to use _Run or similar when it is available in |
| 208 # cros_build_lib. | 270 # cros_build_lib. |
| 209 for attempt in range(_RETRIES): | 271 for attempt in range(_RETRIES): |
| 210 try: | 272 try: |
| 211 output = cros_build_lib.RunCommand(cmd, print_cmd=False, shell=True) | 273 output = cros_build_lib.RunCommand(cmd, print_cmd=False, shell=True) |
| 212 break | 274 break |
| 213 except cros_build_lib.RunCommandError: | 275 except cros_build_lib.RunCommandError: |
| 214 print 'Failed to sync %s -> %s, retrying' % (local_file, remote_file) | 276 print 'Failed to sync %s -> %s, retrying' % (local_file, remote_file) |
| 215 else: | 277 else: |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 UploadPrebuilt(options.build_path, options.upload, version, | 453 UploadPrebuilt(options.build_path, options.upload, version, |
| 392 git_sync=options.git_sync) | 454 git_sync=options.git_sync) |
| 393 | 455 |
| 394 if options.board: | 456 if options.board: |
| 395 UploadPrebuilt(options.build_path, options.upload, version, | 457 UploadPrebuilt(options.build_path, options.upload, version, |
| 396 board=options.board, git_sync=options.git_sync) | 458 board=options.board, git_sync=options.git_sync) |
| 397 | 459 |
| 398 | 460 |
| 399 if __name__ == '__main__': | 461 if __name__ == '__main__': |
| 400 main() | 462 main() |
| OLD | NEW |