本文整理汇总了Python中cactus.config.router.ConfigRouter.write方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigRouter.write方法的具体用法?Python ConfigRouter.write怎么用?Python ConfigRouter.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cactus.config.router.ConfigRouter
的用法示例。
在下文中一共展示了ConfigRouter.write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_duplicate
# 需要导入模块: from cactus.config.router import ConfigRouter [as 别名]
# 或者: from cactus.config.router.ConfigRouter import write [as 别名]
def test_duplicate(self):
"""
Check that the config router handles duplicate files properly.
"""
router = ConfigRouter([self.path1, self.path1])
router.set("a", 3)
router.write()
self.conf1.load()
self.assertEqual(self.conf1.get("a"), 3)
示例2: test_write
# 需要导入模块: from cactus.config.router import ConfigRouter [as 别名]
# 或者: from cactus.config.router.ConfigRouter import write [as 别名]
def test_write(self):
"""
Check that the config router writes correctly to the filesystem
"""
router = ConfigRouter([self.path1, self.path2])
router.set("a", 3)
router.set("b", 4)
router.write()
self.conf1.load()
self.conf2.load()
self.assertEqual(self.conf1.get("a"), 3)
self.assertEqual(self.conf1.get("b"), None)
self.assertEqual(self.conf2.get("b"), 4)
self.assertEqual(self.conf2.get("a"), None)
示例3: SiteTestCase
# 需要导入模块: from cactus.config.router import ConfigRouter [as 别名]
# 或者: from cactus.config.router.ConfigRouter import write [as 别名]
class SiteTestCase(BaseTestCase):
def setUp(self):
super(SiteTestCase, self).setUp()
self.config_path = os.path.join(self.path, 'config.json')
self.conf = ConfigRouter([self.config_path])
self.conf.set('site-url', 'http://example.com/')
for k, v in self.get_config_for_test().items():
self.conf.set(k, v)
self.conf.write()
self.site = Site(self.path, [self.config_path])
self.site._parallel = PARALLEL_DISABLED
def get_config_for_test(self):
"""
Hook to set config keys in other tests.
"""
return {}
示例4: Site
# 需要导入模块: from cactus.config.router import ConfigRouter [as 别名]
# 或者: from cactus.config.router.ConfigRouter import write [as 别名]
class Site(SiteCompatibilityLayer):
_path = None
_parallel = PARALLEL_CONSERVATIVE #TODO: Test me
_static = None
def __init__(self, path, config_paths=None, ui=None,
PluginManagerClass=None, ExternalManagerClass=None, DeploymentEngineClass=None):
# Load the config engine
if config_paths is None:
config_paths = []
self.config = ConfigRouter(config_paths)
# Load site-specific config values
self.prettify_urls = self.config.get('prettify', False)
self.compress_extensions = self.config.get('compress', ['html', 'css', 'js', 'txt', 'xml'])
self.fingerprint_extensions = self.config.get('fingerprint', [])
self.locale = self.config.get("locale", None)
# Verify our location looks correct
self.path = path
self.verify_path()
# Load Managers
if ui is None:
ui = ui_module
self.ui = ui
if PluginManagerClass is None:
PluginManagerClass = PluginManager
self.plugin_manager = PluginManagerClass(self,
[
CustomPluginsLoader(self.plugin_path), # User plugins
ObjectsPluginLoader([ # Builtin plugins
ContextPlugin(), CacheDurationPlugin(),
IgnorePatternsPlugin(), PageContextCompatibilityPlugin(),
])
]
)
if ExternalManagerClass is None:
ExternalManagerClass = ExternalManager
self.external_manager = ExternalManagerClass(self)
if DeploymentEngineClass is None:
hosting_provider = self.config.get("provider", DEFAULT_PROVIDER)
DeploymentEngineClass = get_deployment_engine_class(hosting_provider)
assert DeploymentEngineClass is not None, \
"Could not load Deployment for Provider: {0}".format(hosting_provider)
self.deployment_engine = DeploymentEngineClass(self)
# Load Django settings
self.setup()
@property
def url(self):
return self.config.get('site-url')
@url.setter
def url(self, value):
self.config.set('site-url', value)
self.config.write()
def verify_url(self):
"""
We need the site url to generate the sitemap.
"""
#TODO: Make a "required" option in the config.
#TODO: Use URL tags in the sitemap
# if self.url is None:
# self.url = self.ui.prompt_url("Enter your site URL (e.g. http://example.com/)")
@property
def path(self):
return self._path
@path.setter
def path(self, path):
self._path = path
self.build_path = os.path.join(path, '.build')
self.deploy_path = os.path.join(path, '.deploy')
self.template_path = os.path.join(path, 'templates')
self.page_path = os.path.join(path, 'pages')
self.plugin_path = os.path.join(path, 'plugins')
self.static_path = os.path.join(path, 'static')
self.script_path = os.path.join(os.getcwd(), __file__)
self.locale_path = os.path.join(path, "locale")
def setup(self):
"""
Configure django to use both our template and pages folder as locations
to look for included templates.
"""
settings = {
"TEMPLATE_DIRS": [self.template_path, self.page_path],
"INSTALLED_APPS": ['django_markwhat'],
#.........这里部分代码省略.........
示例5: Site
# 需要导入模块: from cactus.config.router import ConfigRouter [as 别名]
# 或者: from cactus.config.router.ConfigRouter import write [as 别名]
class Site(SiteCompatibilityLayer):
_path = None
_parallel = PARALLEL_CONSERVATIVE #TODO: Test me
_static = None
def __init__(self, path, config_paths=None, ui=None,
PluginManagerClass=None, ExternalManagerClass=None, DeploymentEngineClass=None):
# Load the config engine
if config_paths is None:
config_paths = []
self.config = ConfigRouter(config_paths)
# Load site-specific config values
self.prettify_urls = self.config.get('prettify', False)
self.compress_extensions = self.config.get('compress', ['html', 'css', 'js', 'txt', 'xml'])
self.fingerprint_extensions = self.config.get('fingerprint', [])
self.locale = self.config.get("locale", None)
# Verify our location looks correct
self.path = path
self.verify_path()
# Load Managers
if ui is None:
ui = ui_module
self.ui = ui
if PluginManagerClass is None:
PluginManagerClass = PluginManager
self.plugin_manager = PluginManagerClass(self,
[
CustomPluginsLoader(self.plugin_path), # User plugins
ObjectsPluginLoader([ # Builtin plugins
ContextPlugin(), CacheDurationPlugin(),
IgnorePatternsPlugin(), PageContextCompatibilityPlugin(),
])
]
)
if ExternalManagerClass is None:
ExternalManagerClass = ExternalManager
self.external_manager = ExternalManagerClass(self)
if DeploymentEngineClass is None:
hosting_provider = self.config.get("provider", DEFAULT_PROVIDER)
DeploymentEngineClass = get_deployment_engine_class(hosting_provider)
assert DeploymentEngineClass is not None, \
"Could not load Deployment for Provider: {0}".format(hosting_provider)
self.deployment_engine = DeploymentEngineClass(self)
# Load Django settings
self.setup()
@property
def url(self):
return self.config.get('site-url')
@url.setter
def url(self, value):
self.config.set('site-url', value)
self.config.write()
def verify_url(self):
"""
We need the site url to generate the sitemap.
"""
#TODO: Make a "required" option in the config.
#TODO: Use URL tags in the sitemap
if self.url is None:
self.url = self.ui.prompt_url("Enter your site URL (e.g. http://example.com/), you can change it later.")
@property
def path(self):
return self._path
@path.setter
def path(self, path):
self._path = path
self.build_path = os.path.join(path, '.build')
self.template_path = os.path.join(path, 'templates')
self.page_path = os.path.join(path, 'pages')
self.plugin_path = os.path.join(path, 'plugins')
self.static_path = os.path.join(path, 'static')
self.script_path = os.path.join(os.getcwd(), __file__)
self.locale_path = os.path.join(path, "locale")
def setup(self):
"""
Configure django to use both our template and pages folder as locations
to look for included templates.
"""
settings = {
"TEMPLATE_DIRS": [self.template_path, self.page_path],
"INSTALLED_APPS": ['django.contrib.markup'],
}
#.........这里部分代码省略.........