Show More
@@ -61,6 +61,19 class config(object): | |||||
61 | self._source.update(src._source) |
|
61 | self._source.update(src._source) | |
62 | def get(self, section, item, default=None): |
|
62 | def get(self, section, item, default=None): | |
63 | return self._data.get(section, {}).get(item, default) |
|
63 | return self._data.get(section, {}).get(item, default) | |
|
64 | ||||
|
65 | def backup(self, section, item): | |||
|
66 | """return a tuple allowing restore to reinstall a previous valuesi | |||
|
67 | ||||
|
68 | The main reason we need it is because it handle the "no data" case. | |||
|
69 | """ | |||
|
70 | try: | |||
|
71 | value = self._data[section][item] | |||
|
72 | source = self.source(section, item) | |||
|
73 | return (section, item, value, source) | |||
|
74 | except KeyError: | |||
|
75 | return (section, item) | |||
|
76 | ||||
64 | def source(self, section, item): |
|
77 | def source(self, section, item): | |
65 | return self._source.get((section, item), "") |
|
78 | return self._source.get((section, item), "") | |
66 | def sections(self): |
|
79 | def sections(self): | |
@@ -73,6 +86,20 class config(object): | |||||
73 | self._data[section][item] = value |
|
86 | self._data[section][item] = value | |
74 | self._source[(section, item)] = source |
|
87 | self._source[(section, item)] = source | |
75 |
|
88 | |||
|
89 | def restore(self, data): | |||
|
90 | """restore data returned by self.backup""" | |||
|
91 | if len(data) == 4: | |||
|
92 | # restore old data | |||
|
93 | section, item, value, source = data | |||
|
94 | self._data[section][item] = value | |||
|
95 | self._source[(section, item)] = source | |||
|
96 | else: | |||
|
97 | # no data before, remove everything | |||
|
98 | section, item = data | |||
|
99 | if section in self._data: | |||
|
100 | del self._data[section][item] | |||
|
101 | self._source.pop((section, item), None) | |||
|
102 | ||||
76 | def parse(self, src, data, sections=None, remap=None, include=None): |
|
103 | def parse(self, src, data, sections=None, remap=None, include=None): | |
77 | sectionre = re.compile(r'\[([^\[]+)\]') |
|
104 | sectionre = re.compile(r'\[([^\[]+)\]') | |
78 | itemre = re.compile(r'([^=\s][^=]*?)\s*=\s*(.*\S|)') |
|
105 | itemre = re.compile(r'([^=\s][^=]*?)\s*=\s*(.*\S|)') |
@@ -142,6 +142,15 class ui(object): | |||||
142 | self._trustusers.update(self.configlist('trusted', 'users')) |
|
142 | self._trustusers.update(self.configlist('trusted', 'users')) | |
143 | self._trustgroups.update(self.configlist('trusted', 'groups')) |
|
143 | self._trustgroups.update(self.configlist('trusted', 'groups')) | |
144 |
|
144 | |||
|
145 | def backupconfig(self, section, item): | |||
|
146 | return (self._ocfg.backup(section, item), | |||
|
147 | self._tcfg.backup(section, item), | |||
|
148 | self._ucfg.backup(section, item),) | |||
|
149 | def restoreconfig(self, data): | |||
|
150 | self._ocfg.restore(data[0]) | |||
|
151 | self._tcfg.restore(data[1]) | |||
|
152 | self._ucfg.restore(data[2]) | |||
|
153 | ||||
145 | def setconfig(self, section, name, value, overlay=True): |
|
154 | def setconfig(self, section, name, value, overlay=True): | |
146 | if overlay: |
|
155 | if overlay: | |
147 | self._ocfg.set(section, name, value) |
|
156 | self._ocfg.set(section, name, value) |
General Comments 0
You need to be logged in to leave comments.
Login now