~jimbaker/pyjuju/robust-zk-connect

« back to all changes in this revision

Viewing changes to juju/charm/config.py

  • Committer: kapil.thangavelu at canonical
  • Date: 2011-10-14 15:49:47 UTC
  • mfrom: (391.5.6 config-get)
  • Revision ID: kapil.thangavelu@canonical.com-20111014154947-9k774jhmnpttm9pg
merge config-get [r=fwereade,bcsaller][f=828326]

New juju subcommand for inspecting a service's current configuration and schema.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import copy
 
2
import os
1
3
import sys
2
 
import os
3
4
 
4
5
import yaml
5
6
 
9
10
 
10
11
OPTION_SCHEMA = KeyDict({
11
12
        "type": OneOf(Constant("string"),
12
 
                      Constant("str"), # Obsolete
 
13
                      Constant("str"),  # Obsolete
13
14
                      Constant("int"),
14
15
                      Constant("float")),
15
16
        "default": OneOf(String(), Int(), Float()),
37
38
    def __init__(self):
38
39
        self._data = {}
39
40
 
 
41
    def as_dict(self):
 
42
        return copy.deepcopy(self._data)
 
43
 
40
44
    def load(self, pathname):
41
45
        """Construct a ConfigOptions instance from a YAML file.
42
46
 
45
49
        """
46
50
        data = None
47
51
        if os.path.exists(pathname):
48
 
            data = open(pathname, "r").read()
 
52
            with open(pathname) as fh:
 
53
                data = fh.read()
49
54
        else:
50
55
            pathname = None
51
56
            data = "options: {}\n"