| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, 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 hashlib | 7 import hashlib |
| 8 import imp | 8 import imp |
| 9 import os | 9 import os |
| 10 import subprocess | 10 import subprocess |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 stderr=subprocess.PIPE, env=env) | 137 stderr=subprocess.PIPE, env=env) |
| 138 (stdout, stderr) = p.communicate() | 138 (stdout, stderr) = p.communicate() |
| 139 if p.returncode != 0: | 139 if p.returncode != 0: |
| 140 print >> sys.stderr, "Failed to execute '%s'. Exit code: %s." % ( | 140 print >> sys.stderr, "Failed to execute '%s'. Exit code: %s." % ( |
| 141 command, p.returncode) | 141 command, p.returncode) |
| 142 print >> sys.stderr, "stdout: ", stdout | 142 print >> sys.stderr, "stdout: ", stdout |
| 143 print >> sys.stderr, "stderr: ", stderr | 143 print >> sys.stderr, "stderr: ", stderr |
| 144 raise Exception("Failed to execute %s." % command) | 144 raise Exception("Failed to execute %s." % command) |
| 145 | 145 |
| 146 class GSUtil(object): | 146 class GSUtil(object): |
| 147 GSUTIL_IS_SHELL_SCRIPT = False |
| 147 GSUTIL_PATH = None | 148 GSUTIL_PATH = None |
| 148 | 149 |
| 149 def _layzCalculateGSUtilPath(self): | 150 def _layzCalculateGSUtilPath(self): |
| 150 if not GSUtil.GSUTIL_PATH: | 151 if not GSUtil.GSUTIL_PATH: |
| 151 dart_gsutil = os.path.join(DART_DIR, 'third_party', 'gsutil', 'gsutil') | |
| 152 buildbot_gsutil = os.path.dirname(utils.GetBuildbotGSUtilPath()) | 152 buildbot_gsutil = os.path.dirname(utils.GetBuildbotGSUtilPath()) |
| 153 possible_locations = (list(os.environ['PATH'].split(os.pathsep)) | 153 if os.path.isfile(buildbot_gsutil): |
| 154 + [dart_gsutil, buildbot_gsutil]) | 154 GSUtil.GSUTIL_IS_SHELL_SCRIPT = True |
| 155 for directory in possible_locations: | 155 GSUtil.GSUTIL_PATH = buildbot_gsutil |
| 156 location = os.path.join(directory, 'gsutil') | 156 else: |
| 157 if os.path.isfile(location): | 157 dart_gsutil = os.path.join(DART_DIR, 'third_party', 'gsutil', 'gsutil') |
| 158 GSUtil.GSUTIL_PATH = location | 158 possible_locations = (list(os.environ['PATH'].split(os.pathsep)) |
| 159 break | 159 + [dart_gsutil]) |
| 160 for directory in possible_locations: |
| 161 location = os.path.join(directory, 'gsutil') |
| 162 if os.path.isfile(location): |
| 163 GSUtil.GSUTIL_IS_SHELL_SCRIPT = False |
| 164 GSUtil.GSUTIL_PATH = location |
| 165 break |
| 160 assert GSUtil.GSUTIL_PATH | 166 assert GSUtil.GSUTIL_PATH |
| 161 | 167 |
| 162 def execute(self, gsutil_args): | 168 def execute(self, gsutil_args): |
| 163 self._layzCalculateGSUtilPath() | 169 self._layzCalculateGSUtilPath() |
| 164 | 170 |
| 165 env = dict(os.environ) | 171 env = dict(os.environ) |
| 166 # If we're on the buildbot, we use a specific boto file. | 172 # If we're on the buildbot, we use a specific boto file. |
| 167 if utils.GetUserName() == 'chrome-bot': | 173 if utils.GetUserName() == 'chrome-bot': |
| 168 boto_config = { | 174 boto_config = { |
| 169 'linux': '/mnt/data/b/build/site_config/.boto', | 175 'linux': '/mnt/data/b/build/site_config/.boto', |
| 170 'macos': '/Volumes/data/b/build/site_config/.boto', | 176 'macos': '/Volumes/data/b/build/site_config/.boto', |
| 171 'win32': r'e:\b\build\site_config\.boto', | 177 'win32': r'e:\b\build\site_config\.boto', |
| 172 }[utils.GuessOS()] | 178 }[utils.GuessOS()] |
| 173 env['AWS_CREDENTIAL_FILE'] = boto_config | 179 env['AWS_CREDENTIAL_FILE'] = boto_config |
| 174 env['BOTO_CONFIG'] = boto_config | 180 env['BOTO_CONFIG'] = boto_config |
| 175 run([sys.executable, GSUtil.GSUTIL_PATH] + gsutil_args, | 181 |
| 176 env=env) | 182 if GSUtil.GSUTIL_IS_SHELL_SCRIPT: |
| 183 gsutil_command = [GSUtil.GSUTIL_PATH] |
| 184 else: |
| 185 gsutil_command = [sys.executable, GSUtil.GSUTIL_PATH] |
| 186 |
| 187 run(gsutil_command + gsutil_args, env=env) |
| 177 | 188 |
| 178 def upload(self, local_path, remote_path, recursive=False, public=False): | 189 def upload(self, local_path, remote_path, recursive=False, public=False): |
| 179 assert remote_path.startswith('gs://') | 190 assert remote_path.startswith('gs://') |
| 180 | 191 |
| 181 args = ['cp'] | 192 args = ['cp'] |
| 182 if public: | 193 if public: |
| 183 args += ['-a', 'public-read'] | 194 args += ['-a', 'public-read'] |
| 184 if recursive: | 195 if recursive: |
| 185 args += ['-R'] | 196 args += ['-R'] |
| 186 args += [local_path, remote_path] | 197 args += [local_path, remote_path] |
| (...skipping 27 matching lines...) Expand all Loading... |
| 214 mangled_filename = os.path.basename(filename) | 225 mangled_filename = os.path.basename(filename) |
| 215 | 226 |
| 216 checksum = CalculateChecksum(filename) | 227 checksum = CalculateChecksum(filename) |
| 217 checksum_filename = '%s.md5sum' % filename | 228 checksum_filename = '%s.md5sum' % filename |
| 218 | 229 |
| 219 with open(checksum_filename, 'w') as f: | 230 with open(checksum_filename, 'w') as f: |
| 220 f.write('%s *%s' % (checksum, mangled_filename)) | 231 f.write('%s *%s' % (checksum, mangled_filename)) |
| 221 | 232 |
| 222 return checksum_filename | 233 return checksum_filename |
| 223 | 234 |
| OLD | NEW |