Skip to content

Commit

Permalink
Add compression for pushed files on platforms that support zlib.
Browse files Browse the repository at this point in the history
  • Loading branch information
JordonPhillips committed Oct 1, 2015
1 parent 5af723b commit fd5b034
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions awscli/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# language governing permissions and limitations under the License.
import sys
import os
import zipfile

from botocore.compat import six
#import botocore.compat
Expand All @@ -26,6 +27,15 @@
StringIO = six.StringIO
urlopen = six.moves.urllib.request.urlopen

# Most, but not all, python installations will have zlib. This is required to
# compress any files we send via a push. If we can't compress, we can still
# package the files in a zip container.
try:
import zlib
ZIP_COMPRESSION_MODE = zipfile.ZIP_DEFLATED
except ImportError:
ZIP_COMPRESSION_MODE = zipfile.ZIP_STORED


class BinaryStdout(object):
def __enter__(self):
Expand Down
3 changes: 2 additions & 1 deletion awscli/customizations/codedeploy/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from awscli.customizations.codedeploy.utils import validate_s3_location
from awscli.customizations.commands import BasicCommand
from awscli.errorhandler import ServerError, ClientError
from awscli.compat import ZIP_COMPRESSION_MODE


ONE_MB = 1 << 20
Expand Down Expand Up @@ -199,7 +200,7 @@ def _compress(self, source, ignore_hidden_files=False):
arcname = filename[len(source_path) + 1:]
if filename == appspec_path:
contains_appspec = True
zf.write(filename, arcname)
zf.write(filename, arcname, ZIP_COMPRESSION_MODE)
if not contains_appspec:
raise RuntimeError(
'{0} was not found'.format(appspec_path)
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/customizations/codedeploy/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from awscli.customizations.codedeploy.push import Push
from awscli.errorhandler import ClientError
from awscli.testutils import unittest
from awscli.compat import ZIP_COMPRESSION_MODE


class TestPush(unittest.TestCase):
Expand Down Expand Up @@ -218,7 +219,8 @@ def test_compress_writes_to_zip_file(self, walk, path, tf, zf):
self.args.ignore_hidden_files):
zf().write.assert_called_with(
'/tmp/appspec.yml',
self.appspec
self.appspec,
ZIP_COMPRESSION_MODE
)

def test_upload_to_s3_with_put_object(self):
Expand Down

0 comments on commit fd5b034

Please sign in to comment.