Skip to content

Instantly share code, notes, and snippets.

@banterability
Forked from onyxfish/fabfile.py
Created March 15, 2010 21:43
Show Gist options
  • Save banterability/333365 to your computer and use it in GitHub Desktop.
Save banterability/333365 to your computer and use it in GitHub Desktop.
from fabric.api import *
[...]
def gzip_assets():
"""
GZips every file in the assets directory and places the new file
in the gzip directory with the same filename.
"""
local('python gzip_assets.py')
def deploy_to_s3():
"""
Deploy the latest built tables to S3.
"""
env.gzip_path = 'gzip/tables/'
local(('s3cmd -P --add-header=Content-encoding:gzip --guess-mime-type sync %(gzip_path)s s3://%(s3_bucket)s/%(project_name)s/') % env)
#!/bin/env python
import os
import gzip
import shutil
class FakeTime:
def time(self):
return 1261130520.0
# Hack to override gzip's time implementation
# See: http://stackoverflow.com/questions/264224/setting-the-gzip-timestamp-from-python
gzip.time = FakeTime()
shutil.rmtree('gzip', ignore_errors=True)
shutil.copytree('out', 'gzip')
for path, dirs, files in os.walk('gzip'):
for filename in files:
if filename[-3:] in ['gif', 'png', 'jpg']:
continue
file_path = os.path.join(path, filename)
f_in = open(file_path, 'rb')
contents = f_in.readlines()
f_in.close()
f_out = gzip.open(file_path, 'wb')
f_out.writelines(contents)
f_out.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment