in awscli/customizations/codedeploy/push.py [0:0]
def _compress(self, source, ignore_hidden_files=False):
source_path = os.path.abspath(source)
appspec_path = os.path.sep.join([source_path, 'appspec.yml'])
with tempfile.TemporaryFile('w+b') as tf:
zf = zipfile.ZipFile(tf, 'w', allowZip64=True)
# Using 'try'/'finally' instead of 'with' statement since ZipFile
# does not have support context manager in Python 2.6.
try:
contains_appspec = False
for root, dirs, files in os.walk(source, topdown=True):
if ignore_hidden_files:
files = [fn for fn in files if not fn.startswith('.')]
dirs[:] = [dn for dn in dirs if not dn.startswith('.')]
for fn in files:
filename = os.path.join(root, fn)
filename = os.path.abspath(filename)
arcname = filename[len(source_path) + 1:]
if filename == appspec_path:
contains_appspec = True
zf.write(filename, arcname, ZIP_COMPRESSION_MODE)
if not contains_appspec:
raise RuntimeError(
'{0} was not found'.format(appspec_path)
)
finally:
zf.close()
yield tf