~ibmcharmers/charms/trusty/layer-ibm-mobilefirst-server/devel

« back to all changes in this revision

Viewing changes to deps/layer/layer-basic/lib/charms/layer/__init__.py

  • Committer: Suchitra Venugopal
  • Date: 2016-09-06 09:48:53 UTC
  • Revision ID: suchvenu@in.ibm.com-20160906094853-1n09myeisek096nm
IBM MobileFirst Server

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)