~postgresql-charmers/postgresql-charm/built

« back to all changes in this revision

Viewing changes to lib/charms/layer/__init__.py

  • Committer: Stuart Bishop
  • Date: 2016-02-18 10:53:55 UTC
  • Revision ID: git-v1:a0c4e5cb498bcf9402f52809730edbd220edf665
charm-build of master

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
 
3
 
 
4
class LayerOptions(dict):
 
5
    def __init__(self, layer_file, section=None):
 
6
        import yaml  # defer, might not be available until bootstrap
 
7
        with open(layer_file) as f:
 
8
            layer = yaml.safe_load(f.read())
 
9
        opts = layer.get('options', {})
 
10
        if section and section in opts:
 
11
            super(LayerOptions, self).__init__(opts.get(section))
 
12
        else:
 
13
            super(LayerOptions, self).__init__(opts)
 
14
 
 
15
 
 
16
def options(section=None, layer_file=None):
 
17
    if not layer_file:
 
18
        base_dir = os.environ.get('CHARM_DIR', os.getcwd())
 
19
        layer_file = os.path.join(base_dir, 'layer.yaml')
 
20
 
 
21
    return LayerOptions(layer_file, section)