Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compression for pushed files on platforms that support zlib #1534

Merged
merged 1 commit into from
Oct 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pep8: make sure there are two lines separating imports from where the code logic begins



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