當前位置: 首頁>>代碼示例>>Python>>正文


Python router.ConfigRouter類代碼示例

本文整理匯總了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)
開發者ID:beaufour,項目名稱:Cactus,代碼行數:9,代碼來源:test_config.py

示例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)
開發者ID:beaufour,項目名稱:Cactus,代碼行數:10,代碼來源:test_config.py

示例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"))
開發者ID:beaufour,項目名稱:Cactus,代碼行數:11,代碼來源:test_config.py

示例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)
開發者ID:beaufour,項目名稱:Cactus,代碼行數:13,代碼來源:test_config.py

示例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")
開發者ID:CILP,項目名稱:Cactus,代碼行數:13,代碼來源:test_config.py

示例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")
開發者ID:beaufour,項目名稱:Cactus,代碼行數:14,代碼來源:test_config.py

示例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")
開發者ID:CILP,項目名稱:Cactus,代碼行數:15,代碼來源:test_config.py

示例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)
開發者ID:beaufour,項目名稱:Cactus,代碼行數:16,代碼來源:test_config.py

示例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
開發者ID:beaufour,項目名稱:Cactus,代碼行數:11,代碼來源:__init__.py

示例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()
開發者ID:eudicots,項目名稱:Cactus,代碼行數:50,代碼來源:site.py

示例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 {}
開發者ID:beaufour,項目名稱:Cactus,代碼行數:18,代碼來源:__init__.py

示例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'],
#.........這裏部分代碼省略.........
開發者ID:DjangoBD,項目名稱:Cactus,代碼行數:101,代碼來源:site.py

示例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'],
        }
#.........這裏部分代碼省略.........
開發者ID:krallin,項目名稱:Cactus,代碼行數:101,代碼來源:site.py


注:本文中的cactus.config.router.ConfigRouter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。