mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Finished Env._finalize_core() and corresponding unit tests
This commit is contained in:
@@ -145,13 +145,20 @@ class Env(object):
|
||||
self.home = path.abspath(os.environ['HOME'])
|
||||
self.dot_ipa = path.join(self.home, '.ipa')
|
||||
|
||||
def __do(self, name):
|
||||
def __doing(self, name):
|
||||
if name in self.__done:
|
||||
raise StandardError(
|
||||
'%s.%s() already called' % (self.__class__.__name__, name)
|
||||
)
|
||||
self.__done.add(name)
|
||||
|
||||
def __do_if_not_done(self, name):
|
||||
if name not in self.__done:
|
||||
getattr(self, name)()
|
||||
|
||||
def _isdone(self, name):
|
||||
return name in self.__done
|
||||
|
||||
def _bootstrap(self, **overrides):
|
||||
"""
|
||||
Initialize basic environment.
|
||||
@@ -159,10 +166,8 @@ class Env(object):
|
||||
This method will initialize only enough environment information to
|
||||
determine whether ipa is running in-tree, what the context is,
|
||||
and the location of the configuration file.
|
||||
|
||||
This method should be called before any plugins are loaded.
|
||||
"""
|
||||
self.__do('_bootstrap')
|
||||
self.__doing('_bootstrap')
|
||||
for (key, value) in overrides.items():
|
||||
self[key] = value
|
||||
if 'in_tree' not in self:
|
||||
@@ -180,7 +185,46 @@ class Env(object):
|
||||
else:
|
||||
self.conf = path.join('/', 'etc', 'ipa', name)
|
||||
|
||||
def _load_config(self, conf_file):
|
||||
def _finalize_core(self, **defaults):
|
||||
"""
|
||||
Complete initialization of standard IPA environment.
|
||||
|
||||
After this method is called, the all environment variables
|
||||
used by all the built-in plugins will be available.
|
||||
|
||||
This method should be called before loading any plugins. It will
|
||||
automatically call `Env._bootstrap()` if it has not yet been called.
|
||||
|
||||
After this method has finished, the `Env` instance is still writable
|
||||
so that third
|
||||
"""
|
||||
self.__doing('_finalize_core')
|
||||
self.__do_if_not_done('_bootstrap')
|
||||
self._merge_config(self.conf)
|
||||
if 'in_server' not in self:
|
||||
self.in_server = (self.context == 'server')
|
||||
if 'log' not in self:
|
||||
name = '%s.log' % self.context
|
||||
if self.in_tree or self.context == 'cli':
|
||||
self.log = path.join(self.dot_ipa, 'log', name)
|
||||
else:
|
||||
self.log = path.join('/', 'var', 'log', 'ipa', name)
|
||||
for (key, value) in defaults.items():
|
||||
if key not in self:
|
||||
self[key] = value
|
||||
|
||||
def _finalize(self):
|
||||
"""
|
||||
Finalize and lock environment.
|
||||
|
||||
This method should be called after all plugins have bean loaded and
|
||||
after `plugable.API.finalize()` has been called.
|
||||
"""
|
||||
self.__doing('_finalize')
|
||||
self.__do_if_not_done('_finalize_core')
|
||||
self.__lock__()
|
||||
|
||||
def _merge_config(self, conf_file):
|
||||
"""
|
||||
Merge in values from ``conf_file`` into this `Env`.
|
||||
"""
|
||||
@@ -204,14 +248,6 @@ class Env(object):
|
||||
i += 1
|
||||
return (i, len(items))
|
||||
|
||||
def _finalize(self, **defaults):
|
||||
"""
|
||||
Finalize and lock environment.
|
||||
|
||||
This method should be called after all plugins have bean loaded and
|
||||
after `plugable.API.finalize()` has been called.
|
||||
"""
|
||||
|
||||
def __lock__(self):
|
||||
"""
|
||||
Prevent further changes to environment.
|
||||
|
||||
@@ -21,5 +21,41 @@
|
||||
Constants centralized in one file.
|
||||
"""
|
||||
|
||||
# The section read in config files, i.e. [global]
|
||||
# The section to read in the config files, i.e. [global]
|
||||
CONFIG_SECTION = 'global'
|
||||
|
||||
|
||||
# The default configuration for api.env
|
||||
DEFAULT_CONFIG = (
|
||||
('lite_xmlrpc_port', 8888),
|
||||
('lite_webui_port', 9999),
|
||||
('xmlrpc_uri', 'http://localhost:8888'),
|
||||
('ldap_uri', ''),
|
||||
|
||||
('verbose', False),
|
||||
('debug', False),
|
||||
|
||||
# Env.__init__() or Env._bootstrap() or Env._finalize_core()
|
||||
# will have filled in all the keys below by the time DEFAULT_CONFIG
|
||||
# is merged in, so the values below are never actually used. They are
|
||||
# listed both to provide a big picture and so DEFAULT_CONFIG contains
|
||||
# the keys that should be present after Env._load_standard is called.
|
||||
|
||||
# Set in Env.__init__():
|
||||
('ipalib', None), # The directory containing ipalib/__init__.py
|
||||
('site_packages', None), # The directory contaning ipalib
|
||||
('script', None), # sys.argv[0]
|
||||
('bin', None), # The directory containing script
|
||||
('home', None), # The home directory of user underwhich process is running
|
||||
('dot_ipa', None), # ~/.ipa directory
|
||||
|
||||
# Set in Env._bootstrap():
|
||||
('in_tree', None), # Whether or not running in-tree (bool)
|
||||
('context', None), # Name of context, default is 'default'
|
||||
('conf', None), # Path to configuration file
|
||||
|
||||
# Set in Env._finalize_core():
|
||||
('in_server', None), # Whether or not running in-server (bool)
|
||||
('log', None), # Path to log file
|
||||
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user