Revision 8614814c kamaki/config.py

b/kamaki/config.py
90 90
        self.path = path or os.environ.get(CONFIG_ENV, CONFIG_PATH)
91 91
        self._overrides = defaultdict(dict)
92 92
        self.read(self.path)
93
    
93

  
94 94
    def sections(self):
95 95
        return DEFAULTS.keys()
96
    
96

  
97 97
    def get(self, section, option):
98 98
        value = self._overrides.get(section, {}).get(option)
99 99
        if value is not None:
100 100
            return value
101
        
101

  
102 102
        try:
103 103
            return RawConfigParser.get(self, section, option)
104 104
        except (NoSectionError, NoOptionError):
105 105
            return DEFAULTS.get(section, {}).get(option)
106
    
106

  
107 107
    def set(self, section, option, value):
108 108
        if section not in RawConfigParser.sections(self):
109 109
            self.add_section(section)
110 110
        RawConfigParser.set(self, section, option, value)
111
    
111

  
112 112
    def remove_option(self, section, option):
113 113
        try:
114 114
            RawConfigParser.remove_option(self, section, option)
115 115
        except NoSectionError:
116 116
            pass
117
    
117

  
118 118
    def items(self, section, include_defaults=False):
119 119
        d = dict(DEFAULTS[section]) if include_defaults else {}
120 120
        try:
......
122 122
        except NoSectionError:
123 123
            pass
124 124
        return d.items()
125
    
125

  
126 126
    def override(self, section, option, value):
127 127
        self._overrides[section][option] = value
128
    
128

  
129 129
    def write(self):
130 130
        with open(self.path, 'w') as f:
131 131
            os.chmod(self.path, 0600)

Also available in: Unified diff