45552fde467689be318962d4f60d5c035b1fc829
[osm/riftware.git] /
1
2 import os
3 import yaml
4
5
6 class LayerOptions(dict):
7     def __init__(self, layer_file, section=None):
8         with open(layer_file) as f:
9             layer = yaml.safe_load(f.read())
10         opts = layer.get('options', {})
11         if section and section in opts:
12             super(LayerOptions, self).__init__(opts.get(section))
13         else:
14             super(LayerOptions, self).__init__(opts)
15
16
17 def options(section=None, layer_file=None):
18     if not layer_file:
19         base_dir = os.environ.get('CHARM_DIR', os.getcwd())
20         layer_file = os.path.join(base_dir, 'layer.yaml')
21
22     return LayerOptions(layer_file, section)