本文整理汇总了Python中rose.config.ConfigLoader类的典型用法代码示例。如果您正苦于以下问题:Python ConfigLoader类的具体用法?Python ConfigLoader怎么用?Python ConfigLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigLoader类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_access_info
def _get_access_info(self, repos, path_head, txn=None):
"""Return the owner and the access list of a suite (path_head)."""
opt_txn = []
if txn is not None:
opt_txn = ["-t", txn]
t_handle = tempfile.TemporaryFile()
path = path_head + self.TRUNK_INFO_FILE
t_handle.write(self._svnlook("cat", repos, path, *opt_txn))
t_handle.seek(0)
node = ConfigLoader()(t_handle)
t_handle.close()
owner = node.get_value(["owner"])
access_list = node.get_value(["access-list"], "").split()
access_list.sort()
return owner, access_list
示例2: get_conf
def get_conf(self):
"""Return the site/user configuration root node."""
if self.conf is None:
paths = [self.SITE_CONF_PATH, self.USER_CONF_PATH]
if "ROSE_CONF_PATH" in os.environ:
paths_str = os.getenv("ROSE_CONF_PATH").strip()
if paths_str:
paths = paths_str.split(os.pathsep)
else:
paths = []
self.conf = ConfigNode()
config_loader = ConfigLoader()
for path in paths:
name = os.path.join(path, self.ROSE_CONF)
if os.path.isfile(name) and os.access(name, os.R_OK):
config_loader.load_with_opts(name, self.conf)
return self.conf
示例3: get_conf
def get_conf(self):
"""Return the site/user configuration root node."""
if self.conf is None:
paths = [os.path.join(self.get_util_home(), "etc"),
os.path.join(os.path.expanduser("~"), ".metomi")]
if "ROSE_CONF_PATH" in os.environ:
paths_str = os.getenv("ROSE_CONF_PATH").strip()
if paths_str:
paths = paths_str.split(os.pathsep)
else:
paths = []
self.conf = ConfigNode()
config_loader = ConfigLoader()
for path in paths:
file = os.path.join(path, "rose.conf")
if os.path.isfile(file) and os.access(file, os.R_OK):
config_loader.load_with_opts(file, self.conf)
return self.conf
示例4: run_impl
def run_impl(self, opts, args, uuid, work_files):
# Log file, temporary
if hasattr(self.event_handler, "contexts"):
t_file = TemporaryFile()
log_context = ReporterContext(None, self.event_handler.VV, t_file)
self.event_handler.contexts[uuid] = log_context
# Check suite engine specific compatibility
self.suite_engine_proc.check_global_conf_compat()
# Suite name from the current working directory
if opts.conf_dir:
self.fs_util.chdir(opts.conf_dir)
opts.conf_dir = os.getcwd()
if opts.defines_suite:
suite_section = "jinja2:" + self.suite_engine_proc.SUITE_CONF
if not opts.defines:
opts.defines = []
for define in opts.defines_suite:
opts.defines.append("[" + suite_section + "]" + define)
# --remote=KEY=VALUE,...
if opts.remote:
# opts.name always set for remote.
return self._run_remote(opts, opts.name)
conf_tree = self.config_load(opts)
self.fs_util.chdir(conf_tree.conf_dirs[0])
suite_name = opts.name
if not opts.name:
suite_name = os.path.basename(os.getcwd())
# Automatic Rose constants
# ROSE_ORIG_HOST: originating host
# ROSE_VERSION: Rose version (not retained in run_mode=="reload")
# Suite engine version
jinja2_section = "jinja2:" + self.suite_engine_proc.SUITE_CONF
my_rose_version = ResourceLocator.default().get_version()
suite_engine_key = self.suite_engine_proc.get_version_env_name()
if opts.run_mode == "reload":
prev_config_path = self.suite_engine_proc.get_suite_dir(
suite_name, "log", "rose-suite-run.conf")
prev_config = ConfigLoader()(prev_config_path)
suite_engine_version = prev_config.get_value(
["env", suite_engine_key])
else:
suite_engine_version = self.suite_engine_proc.get_version()
auto_items = {"ROSE_ORIG_HOST": socket.gethostname(),
"ROSE_VERSION": ResourceLocator.default().get_version(),
suite_engine_key: suite_engine_version}
for key, val in auto_items.items():
requested_value = conf_tree.node.get_value(["env", key])
if requested_value:
if key == "ROSE_VERSION" and val != requested_value:
exc = VersionMismatchError(requested_value, val)
raise ConfigValueError(["env", key], requested_value, exc)
val = requested_value
else:
conf_tree.node.set(["env", key], val,
state=conf_tree.node.STATE_NORMAL)
conf_tree.node.set([jinja2_section, key], '"' + val + '"')
# See if suite is running or not
hosts = []
if opts.host:
hosts.append(opts.host)
conf = ResourceLocator.default().get_conf()
known_hosts = self.host_selector.expand(
conf.get_value(["rose-suite-run", "hosts"], "").split() +
conf.get_value(["rose-suite-run", "scan-hosts"], "").split() +
["localhost"])[0]
known_hosts = list(set(known_hosts))
for known_host in known_hosts:
if known_host not in hosts:
hosts.append(known_host)
if opts.run_mode == "reload":
suite_run_hosts = self.suite_engine_proc.ping(suite_name, hosts)
if not suite_run_hosts:
raise NotRunningError(suite_name)
hosts = suite_run_hosts
else:
self.suite_engine_proc.check_suite_not_running(suite_name, hosts)
# Install the suite to its run location
suite_dir_rel = self._suite_dir_rel(suite_name)
suite_dir = os.path.join(os.path.expanduser("~"), suite_dir_rel)
suite_conf_dir = os.getcwd()
locs_conf = ConfigNode()
if opts.new_mode:
if os.getcwd() == suite_dir:
raise NewModeError("PWD", os.getcwd())
elif opts.run_mode in ["reload", "restart"]:
raise NewModeError("--run", opts.run_mode)
self.suite_run_cleaner.clean(suite_name)
if os.getcwd() != suite_dir:
#.........这里部分代码省略.........
示例5: main
def main():
"""Implement the "rose config" command."""
opt_parser = RoseOptionParser()
opt_parser.add_my_options("default", "env_var_process_mode", "files",
"keys", "meta", "meta_key", "no_ignore",
"no_opts", "print_conf_mode")
opts, args = opt_parser.parse_args()
report = Reporter(opts.verbosity - opts.quietness)
rose.macro.add_site_meta_paths()
rose.macro.add_env_meta_paths()
if opts.meta_key:
opts.meta = True
if opts.files and opts.meta_key:
report(Exception("Cannot specify both a file and meta key."))
sys.exit(1)
config_loader = ConfigLoader()
sources = []
if opts.files:
root_node = ConfigNode()
for fname in opts.files:
if fname == "-":
sources.append(sys.stdin)
else:
if opts.meta:
try:
root_node = config_loader.load(fname)
except ConfigSyntaxError as e:
report(e)
sys.exit(1)
rel_path = os.sep.join(fname.split(os.sep)[:-1])
fpath = get_meta_path(root_node, rel_path)
if fpath is None:
report(MetadataNotFoundEvent(fname))
else:
sources.append(fpath)
else:
sources.append(fname)
elif opts.meta:
root_node = ConfigNode()
if opts.meta_key:
root_node.set(["meta"], opts.meta_key)
else:
fname = os.path.join(
os.getcwd(), rose.SUB_CONFIG_NAME)
try:
root_node = config_loader.load(fname)
except ConfigSyntaxError as e:
report(e)
sys.exit(1)
fpath = get_meta_path(root_node, meta_key=opts.meta_key)
root_node.unset(["meta"])
if fpath is None:
report(Exception("Metadata not found"))
sys.exit(1)
else:
sources.append(fpath)
else:
root_node = ResourceLocator.default().get_conf()
for source in sources:
try:
if opts.meta or opts.no_opts:
config_loader.load(source, root_node)
else:
config_loader.load_with_opts(source, root_node)
except (ConfigSyntaxError, IOError) as exc:
report(exc)
sys.exit(1)
if source is sys.stdin:
source.close()
if opts.quietness:
sys.exit(root_node.get(args, opts.no_ignore) is None)
if opts.keys_mode:
try:
keys = root_node.get(args, opts.no_ignore).value.keys()
except:
sys.exit(1)
keys.sort()
for key in keys:
print key
sys.exit()
conf_dump = ConfigDumper()
if len(args) == 0:
conf_dump(root_node, concat_mode=opts.print_conf_mode)
sys.exit()
node = root_node.get(args, opts.no_ignore)
if node is not None and isinstance(node.value, dict):
if opts.print_conf_mode:
conf_dump(ConfigNode().set(args, node.value), concat_mode=True)
sys.exit()
#.........这里部分代码省略.........
示例6: __init__
def __init__(self, *args, **kwargs):
self.node_loader = ConfigLoader(*args, **kwargs)
示例7: ConfigTreeLoader
class ConfigTreeLoader(object):
"""Load a Rose configuration with inheritance."""
def __init__(self, *args, **kwargs):
self.node_loader = ConfigLoader(*args, **kwargs)
def load(self, conf_dir, conf_name, conf_dir_paths=None, opt_keys=None,
conf_node=None, no_ignore=False):
"""Load a (runtime) configuration directory with inheritance.
Return a ConfigTree object that represents the result.
conf_dir -- The path to the configuration directory to load.
conf_name -- The (base) name of the configuration file.
E.g. "rose-suite.conf".
conf_dir_paths -- A list of directories to locate relative paths to
configurations.
opt_keys -- Optional configuration keys.
conf_node -- A rose.config.ConfigNode to extend, or None to use a
fresh one.
no_ignore -- If True, skip loading ignored config settings.
"""
if not conf_dir_paths:
conf_dir_paths = []
conf_dir = self._search(conf_dir, [os.getcwd()] + conf_dir_paths)
nodes = {} # {conf_dir: node, ...}
conf_file_name = os.path.join(conf_dir, conf_name)
used_keys = []
nodes[conf_dir] = self.node_loader.load_with_opts(
conf_file_name, more_keys=opt_keys, used_keys=used_keys)
conf_tree = ConfigTree()
conf_tree.conf_dirs = mro(
conf_dir, self._get_base_names, conf_name, conf_dir_paths,
opt_keys, used_keys, nodes)
if opt_keys:
bad_keys = []
for opt_key in opt_keys:
if opt_key not in used_keys:
bad_keys.append(opt_key)
if bad_keys:
raise BadOptionalConfigurationKeysError(bad_keys)
if conf_node is None:
conf_tree.node = ConfigNode()
else:
conf_tree.node = conf_node
for t_conf_dir in conf_tree.conf_dirs:
node = nodes[t_conf_dir]
for keys, sub_node in node.walk(no_ignore=no_ignore):
if keys == ["", "import"]:
continue
if conf_tree.node.get(keys) is None:
conf_tree.node.set(keys, sub_node.value, sub_node.state,
sub_node.comments)
for dir_path, dir_names, file_names in os.walk(t_conf_dir):
names = [dir_ for dir_ in dir_names if dir_.startswith(".")]
for name in names:
dir_names.remove(name)
for file_name in file_names:
if file_name == conf_name or file_name.startswith("."):
continue
path = os.path.join(dir_path, file_name)
rel_path = os.path.relpath(path, t_conf_dir)
if rel_path not in conf_tree.files:
conf_tree.files[rel_path] = t_conf_dir
if rel_path not in conf_tree.file_locs:
conf_tree.file_locs[rel_path] = []
conf_tree.file_locs[rel_path].append(t_conf_dir)
return conf_tree
__call__ = load
def _get_base_names(self, my_conf_dir, conf_name, conf_dir_paths, opt_keys,
used_keys, nodes):
"""Return a list of configuration directories to import."""
values = shlex.split(nodes[my_conf_dir].get_value(["import"], ""))
i_conf_dirs = []
for value in values:
i_conf_dir = self._search(
value, [os.path.dirname(my_conf_dir)] + conf_dir_paths)
i_conf_file_name = os.path.join(i_conf_dir, conf_name)
if nodes.get(i_conf_dir) is None:
nodes[i_conf_dir] = self.node_loader.load_with_opts(
i_conf_file_name, more_keys=opt_keys,
used_keys=used_keys)
i_conf_dirs.append(i_conf_dir)
return i_conf_dirs
@classmethod
def _search(cls, conf_dir, conf_dir_paths):
"""Search for named a configuration directory from a list of paths."""
if os.path.isabs(conf_dir):
return os.path.abspath(conf_dir)
for conf_dir_path in conf_dir_paths:
#.........这里部分代码省略.........
示例8: run_impl
def run_impl(self, opts, args, uuid, work_files):
# Log file, temporary
if hasattr(self.event_handler, "contexts"):
t_file = TemporaryFile()
log_context = ReporterContext(None, self.event_handler.VV, t_file)
self.event_handler.contexts[uuid] = log_context
# Check suite engine specific compatibility
self.suite_engine_proc.check_global_conf_compat()
# Suite name from the current working directory
if opts.conf_dir:
self.fs_util.chdir(opts.conf_dir)
opts.conf_dir = os.getcwd()
# --remote=KEY=VALUE,...
if opts.remote:
# opts.name always set for remote.
return self._run_remote(opts, opts.name)
conf_tree = self.config_load(opts)
self.fs_util.chdir(conf_tree.conf_dirs[0])
suite_name = opts.name
if not opts.name:
suite_name = os.path.basename(os.getcwd())
# Check suite.rc #! line for template scheme
templ_scheme = "jinja2"
if self.suite_engine_proc.SUITE_CONF in conf_tree.files:
suiterc_path = os.path.join(
conf_tree.files[self.suite_engine_proc.SUITE_CONF],
self.suite_engine_proc.SUITE_CONF)
with open(suiterc_path) as fh:
line = fh.readline()
if line.startswith("#!"):
templ_scheme = line[2:].strip().lower()
suite_section = (templ_scheme + ':' +
self.suite_engine_proc.SUITE_CONF)
extra_defines = []
if opts.defines_suite:
for define in opts.defines_suite:
extra_defines.append("[" + suite_section + "]" + define)
# Automatic Rose constants
# ROSE_ORIG_HOST: originating host
# ROSE_VERSION: Rose version (not retained in run_mode=="reload")
# Suite engine version
my_rose_version = ResourceLocator.default().get_version()
suite_engine_key = self.suite_engine_proc.get_version_env_name()
if opts.run_mode in ["reload", "restart"]:
prev_config_path = self.suite_engine_proc.get_suite_dir(
suite_name, "log", "rose-suite-run.conf")
prev_config = ConfigLoader()(prev_config_path)
suite_engine_version = prev_config.get_value(
["env", suite_engine_key])
else:
suite_engine_version = self.suite_engine_proc.get_version()
resloc = ResourceLocator.default()
auto_items = [
(suite_engine_key, suite_engine_version),
("ROSE_ORIG_HOST", self.host_selector.get_local_host()),
("ROSE_SITE", resloc.get_conf().get_value(['site'], '')),
("ROSE_VERSION", resloc.get_version())]
for key, val in auto_items:
requested_value = conf_tree.node.get_value(["env", key])
if requested_value:
if key == "ROSE_VERSION" and val != requested_value:
exc = VersionMismatchError(requested_value, val)
raise ConfigValueError(["env", key], requested_value, exc)
val = requested_value
else:
conf_tree.node.set(["env", key], val,
state=conf_tree.node.STATE_NORMAL)
extra_defines.append('[%s]%s="%s"' % (suite_section, key, val))
# Pass automatic Rose constants as suite defines
self.conf_tree_loader.node_loader.load_defines(extra_defines,
conf_tree.node)
# See if suite is running or not
if opts.run_mode == "reload":
# Check suite is running
self.suite_engine_proc.get_suite_contact(suite_name)
else:
self.suite_engine_proc.check_suite_not_running(suite_name)
# Install the suite to its run location
suite_dir_rel = self._suite_dir_rel(suite_name)
# Unfortunately a large try/finally block to ensure a temporary folder
# created in validate only mode is cleaned up. Exceptions are not
# caught here
try:
# Process Environment Variables
environ = self.config_pm(conf_tree, "env")
if opts.validate_suite_only_mode:
temp_dir = mkdtemp()
#.........这里部分代码省略.........