Example #1
0
    def testServeRemote(self):

        msettings["SERVE_REMOTE"] = False
        self.assertEqual(backends.client().media_url(), "/media")

        msettings["SERVE_REMOTE"] = True
        self.assertEqual(backends.client().media_url(), "http://s3.amazonaws.com/%s" % self.bucket_name)
Example #2
0
    def testServeRemote(self):
        
        msettings['SERVE_REMOTE'] = False
        self.assertEqual(backends.client().media_url(), '/media')

        msettings['SERVE_REMOTE'] = True
        self.assertEqual(backends.client().media_url(), 'http://s3.amazonaws.com/%s' % self.bucket_name)
Example #3
0
    def testServeRemote(self):
        
        msettings['SERVE_REMOTE'] = False
        self.assertEqual(backends.client().media_url(), '/media')

        msettings['SERVE_REMOTE'] = True
        self.assertEqual(backends.client().media_url(), 'http://s3.amazonaws.com/%s' % self.bucket_name)
Example #4
0
 def testServeRemote(self):
     
     settings.DEBUG = False
     settings.MEDIASYNC['SERVE_REMOTE'] = False
     self.assertEqual(backends.client().media_url(), '/media')
     
     settings.DEBUG = True
     settings.MEDIASYNC['SERVE_REMOTE'] = True
     self.assertEqual(backends.client().media_url(), 'http://mediasync_test.s3.amazonaws.com')
Example #5
0
 def testMediaURL(self):
     
     try:
         del settings.MEDIASYNC['SERVE_REMOTE']
     except KeyError:
         pass
         
     settings.DEBUG = True
     self.assertEqual(backends.client().media_url(), '/media')
     
     settings.DEBUG = False
     self.assertEqual(backends.client().media_url(), 'http://mediasync_test.s3.amazonaws.com')
def sync(client=None, force=False):
    """ 
    Let's face it... pushing this stuff to S3 is messy. A lot of different 
    things need to be calculated for each file and they have to be in a certain 
    order as some variables rely on others.
    """
    # create client connection
    if client is None:
        client = backends.client()

    client.open()
    client.serve_remote = True

    #
    # sync joined media
    #

    for joinfile, sourcefiles in JOINED.iteritems():
        filedata = combine_files(joinfile, sourcefiles, client)
        if filedata is None:
            # combine_files() is only interested in CSS/JS files.
            continue
        filedata, dirname = filedata

        content_type = mimetypes.guess_type(joinfile)[0] or 'application/octet-stream'

        remote_path = joinfile
        if dirname:
            remote_path = "%s/%s" % (dirname, remote_path)

        if client.process_and_put(filedata, content_type, remote_path, force=force):
            print "[%s] %s" % (content_type, remote_path)

    #
    # sync static media
    #

    for dirname in os.listdir(client.media_root):

        dirpath = os.path.abspath(os.path.join(client.media_root, dirname))

        if os.path.isdir(dirpath):

            for filename in listdir_recursive(dirpath):

                # calculate local and remote paths
                filepath = os.path.join(dirpath, filename)
                remote_path = "%s/%s" % (dirname, filename)

                content_type = mimetypes.guess_type(filepath)[0] or 'application/octet-stream'

                if not is_syncable_file(os.path.basename(filename)) or not os.path.isfile(filepath):
                    continue # hidden file or directory, do not upload

                filedata = open(filepath, 'rb').read()

                if client.process_and_put(filedata, content_type, remote_path, force=force):
                    print "[%s] %s" % (content_type, remote_path)

    client.close()
Example #7
0
 def setUp(self):
     msettings['SERVE_REMOTE'] = True
     msettings['BACKEND'] = 'mediasync.tests.tests'
     msettings['PROCESSORS'] = (
         'mediasync.processors.closurecompiler.compile',
     )
     self.client = backends.client()
Example #8
0
 def setUp(self):
     msettings['SERVE_REMOTE'] = True
     msettings['BACKEND'] = 'mediasync.tests.tests'
     msettings['PROCESSORS'] = (
         'mediasync.processors.closurecompiler.compile',
     )
     self.client = backends.client()
Example #9
0
 def setUp(self):
     msettings['BACKEND'] = 'mediasync.tests.tests'
     msettings['PROCESSORS'] = (
         'mediasync.processors.css_minifier',
         'mediasync.processors.js_minifier',
         lambda fd, ct, rp, r: fd.upper(),
     )
     self.client = backends.client()
Example #10
0
 def setUp(self):
     msettings['BACKEND'] = 'mediasync.tests.tests'
     msettings['PROCESSORS'] = []
     msettings['SERVE_REMOTE'] = True
     msettings['JOINED'] = {
         'css/joined.css': ('css/1.css', 'css/2.css'),
         'js/joined.js': ('js/1.js', 'js/2.js'),
     }
     self.client = backends.client()
Example #11
0
 def setUp(self):
     settings.DEBUG = False
     settings.MEDIASYNC = {
         'BACKEND': 'mediasync.backends.s3',
         'AWS_BUCKET': 'mediasync_test',
         'AWS_KEY': os.environ['AWS_KEY'],
         'AWS_SECRET': os.environ['AWS_SECRET'],
     }
     self.client = backends.client()
Example #12
0
 def setUp(self):
     msettings["SERVE_REMOTE"] = True
     msettings["BACKEND"] = "mediasync.tests.tests"
     msettings["PROCESSORS"] = (
         "mediasync.processors.slim.css_minifier",
         "mediasync.processors.slim.js_minifier",
         lambda fd, ct, rp, r: fd.upper(),
     )
     self.client = backends.client()
Example #13
0
 def setUp(self):
     msettings['SERVE_REMOTE'] = True
     msettings['BACKEND'] = 'mediasync.tests.tests'
     msettings['PROCESSORS'] = (
         'mediasync.processors.slim.css_minifier',
         'mediasync.processors.slim.js_minifier',
         lambda fd, ct, rp, r: fd.upper(),
     )
     self.client = backends.client()
Example #14
0
 def setUp(self):
     msettings['BACKEND'] = 'mediasync.tests.tests'
     msettings['PROCESSORS'] = []
     msettings['SERVE_REMOTE'] = True
     msettings['JOINED'] = {
         'css/joined.css': ('css/1.css', 'css/2.css'),
         'js/joined.js': ('js/1.js', 'js/2.js'),
     }
     self.client = backends.client()
Example #15
0
    def setUp(self):

        bucket_hash = md5("%i-%s" % (int(time.time()), os.environ["USER"])).hexdigest()
        self.bucket_name = "mediasync_test_" + bucket_hash

        msettings["BACKEND"] = "mediasync.backends.s3"
        msettings["AWS_BUCKET"] = self.bucket_name
        msettings["AWS_KEY"] = os.environ["AWS_KEY"] or None
        msettings["AWS_SECRET"] = os.environ["AWS_SECRET"] or None
        msettings["PROCESSORS"] = []
        msettings["SERVE_REMOTE"] = True
        msettings["JOINED"] = {"css/joined.css": ("css/1.css", "css/2.css"), "js/joined.js": ("js/1.js", "js/2.js")}

        self.client = backends.client()
Example #16
0
 def setUp(self):
     
     bucket_hash = md5("%i-%s" % (int(time.time()), os.environ['USER'])).hexdigest()
     self.bucket_name = 'mediasync_test_' + bucket_hash
     
     msettings['BACKEND'] = 'mediasync.backends.s3'
     msettings['AWS_BUCKET'] = self.bucket_name
     msettings['AWS_KEY'] = os.environ['AWS_KEY'] or None
     msettings['AWS_SECRET'] = os.environ['AWS_SECRET'] or None
     msettings['PROCESSORS'] = []
     msettings['SERVE_REMOTE'] = True
     msettings['JOINED'] = {
         'css/joined.css': ('css/1.css', 'css/2.css'),
         'js/joined.js': ('js/1.js', 'js/2.js'),
     }
     
     self.client = backends.client()
Example #17
0
 def setUp(self):
     
     bucket_hash = md5("%i-%s" % (int(time.time()), os.environ['USER'])).hexdigest()
     self.bucket_name = 'mediasync_test_' + bucket_hash
     
     msettings['BACKEND'] = 'mediasync.backends.s3'
     msettings['AWS_BUCKET'] = self.bucket_name
     msettings['AWS_KEY'] = os.environ['AWS_KEY'] or None
     msettings['AWS_SECRET'] = os.environ['AWS_SECRET'] or None
     msettings['PROCESSORS'] = []
     msettings['SERVE_REMOTE'] = True
     msettings['JOINED'] = {
         'css/joined.css': ('css/1.css', 'css/2.css'),
         'js/joined.js': ('js/1.js', 'js/2.js'),
     }
     
     self.client = backends.client()
Example #18
0
 def setUp(self):
     settings.DEBUG = False
     settings.MEDIASYNC = {
         'BACKEND': 'mediasync.backends.dummy',
     }
     self.client = backends.client()
Example #19
0
 def setUp(self):
     msettings.PROCESSORS = (
         'mediasync.processors.js_minifier',
         lambda fd, ct, rp, r: fd.upper(),
     )
     self.client = backends.client()
Example #20
0
    def testServeRemote(self):
        msettings.SERVE_REMOTE = False
        self.assertEqual(backends.client().media_url(), '/media')

        msettings.SERVE_REMOTE = True
        self.assertEqual(backends.client().media_url(), 'http://mediasync_test.s3.amazonaws.com')
Example #21
0
 def setUp(self):
     msettings.BACKEND = 'mediasync.backends.s3'
     msettings.AWS_BUCKET = 'mediasync_test'
     msettings.AWS_KEY = os.environ['AWS_KEY']
     msettings.AWS_SECRET = os.environ['AWS_SECRET']
     self.client = backends.client()
Example #22
0
 def setUp(self):
     msettings.BACKEND = 'mediasync.backends.dummy'
     self.client = backends.client()
Example #23
0
 def setUp(self):
     msettings['BACKEND'] = 'mediasync.tests.tests'
     msettings['DOCTYPE'] = 'html5'
     self.client = backends.client()
Example #24
0
 def setUp(self):
     msettings["SERVE_REMOTE"] = True
     msettings["BACKEND"] = "mediasync.tests.tests"
     msettings["PROCESSORS"] = ("mediasync.processors.closurecompiler.compile",)
     self.client = backends.client()
Example #25
0
 def setUp(self):
     msettings['BACKEND'] = 'mediasync.tests.tests'
     msettings['DOCTYPE'] = 'html5'
     self.client = backends.client()
Example #26
0
 def setUp(self):
     msettings['BACKEND'] = 'mediasync.tests.tests'
     self.client = backends.client()
Example #27
0
def sync(client=None, force=False):
    """ Let's face it... pushing this stuff to S3 is messy.
        A lot of different things need to be calculated for each file
        and they have to be in a certain order as some variables rely
        on others.
    """
    
    from django.conf import settings
    from mediasync import backends
    import cStringIO
    
    assert hasattr(settings, "MEDIASYNC")
    
    CSS_PATH = settings.MEDIASYNC.get("CSS_PATH", "").strip('/')
    JS_PATH = settings.MEDIASYNC.get("JS_PATH", "").strip('/')
    
    # create client connection
    if client is None:
        client = backends.client()
        
    client.open()
    client.serve_remote = True

    #
    # sync joined media
    #
    
    joined = settings.MEDIASYNC.get("JOINED", {})
    
    for joinfile, sourcefiles in joined.iteritems():
        
        joinfile = joinfile.strip('/')
        
        if joinfile.endswith('.css'):
            dirname = CSS_PATH
        elif joinfile.endswith('.js'):
            dirname = JS_PATH
        else:
            continue # bypass this file since we only join css and js
        
        buffer = cStringIO.StringIO()
        
        for sourcefile in sourcefiles:
            
            sourcepath = os.path.join(client.media_root, dirname, sourcefile)
            if os.path.isfile(sourcepath):
                f = open(sourcepath)
                buffer.write(f.read())
                f.close()
                buffer.write('\n')        
        
        filedata = buffer.getvalue()
        buffer.close()
        
        content_type = mimetypes.guess_type(joinfile)[0] or 'application/octet-stream'
        
        remote_path = joinfile
        if dirname:
            remote_path = "%s/%s" % (dirname, remote_path)
        
        if client.process_and_put(filedata, content_type, remote_path, force=force):
            print "[%s] %s" % (content_type, remote_path)
    
    #
    # sync static media
    #

    for dirname in os.listdir(client.media_root):
        
        dirpath = os.path.abspath(os.path.join(client.media_root, dirname))
        
        if os.path.isdir(dirpath):
           
            for filename in listdir_recursive(dirpath):
                
                # calculate local and remote paths
                filepath = os.path.join(dirpath, filename)
                remote_path = "%s/%s" % (dirname, filename)
                
                content_type = mimetypes.guess_type(filepath)[0] or 'application/octet-stream'
                
                if not is_syncable_file(os.path.basename(filename)) or not os.path.isfile(filepath):
                    continue # hidden file or directory, do not upload
                
                filedata = open(filepath, 'rb').read()
                
                if client.process_and_put(filedata, content_type, remote_path, force=force):
                    print "[%s] %s" % (content_type, remote_path)
    
    client.close()
Example #28
0
import warnings
from django import template
from django.conf import settings
from django.template.defaultfilters import stringfilter
from mediasync.msettings import CSS_PATH, JS_PATH, DOCTYPE, JOINED, SERVE_REMOTE, EMULATE_COMBO, URL_PROCESSOR, CACHE_BUSTER, USE_SSL
from mediasync import backends

# Instance of the backend you configured in settings.py.
client = backends.client()
MEDIA_URL = client.media_url()
SECURE_MEDIA_URL = client.media_url(with_ssl=True)

register = template.Library()

class BaseTagNode(template.Node):
    """
    Base class for all mediasync nodes.
    """
    def __init__(self, path):
        super(BaseTagNode, self).__init__()
        # This is the filename or path+filename supplied by the template call.
        self.path = path

    def is_secure(self, context):
        """
        Looks at the RequestContext object and determines if this page is
        secured with SSL. Linking unencrypted media on an encrypted page will
        show a warning icon on some browsers. We need to be able to serve from
        an encrypted source for encrypted pages, if our backend supports it.

        'django.core.context_processors.request' must be added to
def sync(client=None, force=False, verbose=True):
    """ Let's face it... pushing this stuff to S3 is messy.
        A lot of different things need to be calculated for each file
        and they have to be in a certain order as some variables rely
        on others.
    """
    from mediasync import backends
    from mediasync.conf import msettings
    from mediasync.signals import pre_sync, post_sync

    # create client connection
    if client is None:
        client = backends.client()

    client.open()
    client.serve_remote = True

    # send pre-sync signal
    pre_sync.send(sender=client)

    #
    # sync joined media
    #

    for joinfile, sourcefiles in msettings['JOINED'].iteritems():
        
        filedata = combine_files(joinfile, sourcefiles, client)
        if filedata is None:
            # combine_files() is only interested in CSS/JS files.
            continue
        filedata, dirname = filedata

        content_type = mimetypes.guess_type(joinfile)[0] or msettings['DEFAULT_MIMETYPE']

        remote_path = joinfile
        if dirname:
            remote_path = "%s/%s" % (dirname, remote_path)

        if client.process_and_put(filedata, content_type, remote_path, force=force):
            if verbose:
                print "[%s] %s" % (content_type, remote_path)

    #
    # sync static media
    #

    for dirname in os.listdir(client.media_root):

        dirpath = os.path.abspath(os.path.join(client.media_root, dirname))

        if os.path.isdir(dirpath):

            for filename in listdir_recursive(dirpath):

                # calculate local and remote paths
                filepath = os.path.join(dirpath, filename)
                remote_path = "%s/%s" % (dirname, filename)

                content_type = mimetypes.guess_type(filepath)[0] or msettings['DEFAULT_MIMETYPE']

                if not is_syncable_file(os.path.basename(filename)) or not os.path.isfile(filepath):
                    continue # hidden file or directory, do not upload

                filedata = open(filepath, 'rb').read()

                if client.process_and_put(filedata, content_type, remote_path, force=force):
                    if verbose:
                        print "[%s] %s" % (content_type, remote_path)
    
    # send post-sync signal while client is still open
    post_sync.send(sender=client)
    
    client.close()
Example #30
0
 def setUp(self):
     msettings["BACKEND"] = "mediasync.tests.tests"
     msettings["DOCTYPE"] = "html5"
     self.client = backends.client()
Example #31
0
 def setUp(self):
     msettings["BACKEND"] = "mediasync.tests.tests"
     msettings["PROCESSORS"] = []
     msettings["SERVE_REMOTE"] = True
     msettings["JOINED"] = {"css/joined.css": ("css/1.css", "css/2.css"), "js/joined.js": ("js/1.js", "js/2.js")}
     self.client = backends.client()
Example #32
0
 def setUp(self):
     msettings["BACKEND"] = "mediasync.tests.tests"
     self.client = backends.client()
Example #33
0
from django import template
from mediasync import backends
from mediasync.conf import msettings
import mediasync
import mimetypes

# Instance of the backend you configured in settings.py.
client = backends.client()

register = template.Library()


class BaseTagNode(template.Node):
    """
    Base class for all mediasync nodes.
    """
    def __init__(self, path):
        super(BaseTagNode, self).__init__()
        # This is the filename or path+filename supplied by the template call.
        self.path = path

    def is_secure(self, context):
        """
        Looks at the RequestContext object and determines if this page is
        secured with SSL. Linking unencrypted media on an encrypted page will
        show a warning icon on some browsers. We need to be able to serve from
        an encrypted source for encrypted pages, if our backend supports it.
        'django.core.context_processors.request' must be added to
        TEMPLATE_CONTEXT_PROCESSORS in settings.py.
        """
        return 'request' in context and context['request'].is_secure()
Example #34
0
def sync(client=None, force=False, verbose=True):
    """ Let's face it... pushing this stuff to S3 is messy.
        A lot of different things need to be calculated for each file
        and they have to be in a certain order as some variables rely
        on others.
    """
    from mediasync import backends
    from mediasync.conf import msettings
    from mediasync.signals import pre_sync, post_sync

    # create client connection
    if client is None:
        client = backends.client()

    client.open()
    client.serve_remote = True

    # send pre-sync signal
    pre_sync.send(sender=client)

    #
    # sync joined media
    #

    for joinfile, sourcefiles in msettings['JOINED'].iteritems():
        
        filedata = combine_files(joinfile, sourcefiles, client)
        if filedata is None:
            # combine_files() is only interested in CSS/JS files.
            continue
        filedata, dirname = filedata

        content_type = mimetypes.guess_type(joinfile)[0] or msettings['DEFAULT_MIMETYPE']

        remote_path = joinfile
        if dirname:
            remote_path = "%s/%s" % (dirname, remote_path)

        if client.process_and_put(filedata, content_type, remote_path, force=force):
            if verbose:
                print "[%s] %s" % (content_type, remote_path)

    #
    # sync static media
    #

    for dirname in os.listdir(client.media_root):

        dirpath = os.path.abspath(os.path.join(client.media_root, dirname))

        if os.path.isdir(dirpath):

            for filename in listdir_recursive(dirpath):

                # calculate local and remote paths
                filepath = os.path.join(dirpath, filename)
                remote_path = "%s/%s" % (dirname, filename)

                content_type = mimetypes.guess_type(filepath)[0] or msettings['DEFAULT_MIMETYPE']

                if not is_syncable_file(os.path.basename(filename)) or not os.path.isfile(filepath):
                    continue # hidden file or directory, do not upload

                filedata = open(filepath, 'rb').read()

                if client.process_and_put(filedata, content_type, remote_path, force=force):
                    if verbose:
                        print "[%s] %s" % (content_type, remote_path)
    
    # send post-sync signal while client is still open
    post_sync.send(sender=client)
    
    client.close()
Example #35
0
 def setUp(self):
     msettings['BACKEND'] = 'mediasync.tests.tests'
     self.client = backends.client()