1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 CLI configuration mechanism.
22 from ruamel import yaml
24 from jinja2.environment import Template
27 CONFIG_FILE_NAME = 'config.yaml'
30 class CliConfig(object):
32 def __init__(self, config_path):
33 with open(config_path) as f:
34 self._config = yaml.safe_load(f.read())
37 def create_config(cls, workdir):
38 config_path = os.path.join(workdir, CONFIG_FILE_NAME)
39 if not os.path.isfile(config_path):
40 config_template = pkg_resources.resource_string(
42 'config_template.yaml')
45 'log_path': os.path.join(workdir, 'cli.log'),
49 template = Template(config_template)
50 rendered = template.render(**default_values)
51 with open(config_path, 'w') as f:
55 return cls(config_path)
59 return self.Logging(self._config.get('logging'))
61 class Logging(object):
63 def __init__(self, logging):
64 self._logging = logging or {}
68 return self._logging.get('filename')
72 return self._logging.get('loggers', {})
76 return self.Execution(self._logging.get('execution'))
78 class Execution(object):
80 def __init__(self, execution_logging):
81 self._execution_logging = execution_logging
84 def colors_enabled(self):
85 return self.colors.get('enabled', False)
89 return self._execution_logging.get('colors', {})
93 return self._execution_logging.get('formats', {})