本文整理汇总了Python中cactus.config.router.ConfigRouter类的典型用法代码示例。如果您正苦于以下问题:Python ConfigRouter类的具体用法?Python ConfigRouter怎么用?Python ConfigRouter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigRouter类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read
def test_read(self):
"""
Check that the config router reads correctly from the filesystem
"""
router = ConfigRouter([self.path1, self.path2])
self.assertEqual(router.get("a"), 1)
self.assertEqual(router.get("b"), 2)
self.assertEqual(router.get("c"), None)
示例2: test_duplicate
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)
示例3: test_read_write
def test_read_write(self):
"""
Check that our config is readable after writing it
"""
router = ConfigRouter([self.path1, self.path2])
router.set("a", 3)
router.set("b", 4)
self.assertEqual(3, router.get("a"))
self.assertEqual(4, router.get("b"))
示例4: test_collision
def test_collision(self):
"""
Check that we get the right key when there is a collision
"""
self.conf1.set("b", 3)
self.conf2.set("a", 4)
self.conf1.write()
self.conf2.write()
router = ConfigRouter([self.path1, self.path2])
self.assertEqual(router.get("a"), 1)
self.assertEqual(router.get("b"), 3)
示例5: test_missing_file
def test_missing_file(self):
"""
Test that we don't throw on a missing file, and that the configuration
remains in a consistent state.
"""
wrong_path = os.path.join(self.path, "does_not_exist.json")
self.conf1.set("context", {"k1":"v1"})
self.conf1.write()
router = ConfigRouter([wrong_path, self.path1])
self.assertEqual(router.get("context").get("k1"), "v1")
示例6: test_nested
def test_nested(self):
"""
Test that we support nested config for context
"""
self.conf1.set("context", {"k1": "v1"})
self.conf2.set("context", {"k2": "v2"})
self.conf1.write()
self.conf2.write()
router = ConfigRouter([self.path1, self.path2])
context = router.get("context", default={}, nested=True)
self.assertEqual(context.get("k1"), "v1")
self.assertEqual(context.get("k2"), "v2")
示例7: test_broken_file
def test_broken_file(self):
"""
Test that we don't throw on a broken file, and that the configuration
remains in a consistent state.
"""
with open(self.path1, "w") as f:
f.write("{broken}")
self.conf2.set("context", {"k1":"v1"})
self.conf2.write()
router = ConfigRouter([self.path1, self.path2])
self.assertEqual(router.get("context").get("k1"), "v1")
示例8: test_write
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)
示例9: setUp
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
示例10: __init__
def __init__(self, path, config_paths=None, ui=None,
PluginManagerClass=None, ExternalManagerClass=None, DeploymentEngineClass=None,
verb=VERB_UNKNOWN):
# Load the config engine
if config_paths is None:
config_paths = []
self.config = ConfigRouter(config_paths)
self.verb = verb
# 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()
示例11: SiteTestCase
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 {}
示例12: Site
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'],
#.........这里部分代码省略.........
示例13: Site
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'],
}
#.........这里部分代码省略.........