本文整理汇总了Python中webassets.Environment.directory方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.directory方法的具体用法?Python Environment.directory怎么用?Python Environment.directory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webassets.Environment
的用法示例。
在下文中一共展示了Environment.directory方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: webassets_init
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import directory [as 别名]
def webassets_init():
global env
static_path = get_webassets_path()
public = config.get(u'ckan.base_public_folder')
public_folder = os.path.abspath(os.path.join(
os.path.dirname(__file__), u'..', public))
base_path = os.path.join(public_folder, u'base')
env = Environment()
env.directory = static_path
env.debug = config.get(u'debug', False)
env.url = u'/webassets/'
env.append_path(base_path, u'/base/')
logger.debug(u'Base path {0}'.format(base_path))
create_library(u'vendor', os.path.join(
base_path, u'vendor'))
create_library(u'base', os.path.join(base_path, u'javascript'))
create_library(u'datapreview', os.path.join(base_path, u'datapreview'))
create_library(u'css', os.path.join(base_path, u'css'))
示例2: load_environment
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import directory [as 别名]
def load_environment(self):
"""Load an ``Environment`` instance defined in the YAML file.
Expects the following format::
directory: ../static
url: /media
debug: True
updater: timestamp
config:
compass_bin: /opt/compass
another_custom_config_value: foo
bundles:
bundle-name:
filters: sass,cssutils
output: cache/default.css
contents:
- css/jquery.ui.calendar.css
- css/jquery.ui.slider.css
"""
f, filename = self._open()
try:
obj = self.yaml.load(f) or {}
env = Environment()
# Load environment settings
for setting in ('debug', 'cache', 'versions', 'url_expire',
'auto_build', 'url', 'directory',
# TODO: The deprecated values; remove at some point
'expire', 'updater'):
if setting in obj:
setattr(env, setting, obj[setting])
# Treat the 'directory' option special, make it relative to the
# path of the YAML file, if we know it.
if filename and 'directory' in env.config:
env.directory = path.normpath(
path.join(path.dirname(filename), env.directory))
# Load custom config options
if 'config' in obj:
env.config.update(obj['config'])
# Load bundles
bundles = self._get_bundles(obj.get('bundles', {}))
for name, bundle in bundles.iteritems():
env.register(name, bundle)
return env
finally:
f.close()
示例3: register_assets
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import directory [as 别名]
def register_assets(settings):
"""
Initialize webassets environment and its bundles.
Arguments:
settings (conf.model.SettingsModel): Settings registry instance.
Returns:
webassets.Environment: New configured Webasset environment.
"""
logger = logging.getLogger('optimus')
if not settings.ENABLED_BUNDLES:
logger.warning(("Asset registering skipped as there are no enabled "
"bundle"))
return None
logger.info("Starting asset registering")
# Assets bundles
AVAILABLE_BUNDLES = getattr(settings, 'BUNDLES', {})
# Initialize webassets environment
assets_env = AssetsEnvironment()
assets_env.debug = settings.DEBUG
assets_env.url = settings.STATIC_URL
assets_env.directory = settings.STATIC_DIR
assets_env.load_path = [settings.SOURCES_DIR]
assets_env.cache = settings.WEBASSETS_CACHE
assets_env.url_expire = settings.WEBASSETS_URLEXPIRE
#
assets_env.optimus_registry = AssetRegistry()
# Register enabled assets bundles
for bundle_name in settings.ENABLED_BUNDLES:
logger.debug("Registering bundle: {}".format(bundle_name))
assets_env.register(bundle_name, AVAILABLE_BUNDLES[bundle_name])
assets_env.optimus_registry.add_bundle(bundle_name,
AVAILABLE_BUNDLES[bundle_name])
# When after bundle has been registered we can resolve it
for bundle_name in settings.ENABLED_BUNDLES:
logger.info(" Processing: {}".format(
assets_env[bundle_name].resolve_output()
))
# Avoid to loop on every bundle part if we are not in debug logger
if logger.getEffectiveLevel() == logging.DEBUG:
for url in assets_env[bundle_name].urls():
logger.debug(" - {}".format(url))
return assets_env
示例4: register_assets
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import directory [as 别名]
def register_assets():
"""
Initialize webassets environment and its bundles
NOTE: The asset bundles building is lazy, webassets only do building when he is
invoked by his template tag **assets** and if it detect that a file in a
bundle has changed.
"""
logger = logging.getLogger('optimus')
if not settings.ENABLED_BUNDLES:
logger.warning("Asset registering skipped as there are no enabled bundles")
return None
logger.info("Starting asset registering")
# Assets bundles
AVAILABLE_BUNDLES = copy.deepcopy(COMMON_BUNDLES)
AVAILABLE_BUNDLES.update(getattr(settings, 'EXTRA_BUNDLES', {}))
# Initialize webassets environment
assets_env = AssetsEnvironment()
assets_env.debug = settings.DEBUG
assets_env.url = settings.STATIC_URL
assets_env.directory = settings.STATIC_DIR
assets_env.load_path = [settings.SOURCES_DIR]
assets_env.cache = settings.WEBASSETS_CACHE
#
assets_env.optimus_registry = AssetRegistry()
# Register enabled assets bundles
for bundle_name in settings.ENABLED_BUNDLES:
logger.debug("Registering bundle: %s", bundle_name)
# Little trick because Bundle does not know their used name in the webassets
# environment
AVAILABLE_BUNDLES[bundle_name]._internal_env_name = bundle_name
assets_env.register(bundle_name, AVAILABLE_BUNDLES[bundle_name])
assets_env.optimus_registry.add_bundle(AVAILABLE_BUNDLES[bundle_name])
# for debugging purpopse
for bundle_name in settings.ENABLED_BUNDLES:
logger.info(" Processing: %s", assets_env[bundle_name].resolve_output())
# TODO: conditionnal on the log level to avoid to loop on multiple items if not
# in a debug log level
for url in assets_env[bundle_name].urls():
logger.debug(" - %s", url)
return assets_env
示例5: load_environment
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import directory [as 别名]
def load_environment(self):
"""Load an :class:`Environment` instance defined in the YAML file.
Expects the following format:
.. code-block:: yaml
directory: ../static
url: /media
debug: True
updater: timestamp
config:
compass_bin: /opt/compass
another_custom_config_value: foo
bundles:
# ...
All values, including ``directory`` and ``url`` are optional. The
syntax for defining bundles is the same as for
:meth:`~.YAMLLoader.load_bundles`.
Sample usage::
from webassets.loaders import YAMLLoader
loader = YAMLLoader('asset.yml')
env = loader.load_environment()
env['some-bundle'].urls()
"""
f, filename = self._open()
try:
obj = self.yaml.load(f) or {}
env = Environment()
# Load environment settings
for setting in ('debug', 'cache', 'versions', 'url_expire',
'auto_build', 'url', 'directory', 'manifest',
# TODO: The deprecated values; remove at some point
'expire', 'updater'):
if setting in obj:
setattr(env, setting, obj[setting])
# Treat the 'directory' option special, make it relative to the
# path of the YAML file, if we know it.
if filename and 'directory' in env.config:
env.directory = path.normpath(
path.join(path.dirname(filename),
env.config['directory']))
# Load custom config options
if 'config' in obj:
env.config.update(obj['config'])
# Load bundles
bundles = self._get_bundles(obj.get('bundles', {}))
for name, bundle in six.iteritems(bundles):
env.register(name, bundle)
return env
finally:
f.close()
示例6: load_environment
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import directory [as 别名]
def load_environment(self):
"""Load an :class:`Environment` instance defined in the YAML file.
Expects the following format:
.. code-block:: yaml
directory: ../static
url: /media
debug: True
updater: timestamp
filters:
- my_custom_package.my_filter
config:
compass_bin: /opt/compass
another_custom_config_value: foo
bundles:
# ...
All values, including ``directory`` and ``url`` are optional. The
syntax for defining bundles is the same as for
:meth:`~.YAMLLoader.load_bundles`.
Sample usage::
from webassets.loaders import YAMLLoader
loader = YAMLLoader('asset.yml')
env = loader.load_environment()
env['some-bundle'].urls()
"""
f, filename = self._open()
try:
obj = self.yaml.load(f) or {}
env = Environment()
# Load environment settings
for setting in ('debug', 'cache', 'versions', 'url_expire',
'auto_build', 'url', 'directory', 'manifest', 'load_path',
'cache_file_mode',
# TODO: The deprecated values; remove at some point
'expire', 'updater'):
if setting in obj:
setattr(env, setting, obj[setting])
# Treat the 'directory' option special, make it relative to the
# path of the YAML file, if we know it.
if filename and 'directory' in env.config:
env.directory = path.normpath(
path.join(path.dirname(filename),
env.config['directory']))
# Treat the 'filters' option special, it should resolve the
# entries as classes and register them to the environment
if 'filters' in obj:
try:
resolve_dotted = self._get_import_resolver()
except ImportError:
raise EnvironmentError(
"In order to use custom filters in the YAMLLoader "
"you must install the zope.dottedname package")
for filter_class in obj['filters']:
try:
cls = resolve_dotted(filter_class)
except ImportError:
raise LoaderError("Unable to resolve class %s" % filter_class)
if inspect.isclass(cls):
register_filter(cls)
else:
raise LoaderError("Custom filters must be classes "
"not modules or functions")
# Load custom config options
if 'config' in obj:
env.config.update(obj['config'])
# Load bundles
bundles = self._get_bundles(obj.get('bundles', {}))
for name, bundle in six.iteritems(bundles):
env.register(name, bundle)
return env
finally:
f.close()