| 169 | |
| 170 | @contextlib.contextmanager |
| 171 | def _compress(self, source, ignore_hidden_files=False): |
| 172 | source_path = os.path.abspath(source) |
| 173 | appspec_path = os.path.sep.join([source_path, 'appspec.yml']) |
| 174 | with tempfile.TemporaryFile('w+b') as tf: |
| 175 | zf = zipfile.ZipFile(tf, 'w', allowZip64=True) |
| 176 | # Using 'try'/'finally' instead of 'with' statement since ZipFile |
| 177 | # does not have support context manager in Python 2.6. |
| 178 | try: |
| 179 | contains_appspec = False |
| 180 | for root, dirs, files in os.walk(source, topdown=True): |
| 181 | if ignore_hidden_files: |
| 182 | files = [fn for fn in files if not fn.startswith('.')] |
| 183 | dirs[:] = [dn for dn in dirs if not dn.startswith('.')] |
| 184 | for fn in files: |
| 185 | filename = os.path.join(root, fn) |
| 186 | filename = os.path.abspath(filename) |
| 187 | arcname = filename[len(source_path) + 1 :] |
| 188 | if filename == appspec_path: |
| 189 | contains_appspec = True |
| 190 | zf.write(filename, arcname, ZIP_COMPRESSION_MODE) |
| 191 | if not contains_appspec: |
| 192 | raise RuntimeError(f'{appspec_path} was not found') |
| 193 | finally: |
| 194 | zf.close() |
| 195 | yield tf |
| 196 | |
| 197 | def _upload_to_s3(self, params, bundle): |
| 198 | size_remaining = self._bundle_size(bundle) |