Chromium Code Reviews| 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 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 """Repo sync and then push git changes in flight. | 135 """Repo sync and then push git changes in flight. |
| 136 | 136 |
| 137 Args: | 137 Args: |
| 138 retries: The number of times to retry before giving up, default: 5 | 138 retries: The number of times to retry before giving up, default: 5 |
| 139 | 139 |
| 140 Raises: | 140 Raises: |
| 141 GitPushFailed if push was unsuccessful after retries | 141 GitPushFailed if push was unsuccessful after retries |
| 142 """ | 142 """ |
| 143 for retry in range(1, retries + 1): | 143 for retry in range(1, retries + 1): |
| 144 try: | 144 try: |
| 145 cros_build_lib.RunCommand('repo sync .', shell=True) | 145 cros_build_lib.RunCommand(['repo', 'sync', '.']) |
| 146 cros_build_lib.RunCommand('git push', shell=True) | 146 cros_build_lib.RunCommand(['git', 'push']) |
| 147 break | 147 break |
| 148 except cros_build_lib.RunCommandError: | 148 except cros_build_lib.RunCommandError: |
| 149 if retry < retries: | 149 if retry < retries: |
| 150 print 'Error pushing changes trying again (%s/%s)' % (retry, retries) | 150 print 'Error pushing changes trying again (%s/%s)' % (retry, retries) |
| 151 time.sleep(5 * retry) | 151 time.sleep(5 * retry) |
| 152 else: | 152 else: |
| 153 raise GitPushFailed('Failed to push change after %s retries' % retries) | 153 raise GitPushFailed('Failed to push change after %s retries' % retries) |
| 154 | 154 |
| 155 | 155 |
| 156 def RevGitFile(filename, value, retries=5, key='PORTAGE_BINHOST'): | 156 def RevGitFile(filename, value, retries=5, key='PORTAGE_BINHOST'): |
| 157 """Update and push the git file. | 157 """Update and push the git file. |
| 158 | 158 |
| 159 Args: | 159 Args: |
| 160 filename: file to modify that is in a git repo already | 160 filename: file to modify that is in a git repo already |
| 161 value: string representing the version of the prebuilt that has been | 161 value: string representing the version of the prebuilt that has been |
| 162 uploaded. | 162 uploaded. |
| 163 retries: The number of times to retry before giving up, default: 5 | 163 retries: The number of times to retry before giving up, default: 5 |
| 164 key: The variable key to update in the git file. | 164 key: The variable key to update in the git file. |
| 165 (Default: PORTAGE_BINHOST) | 165 (Default: PORTAGE_BINHOST) |
| 166 """ | 166 """ |
| 167 prebuilt_branch = 'prebuilt_branch' | 167 prebuilt_branch = 'prebuilt_branch' |
| 168 old_cwd = os.getcwd() | 168 old_cwd = os.getcwd() |
| 169 os.chdir(os.path.dirname(filename)) | 169 os.chdir(os.path.dirname(filename)) |
| 170 | 170 |
| 171 commit = cros_build_lib.RunCommand('git rev-parse HEAD', shell=True, | 171 commit = cros_build_lib.RunCommand(['git', 'rev-parse', 'HEAD'], |
| 172 redirect_stdout=True).output | 172 redirect_stdout=True).output |
| 173 cros_build_lib.RunCommand('git remote update', shell=True) | 173 cros_build_lib.RunCommand(['git', 'remote', 'update']) |
| 174 cros_build_lib.RunCommand('repo start %s .' % prebuilt_branch, shell=True) | 174 cros_build_lib.RunCommand(['repo', 'start', prebuilt_branch, '.']) |
| 175 git_ssh_config_cmd = ( | 175 git_ssh_config_cmd = ['git', 'config', |
|
sosa
2011/04/14 21:22:18
Style is a big wrong. If you wish to continue wit
dgarrett
2011/04/18 21:17:38
As I understand, you have a choice...
stuff ['git
Peter Mayo
2011/04/19 03:59:39
Done.
| |
| 176 'git config url.ssh://git@gitrw.chromium.org:9222.pushinsteadof ' | 176 'url.ssh://git@gitrw.chromium.org:9222.pushinsteadof', |
| 177 'http://git.chromium.org/git') | 177 'http://git.chromium.org/git' ] |
| 178 cros_build_lib.RunCommand(git_ssh_config_cmd, shell=True) | 178 cros_build_lib.RunCommand(git_ssh_config_cmd) |
| 179 description = 'Update %s="%s" in %s' % (key, value, filename) | 179 description = 'Update %s="%s" in %s' % (key, value, filename) |
| 180 print description | 180 print description |
| 181 try: | 181 try: |
| 182 UpdateLocalFile(filename, value, key) | 182 UpdateLocalFile(filename, value, key) |
| 183 cros_build_lib.RunCommand('git config push.default tracking', shell=True) | 183 cros_build_lib.RunCommand(['git', 'config', 'push.default', 'tracking']) |
| 184 cros_build_lib.RunCommand('git commit -am "%s"' % description, shell=True) | 184 cros_build_lib.RunCommand(['git', 'commit', '-am', description]) |
| 185 RevGitPushWithRetry(retries) | 185 RevGitPushWithRetry(retries) |
| 186 finally: | 186 finally: |
| 187 cros_build_lib.RunCommand('repo abandon %s .' % prebuilt_branch, shell=True) | 187 cros_build_lib.RunCommand(['repo', 'abandon', 'prebuilt_branch', '.']) |
| 188 cros_build_lib.RunCommand('git checkout %s' % commit, shell=True) | 188 cros_build_lib.RunCommand(['git', 'checkout', commit]) |
| 189 os.chdir(old_cwd) | 189 os.chdir(old_cwd) |
| 190 | 190 |
| 191 | 191 |
| 192 def GetVersion(): | 192 def GetVersion(): |
| 193 """Get the version to put in LATEST and update the git version with.""" | 193 """Get the version to put in LATEST and update the git version with.""" |
| 194 return datetime.datetime.now().strftime('%d.%m.%y.%H%M%S') | 194 return datetime.datetime.now().strftime('%d.%m.%y.%H%M%S') |
| 195 | 195 |
| 196 | 196 |
| 197 def LoadPrivateFilters(build_path): | 197 def LoadPrivateFilters(build_path): |
| 198 """Load private filters based on ebuilds found under _PRIVATE_OVERLAY_DIR. | 198 """Load private filters based on ebuilds found under _PRIVATE_OVERLAY_DIR. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 False otherwise. | 233 False otherwise. |
| 234 """ | 234 """ |
| 235 for name in _FILTER_PACKAGES: | 235 for name in _FILTER_PACKAGES: |
| 236 if name in file_path: | 236 if name in file_path: |
| 237 print 'FILTERING %s' % file_path | 237 print 'FILTERING %s' % file_path |
| 238 return True | 238 return True |
| 239 | 239 |
| 240 return False | 240 return False |
| 241 | 241 |
| 242 | 242 |
| 243 def _RetryRun(cmd, print_cmd=True, shell=False, cwd=None): | 243 def _RetryRun(cmd, print_cmd=True, cwd=None): |
| 244 """Run the specified command, retrying if necessary. | 244 """Run the specified command, retrying if necessary. |
| 245 | 245 |
| 246 Args: | 246 Args: |
| 247 cmd: The command to run. | 247 cmd: The command to run. |
| 248 print_cmd: Whether to print out the cmd. | 248 print_cmd: Whether to print out the cmd. |
| 249 shell: Whether to treat the command as a shell. | 249 shell: Whether to treat the command as a shell. |
| 250 cwd: Working directory to run command in. | 250 cwd: Working directory to run command in. |
| 251 | 251 |
| 252 Returns: | 252 Returns: |
| 253 True if the command succeeded. Otherwise, returns False. | 253 True if the command succeeded. Otherwise, returns False. |
| 254 """ | 254 """ |
| 255 | 255 |
| 256 # TODO(scottz): port to use _Run or similar when it is available in | 256 # TODO(scottz): port to use _Run or similar when it is available in |
| 257 # cros_build_lib. | 257 # cros_build_lib. |
| 258 for attempt in range(_RETRIES): | 258 for attempt in range(_RETRIES): |
| 259 try: | 259 try: |
| 260 output = cros_build_lib.RunCommand(cmd, print_cmd=print_cmd, shell=shell, | 260 output = cros_build_lib.RunCommand(cmd, print_cmd=print_cmd, |
| 261 cwd=cwd) | 261 cwd=cwd) |
| 262 return True | 262 return True |
| 263 except cros_build_lib.RunCommandError: | 263 except cros_build_lib.RunCommandError: |
| 264 print 'Failed to run %s' % cmd | 264 print 'Failed to run %r' % cmd |
| 265 else: | 265 else: |
| 266 print 'Retry failed run %s, giving up' % cmd | 266 print 'Retry failed run %r, giving up' % cmd |
| 267 return False | 267 return False |
| 268 | 268 |
| 269 | 269 |
| 270 def _GsUpload(args): | 270 def _GsUpload(args): |
| 271 """Upload to GS bucket. | 271 """Upload to GS bucket. |
| 272 | 272 |
| 273 Args: | 273 Args: |
| 274 args: a tuple of three arguments that contains local_file, remote_file, and | 274 args: a tuple of three arguments that contains local_file, remote_file, and |
| 275 the acl used for uploading the file. | 275 the acl used for uploading the file. |
| 276 | 276 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 290 cmd = '%s cp -a private %s %s' % (_GSUTIL_BIN, local_file, remote_file) | 290 cmd = '%s cp -a private %s %s' % (_GSUTIL_BIN, local_file, remote_file) |
| 291 if not os.path.exists(acl): | 291 if not os.path.exists(acl): |
| 292 print >> sys.stderr, ('You are specifying either a file that does not ' | 292 print >> sys.stderr, ('You are specifying either a file that does not ' |
| 293 'exist or an unknown canned acl: %s. Aborting ' | 293 'exist or an unknown canned acl: %s. Aborting ' |
| 294 'upload') % acl | 294 'upload') % acl |
| 295 # emulate the failing of an upload since we are not uploading the file | 295 # emulate the failing of an upload since we are not uploading the file |
| 296 return (local_file, remote_file) | 296 return (local_file, remote_file) |
| 297 | 297 |
| 298 acl_cmd = '%s setacl %s %s' % (_GSUTIL_BIN, acl, remote_file) | 298 acl_cmd = '%s setacl %s %s' % (_GSUTIL_BIN, acl, remote_file) |
| 299 | 299 |
| 300 if not _RetryRun(cmd, print_cmd=False, shell=True): | 300 if not _RetryRun(cmd, print_cmd=False): |
| 301 return (local_file, remote_file) | 301 return (local_file, remote_file) |
| 302 | 302 |
| 303 if acl_cmd: | 303 if acl_cmd: |
| 304 # Apply the passed in ACL xml file to the uploaded object. | 304 # Apply the passed in ACL xml file to the uploaded object. |
| 305 _RetryRun(acl_cmd, print_cmd=False, shell=True) | 305 _RetryRun(acl_cmd, print_cmd=False) |
| 306 | 306 |
| 307 | 307 |
| 308 def RemoteUpload(acl, files, pool=10): | 308 def RemoteUpload(acl, files, pool=10): |
| 309 """Upload to google storage. | 309 """Upload to google storage. |
| 310 | 310 |
| 311 Create a pool of process and call _GsUpload with the proper arguments. | 311 Create a pool of process and call _GsUpload with the proper arguments. |
| 312 | 312 |
| 313 Args: | 313 Args: |
| 314 acl: The canned acl used for uploading. acl can be one of: "public-read", | 314 acl: The canned acl used for uploading. acl can be one of: "public-read", |
| 315 "public-read-write", "authenticated-read", "bucket-owner-read", | 315 "public-read-write", "authenticated-read", "bucket-owner-read", |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 value: New value for key. | 415 value: New value for key. |
| 416 """ | 416 """ |
| 417 cwd = os.path.dirname(os.path.abspath(path)) | 417 cwd = os.path.dirname(os.path.abspath(path)) |
| 418 filename = os.path.basename(path) | 418 filename = os.path.basename(path) |
| 419 if not os.path.isdir(cwd): | 419 if not os.path.isdir(cwd): |
| 420 os.makedirs(cwd) | 420 os.makedirs(cwd) |
| 421 if not os.path.isfile(path): | 421 if not os.path.isfile(path): |
| 422 config_file = file(path, 'w') | 422 config_file = file(path, 'w') |
| 423 config_file.close() | 423 config_file.close() |
| 424 UpdateLocalFile(path, value, key) | 424 UpdateLocalFile(path, value, key) |
| 425 cros_build_lib.RunCommand('git add %s' % filename, cwd=cwd, shell=True) | 425 cros_build_lib.RunCommand(['git', 'add', filename], cwd=cwd) |
| 426 description = 'Update %s=%s in %s' % (key, value, filename) | 426 description = 'Update %s=%s in %s' % (key, value, filename) |
| 427 cros_build_lib.RunCommand('git commit -m "%s"' % description, cwd=cwd, | 427 cros_build_lib.RunCommand(['git', 'commit', '-m', description], cwd=cwd) |
| 428 shell=True) | |
| 429 | 428 |
| 430 | 429 |
| 431 def _GrabAllRemotePackageIndexes(binhost_urls): | 430 def _GrabAllRemotePackageIndexes(binhost_urls): |
| 432 """Grab all of the packages files associated with a list of binhost_urls. | 431 """Grab all of the packages files associated with a list of binhost_urls. |
| 433 | 432 |
| 434 Args: | 433 Args: |
| 435 binhost_urls: The URLs for the directories containing the Packages files we | 434 binhost_urls: The URLs for the directories containing the Packages files we |
| 436 want to grab. | 435 want to grab. |
| 437 | 436 |
| 438 Returns: | 437 Returns: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 'pkgs': pkgs, | 504 'pkgs': pkgs, |
| 506 'remote_packages': '%s/Packages' % remote_location.rstrip('/'), | 505 'remote_packages': '%s/Packages' % remote_location.rstrip('/'), |
| 507 'remote_path': remote_path.rstrip('/'), | 506 'remote_path': remote_path.rstrip('/'), |
| 508 'remote_location': remote_location.rstrip('/'), | 507 'remote_location': remote_location.rstrip('/'), |
| 509 'ssh_server': ssh_server } | 508 'ssh_server': ssh_server } |
| 510 cmds = ['ssh %(ssh_server)s mkdir -p %(remote_path)s' % d, | 509 cmds = ['ssh %(ssh_server)s mkdir -p %(remote_path)s' % d, |
| 511 'rsync -av --chmod=a+r %(pkg_index)s %(remote_packages)s' % d] | 510 'rsync -av --chmod=a+r %(pkg_index)s %(remote_packages)s' % d] |
| 512 if pkgs: | 511 if pkgs: |
| 513 cmds.append('rsync -Rav %(pkgs)s %(remote_location)s/' % d) | 512 cmds.append('rsync -Rav %(pkgs)s %(remote_location)s/' % d) |
| 514 for cmd in cmds: | 513 for cmd in cmds: |
| 515 if not _RetryRun(cmd, shell=True, cwd=package_path): | 514 if not _RetryRun(cmd, cwd=package_path): |
| 516 raise UploadFailed('Could not run %s' % cmd) | 515 raise UploadFailed('Could not run %s' % cmd) |
| 517 | 516 |
| 518 def _SyncHostPrebuilts(self, build_path, version, key, git_sync, | 517 def _SyncHostPrebuilts(self, build_path, version, key, git_sync, |
| 519 sync_binhost_conf): | 518 sync_binhost_conf): |
| 520 """Synchronize host prebuilt files. | 519 """Synchronize host prebuilt files. |
| 521 | 520 |
| 522 This function will sync both the standard host packages, plus the host | 521 This function will sync both the standard host packages, plus the host |
| 523 packages associated with all targets that have been "setup" with the | 522 packages associated with all targets that have been "setup" with the |
| 524 current host's chroot. For instance, if this host has been used to build | 523 current host's chroot. For instance, if this host has been used to build |
| 525 x86-generic, it will sync the host packages associated with | 524 x86-generic, it will sync the host packages associated with |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 uploader._SyncHostPrebuilts(options.build_path, version, options.key, | 680 uploader._SyncHostPrebuilts(options.build_path, version, options.key, |
| 682 options.git_sync, options.sync_binhost_conf) | 681 options.git_sync, options.sync_binhost_conf) |
| 683 | 682 |
| 684 if options.board: | 683 if options.board: |
| 685 uploader._SyncBoardPrebuilts(options.board, options.build_path, version, | 684 uploader._SyncBoardPrebuilts(options.board, options.build_path, version, |
| 686 options.key, options.git_sync, | 685 options.key, options.git_sync, |
| 687 options.sync_binhost_conf) | 686 options.sync_binhost_conf) |
| 688 | 687 |
| 689 if __name__ == '__main__': | 688 if __name__ == '__main__': |
| 690 main() | 689 main() |
| OLD | NEW |