From 6d2dd32291d0c8d524bb6997faf1bf82cdbb8ca4 Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh Date: Thu, 6 Aug 2009 14:28:00 -0400 Subject: [PATCH] attempt to fix some bugs. may be broken in the process --- MANIFEST.in | 2 +- mediasync/__init__.py | 20 ++++++++++++++++++-- mediasync/templatetags/media.py | 21 ++++----------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 6741b8a..689e50f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ include LICENSE -include README.markdown \ No newline at end of file +include README.md \ No newline at end of file diff --git a/mediasync/__init__.py b/mediasync/__init__.py index 9c5731e..b31cd21 100644 --- a/mediasync/__init__.py +++ b/mediasync/__init__.py @@ -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) - \ No newline at end of file + +__all__ = ['DIRS_TO_SYNC','MEDIA_URL','sync'] \ No newline at end of file diff --git a/mediasync/templatetags/media.py b/mediasync/templatetags/media.py index 246492b..7469091 100644 --- a/mediasync/templatetags/media.py +++ b/mediasync/templatetags/media.py @@ -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