~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-04-04 15:31:16 UTC
  • mto: (5743.5.1 config-concrete-stores)
  • mto: This revision was merged to the branch mainline in revision 5832.
  • Revision ID: v.ladeuil+lp@free.fr-20110404153116-86oshhkw9nboow6z
Implement store.get_sections() as an iterator and provides the configobj implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2038
2038
    def load(self):
2039
2039
        raise NotImplementedError(self.load)
2040
2040
 
 
2041
    def save(self):
 
2042
        raise NotImplementedError(self.load)
 
2043
 
 
2044
    def get_sections(self):
 
2045
        """Returns an ordered iterable of existing sections.
 
2046
 
 
2047
        :returns: An iterable of (name, dict).
 
2048
        """
 
2049
        raise NotImplementedError(self.get_sections)
 
2050
 
2041
2051
 
2042
2052
class ConfigObjStore(Store):
2043
2053
 
2100
2110
        self._config_obj.write(out)
2101
2111
        self.transport.put_bytes(self.file_name, out.getvalue())
2102
2112
 
 
2113
    def get_sections(self):
 
2114
        """Get the configobj section in the file order.
 
2115
 
 
2116
        :returns: An iterable of (name, dict).
 
2117
        """
 
2118
        # We need a loaded store
 
2119
        self.load()
 
2120
        cobj = self._config_obj
 
2121
        if cobj.scalars:
 
2122
            yield None, dict([(k, cobj[k]) for k in cobj.scalars])
 
2123
        for section_name in cobj.sections:
 
2124
            yield section_name, dict(cobj[section_name])
 
2125
 
2103
2126
 
2104
2127
class cmd_config(commands.Command):
2105
2128
    __doc__ = """Display, set or remove a configuration option.