本文整理汇总了Python中mediasync.backends.client函数的典型用法代码示例。如果您正苦于以下问题:Python client函数的具体用法?Python client怎么用?Python client使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了client函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testServeRemote
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)
示例2: testServeRemote
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)
示例3: testServeRemote
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')
示例4: testMediaURL
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')
示例5: sync
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()
示例6: setUp
def setUp(self):
msettings['SERVE_REMOTE'] = True
msettings['BACKEND'] = 'mediasync.tests.tests'
msettings['PROCESSORS'] = (
'mediasync.processors.closurecompiler.compile',
)
self.client = backends.client()
示例7: setUp
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()
示例8: setUp
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()
示例9: setUp
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()
示例10: sync
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()
示例11: setUp
def setUp(self):
msettings.PROCESSORS = (
'mediasync.processors.js_minifier',
lambda fd, ct, rp, r: fd.upper(),
)
self.client = backends.client()
示例12: testServeRemote
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')
示例13: sync
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()
示例14: BaseTagNode
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