attempt to fix some bugs. may be broken in the process

This commit is contained in:
Jeremy Carbaugh
2009-08-06 14:28:00 -04:00
parent 9918940a65
commit 6d2dd32291
3 changed files with 23 additions and 20 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
include LICENSE
include README.markdown
include README.md
+18 -2
View File
@@ -1,9 +1,24 @@
from django.conf import settings
import os
import re
DIRS_TO_SYNC = ['images','scripts','styles']
MEDIA_URL_RE = re.compile(r"/media/(images|styles|scripts)/")
SERVE_REMOTE = getattr(settings, "MEDIASYNC_SERVE_REMOTE", not settings.DEBUG)
BUCKET_CNAME = getattr(settings, "MEDIASYNC_BUCKET_CNAME", False)
AWS_PREFIX = getattr(settings, "MEDIASYNC_AWS_PREFIX", None)
if SERVE_REMOTE:
assert hasattr(settings, "MEDIASYNC_AWS_BUCKET")
mu = (BUCKET_CNAME and "http://%s" or "http://%s.s3.amazonaws.com") % settings.MEDIASYNC_AWS_BUCKET
if AWS_PREFIX:
mu = "%s/%s" % (mu, AWS_PREFIX)
else:
mu = settings.MEDIA_URL
MEDIA_URL = mu.rstrip('/')
def listdir_recursive(dir):
for root, dirs, files in os.walk(dir):
for file in files:
@@ -122,9 +137,10 @@ def _sync_file(client, filepath, remote_path, filedata=None):
# rewrite CSS if the user chooses
if REWRITE_CSS:
if content_type == "text/css" or filename.endswith('.htc'):
if content_type == "text/css" or filepath.endswith('.htc'):
filedata = MEDIA_URL_RE.sub(r'%s/\1/' % media_url, filedata)
if client.put(filedata, content_type, remote_path):
print "[%s] %s" % (content_type, remote_path)
__all__ = ['DIRS_TO_SYNC','MEDIA_URL','sync']
+4 -17
View File
@@ -1,6 +1,10 @@
from django import template
from django.conf import settings
from django.template.defaultfilters import stringfilter
from mediasync import MEDIA_URL
JOINED = getattr(settings, "MEDIASYNC_JOINED", {})
SERVE_REMOTE = getattr(settings, "MEDIASYNC_SERVE_REMOTE", not settings.DEBUG)
register = template.Library()
@@ -8,23 +12,6 @@ register = template.Library()
# media stuff
#
assert hasattr(settings, "MEDIASYNC_AWS_BUCKET")
SERVE_REMOTE = getattr(settings, "MEDIASYNC_SERVE_REMOTE", not settings.DEBUG)
BUCKET_CNAME = getattr(settings, "MEDIASYNC_BUCKET_CNAME", False)
AWS_PREFIX = getattr(settings, "MEDIASYNC_AWS_PREFIX", None)
JOINED = getattr(settings, "MEDIASYNC_JOINED", {})
if SERVE_REMOTE:
mu = (BUCKET_CNAME and "http://%s" or "http://%s.s3.amazonaws.com") % settings.MEDIASYNC_AWS_BUCKET
if AWS_PREFIX:
mu = "%s/%s" % (mu, AWS_PREFIX)
else:
mu = settings.MEDIA_URL
MEDIA_URL = mu.rstrip('/')
@register.simple_tag
def media_url():
return MEDIA_URL