OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2016 Google Inc. | 3 # Copyright 2016 Google Inc. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license that can be | 5 # Use of this source code is governed by a BSD-style license that can be |
6 # found in the LICENSE file. | 6 # found in the LICENSE file. |
7 | 7 |
8 | 8 |
9 """Utilities for managing assets.""" | 9 """Utilities for managing assets.""" |
10 | 10 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 with utils.tmp_dir(): | 191 with utils.tmp_dir(): |
192 zip_file = os.path.join(os.getcwd(), '%d.zip' % version) | 192 zip_file = os.path.join(os.getcwd(), '%d.zip' % version) |
193 self.copy(gs_path, zip_file) | 193 self.copy(gs_path, zip_file) |
194 zip_utils.unzip(zip_file, target_dir) | 194 zip_utils.unzip(zip_file, target_dir) |
195 | 195 |
196 def delete_contents(self, name): | 196 def delete_contents(self, name): |
197 """Delete data for the given asset.""" | 197 """Delete data for the given asset.""" |
198 gs_path = GS_SUBDIR_TMPL % (self._gs_bucket, name) | 198 gs_path = GS_SUBDIR_TMPL % (self._gs_bucket, name) |
199 attempt_delete = True | 199 attempt_delete = True |
200 try: | 200 try: |
201 subprocess.check_call(['gsutil', 'ls', gs_path]) | 201 subprocess.check_call(self._gsutil + ['ls', gs_path]) |
202 except subprocess.CalledProcessError: | 202 except subprocess.CalledProcessError: |
203 attempt_delete = False | 203 attempt_delete = False |
204 if attempt_delete: | 204 if attempt_delete: |
205 subprocess.check_call(['gsutil', 'rm', '-rf', gs_path]) | 205 subprocess.check_call(self._gsutil + ['rm', '-rf', gs_path]) |
206 | 206 |
207 | 207 |
208 class MultiStore(object): | 208 class MultiStore(object): |
209 """Wrapper object which uses CIPD as the primary store and GS for backup.""" | 209 """Wrapper object which uses CIPD as the primary store and GS for backup.""" |
210 def __init__(self, cipd_url=DEFAULT_CIPD_SERVICE_URL, | 210 def __init__(self, cipd_url=DEFAULT_CIPD_SERVICE_URL, |
211 gsutil=None, gs_bucket=DEFAULT_GS_BUCKET): | 211 gsutil=None, gs_bucket=DEFAULT_GS_BUCKET): |
212 self._cipd = CIPDStore(cipd_url=cipd_url) | 212 self._cipd = CIPDStore(cipd_url=cipd_url) |
213 self._gs = GSStore(gsutil=gsutil, bucket=gs_bucket) | 213 self._gs = GSStore(gsutil=gsutil, bucket=gs_bucket) |
214 | 214 |
215 def get_available_versions(self, name): | 215 def get_available_versions(self, name): |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 raise Exception('Asset %s does not exist!' % self._name) | 323 raise Exception('Asset %s does not exist!' % self._name) |
324 | 324 |
325 # Cleanup the store. | 325 # Cleanup the store. |
326 if remove_in_store: | 326 if remove_in_store: |
327 self._store.delete_contents(self._name) | 327 self._store.delete_contents(self._name) |
328 | 328 |
329 # Remove the asset. | 329 # Remove the asset. |
330 subprocess.check_call([utils.GIT, 'rm', '-rf', self._dir]) | 330 subprocess.check_call([utils.GIT, 'rm', '-rf', self._dir]) |
331 if os.path.isdir(self._dir): | 331 if os.path.isdir(self._dir): |
332 shutil.rmtree(self._dir) | 332 shutil.rmtree(self._dir) |
OLD | NEW |