예제 #1
0
파일: pods.py 프로젝트: cdhermann/grow
    def __init__(self,
                 root,
                 storage=grow_storage.AUTO,
                 env=None,
                 load_extensions=True):
        self.deprecated = deprecated.DeprecationManager(self.logger.warn)
        self._yaml = utils.SENTINEL
        self.storage = storage
        self.root = (root if self.storage.is_cloud_storage else
                     os.path.abspath(root))
        self.env = (env if env else environment.Env(
            environment.EnvConfig(host='localhost')))
        self.locales = locales.Locales(pod=self)
        self.catalogs = catalog_holder.Catalogs(pod=self)
        self._jinja_env_lock = threading.RLock()
        self._podcache = None
        self._features = features.Features(disabled=[
            self.FEATURE_TRANSLATION_STATS,
            self.FEATURE_OLD_SLUGIFY,
        ])
        self._experiments = features.Features(default_enabled=False)

        self._extensions_controller = ext_controller.ExtensionController(self)

        if self.exists:
            # Modify sys.path for built-in extension support.
            _ext_dir = self.abs_path(self.extensions_dir)
            if os.path.exists(_ext_dir):
                sys.path.insert(0, _ext_dir)

            # Load the features from the podspec.
            self._load_features()

            # Load the experiments from the podspec.
            self._load_experiments()

        # Ensure preprocessors are loaded when pod is initialized.
        # Preprocessors may modify the environment in ways that are required by
        # data files (e.g. yaml constructors). Avoid loading extensions using
        # `load_extensions=False` to permit `grow install` to be used to
        # actually install extensions, prior to loading them.
        if load_extensions and self.exists:
            self.list_preprocessors()

        # Load extensions, ignore local extensions during install.
        self._load_extensions(load_extensions)

        try:
            update_checker = updater.Updater(self)
            update_checker.verify_required_version()
        except PodDoesNotExistError:
            pass  # Pod doesn't exist yet, simply pass.
예제 #2
0
 def test_enable_without_config(self):
     """Enabling feature without a config."""
     feat = features.Features(default_enabled=False)
     self.assertFalse(feat.is_enabled('a'))
     feat.enable('a')
     self.assertTrue(feat.is_enabled('a'))
     self.assertEqual({}, feat.config('a').export())
예제 #3
0
    def features(self):
        """Collection features."""
        coll_features = features.Features(disabled=[
            self.FEATURE_SEPARATE_ROUTING,
        ])

        # Enable the separate_routing feature if there are routes specified.
        if self.yaml.get('routes', {}):
            coll_features.enable(self.FEATURE_SEPARATE_ROUTING)

        return coll_features
예제 #4
0
    def __init__(self, pod, config):
        self.pod = pod
        self.config = config
        self.hooks = features.Features(default_enabled=False)

        if 'enabled' in self.config:
            for hook in self.config['enabled']:
                self.hooks.enable(hook)
        else:
            for hook in self.available_hooks:
                self.hooks.enable(hook.KEY)

        if 'disabled' in self.config:
            for hook in self.config['disabled']:
                self.hooks.disable(hook)
예제 #5
0
 def test_default_enabled(self):
     """Does the default enabled work?"""
     feat = features.Features(default_enabled=True)
     self.assertTrue(feat.is_enabled('unknown'))
예제 #6
0
 def test_is_enabled_enabled_with_default_enabled_false(self):
     """Enabled features."""
     feat = features.Features(enabled=['a', 'b'], default_enabled=False)
     self.assertTrue(feat.is_enabled('a'))
     self.assertTrue(feat.is_enabled('b'))
     self.assertFalse(feat.is_enabled('c'))
예제 #7
0
 def test_is_enabled_enabled(self):
     """Enabled features."""
     feat = features.Features(enabled=['a', 'b'])
     self.assertTrue(feat.is_enabled('a'))
     self.assertTrue(feat.is_enabled('b'))
     self.assertTrue(feat.is_enabled('c'))
예제 #8
0
 def test_default_enabled_false(self):
     """Does the default disabled work?"""
     feat = features.Features(default_enabled=False)
     self.assertFalse(feat.is_enabled('unknown'))
예제 #9
0
 def test_enable(self):
     """Enabling feature."""
     feat = features.Features(default_enabled=False)
     self.assertFalse(feat.is_enabled('a'))
     feat.enable('a')
     self.assertTrue(feat.is_enabled('a'))
예제 #10
0
 def test_callable_enabled(self):
     """Callable shortcut for testing for enabled features."""
     feat = features.Features(enabled=['a'], default_enabled=False)
     self.assertTrue(feat('a'))
     self.assertFalse(feat('b'))