13 def dupconfig(orig): |
13 def dupconfig(orig): |
14 new = util.configparser(orig.defaults()) |
14 new = util.configparser(orig.defaults()) |
15 updateconfig(orig, new) |
15 updateconfig(orig, new) |
16 return new |
16 return new |
17 |
17 |
18 def updateconfig(source, dest): |
18 def updateconfig(source, dest, sections=None): |
19 for section in source.sections(): |
19 if not sections: |
|
20 sections = source.sections() |
|
21 for section in sections: |
20 if not dest.has_section(section): |
22 if not dest.has_section(section): |
21 dest.add_section(section) |
23 dest.add_section(section) |
22 for name, value in source.items(section, raw=True): |
24 for name, value in source.items(section, raw=True): |
23 dest.set(section, name, value) |
25 dest.set(section, name, value) |
24 |
26 |
97 for hook in self.readhooks: |
99 for hook in self.readhooks: |
98 hook(self) |
100 hook(self) |
99 |
101 |
100 def addreadhook(self, hook): |
102 def addreadhook(self, hook): |
101 self.readhooks.append(hook) |
103 self.readhooks.append(hook) |
|
104 |
|
105 def readsections(self, filename, *sections): |
|
106 "read filename and add only the specified sections to the config data" |
|
107 if not sections: |
|
108 return |
|
109 |
|
110 cdata = util.configparser() |
|
111 try: |
|
112 cdata.read(filename) |
|
113 except ConfigParser.ParsingError, inst: |
|
114 raise util.Abort(_("failed to parse %s\n%s") % (f, inst)) |
|
115 |
|
116 for section in sections: |
|
117 if not cdata.has_section(section): |
|
118 cdata.add_section(section) |
|
119 |
|
120 updateconfig(cdata, self.cdata, sections) |
102 |
121 |
103 def fixconfig(self, section=None, name=None, value=None, root=None): |
122 def fixconfig(self, section=None, name=None, value=None, root=None): |
104 # translate paths relative to root (or home) into absolute paths |
123 # translate paths relative to root (or home) into absolute paths |
105 if section is None or section == 'paths': |
124 if section is None or section == 'paths': |
106 if root is None: |
125 if root is None: |