Show More
@@ -35,9 +35,8 b' class ui(object):' | |||||
35 | self.trusted_users = {} |
|
35 | self.trusted_users = {} | |
36 | self.trusted_groups = {} |
|
36 | self.trusted_groups = {} | |
37 | self.overlay = util.configparser() |
|
37 | self.overlay = util.configparser() | |
38 | # if ucdata is not None, its keys must be a superset of cdata's |
|
|||
39 | self.cdata = util.configparser() |
|
38 | self.cdata = util.configparser() | |
40 |
self.ucdata = |
|
39 | self.ucdata = util.configparser() | |
41 | # we always trust global config files |
|
40 | # we always trust global config files | |
42 | self.readconfig(util.rcpath(), assumetrusted=True) |
|
41 | self.readconfig(util.rcpath(), assumetrusted=True) | |
43 | else: |
|
42 | else: | |
@@ -47,8 +46,7 b' class ui(object):' | |||||
47 | self.trusted_groups = parentui.trusted_groups.copy() |
|
46 | self.trusted_groups = parentui.trusted_groups.copy() | |
48 | self.cdata = dupconfig(self.parentui.cdata) |
|
47 | self.cdata = dupconfig(self.parentui.cdata) | |
49 | self.overlay = dupconfig(self.parentui.overlay) |
|
48 | self.overlay = dupconfig(self.parentui.overlay) | |
50 |
|
|
49 | self.ucdata = dupconfig(self.parentui.ucdata) | |
51 | self.ucdata = dupconfig(self.parentui.ucdata) |
|
|||
52 | if self.parentui is not parentui: |
|
50 | if self.parentui is not parentui: | |
53 | self.overlay = util.configparser() |
|
51 | self.overlay = util.configparser() | |
54 | updateconfig(parentui.overlay, self.overlay) |
|
52 | updateconfig(parentui.overlay, self.overlay) | |
@@ -88,6 +86,8 b' class ui(object):' | |||||
88 | return True |
|
86 | return True | |
89 |
|
87 | |||
90 | def readconfig(self, fn, root=None, assumetrusted=False): |
|
88 | def readconfig(self, fn, root=None, assumetrusted=False): | |
|
89 | cdata = util.configparser() | |||
|
90 | ||||
91 | if isinstance(fn, basestring): |
|
91 | if isinstance(fn, basestring): | |
92 | fn = [fn] |
|
92 | fn = [fn] | |
93 | for f in fn: |
|
93 | for f in fn: | |
@@ -95,16 +95,8 b' class ui(object):' | |||||
95 | fp = open(f) |
|
95 | fp = open(f) | |
96 | except IOError: |
|
96 | except IOError: | |
97 | continue |
|
97 | continue | |
98 | cdata = self.cdata |
|
98 | ||
99 | trusted = assumetrusted or self._is_trusted(fp, f) |
|
99 | trusted = assumetrusted or self._is_trusted(fp, f) | |
100 | if not trusted: |
|
|||
101 | if self.ucdata is None: |
|
|||
102 | self.ucdata = dupconfig(self.cdata) |
|
|||
103 | cdata = self.ucdata |
|
|||
104 | elif self.ucdata is not None: |
|
|||
105 | # use a separate configparser, so that we don't accidentally |
|
|||
106 | # override ucdata settings later on. |
|
|||
107 | cdata = util.configparser() |
|
|||
108 |
|
100 | |||
109 | try: |
|
101 | try: | |
110 | cdata.readfp(fp, f) |
|
102 | cdata.readfp(fp, f) | |
@@ -115,12 +107,11 b' class ui(object):' | |||||
115 | self.warn(_("Ignored: %s\n") % msg) |
|
107 | self.warn(_("Ignored: %s\n") % msg) | |
116 |
|
108 | |||
117 | if trusted: |
|
109 | if trusted: | |
118 |
|
|
110 | updateconfig(cdata, self.cdata) | |
119 |
|
|
111 | updateconfig(self.overlay, self.cdata) | |
120 | if self.ucdata is not None: |
|
112 | updateconfig(cdata, self.ucdata) | |
121 |
|
|
113 | updateconfig(self.overlay, self.ucdata) | |
122 | # override data from config files with data set with ui.setconfig |
|
114 | ||
123 | updateconfig(self.overlay, self.cdata) |
|
|||
124 | if root is None: |
|
115 | if root is None: | |
125 | root = os.path.expanduser('~') |
|
116 | root = os.path.expanduser('~') | |
126 | self.fixconfig(root=root) |
|
117 | self.fixconfig(root=root) | |
@@ -152,8 +143,7 b' class ui(object):' | |||||
152 | cdata.add_section(section) |
|
143 | cdata.add_section(section) | |
153 |
|
144 | |||
154 | updateconfig(cdata, self.cdata, sections) |
|
145 | updateconfig(cdata, self.cdata, sections) | |
155 | if self.ucdata: |
|
146 | updateconfig(cdata, self.ucdata, sections) | |
156 | updateconfig(cdata, self.ucdata, sections) |
|
|||
157 |
|
147 | |||
158 | def fixconfig(self, section=None, name=None, value=None, root=None): |
|
148 | def fixconfig(self, section=None, name=None, value=None, root=None): | |
159 | # translate paths relative to root (or home) into absolute paths |
|
149 | # translate paths relative to root (or home) into absolute paths | |
@@ -162,7 +152,6 b' class ui(object):' | |||||
162 | root = os.getcwd() |
|
152 | root = os.getcwd() | |
163 | items = section and [(name, value)] or [] |
|
153 | items = section and [(name, value)] or [] | |
164 | for cdata in self.cdata, self.ucdata, self.overlay: |
|
154 | for cdata in self.cdata, self.ucdata, self.overlay: | |
165 | if not cdata: continue |
|
|||
166 | if not items and cdata.has_section('paths'): |
|
155 | if not items and cdata.has_section('paths'): | |
167 | pathsitems = cdata.items('paths') |
|
156 | pathsitems = cdata.items('paths') | |
168 | else: |
|
157 | else: | |
@@ -195,14 +184,13 b' class ui(object):' | |||||
195 |
|
184 | |||
196 | def setconfig(self, section, name, value): |
|
185 | def setconfig(self, section, name, value): | |
197 | for cdata in (self.overlay, self.cdata, self.ucdata): |
|
186 | for cdata in (self.overlay, self.cdata, self.ucdata): | |
198 | if not cdata: continue |
|
|||
199 | if not cdata.has_section(section): |
|
187 | if not cdata.has_section(section): | |
200 | cdata.add_section(section) |
|
188 | cdata.add_section(section) | |
201 | cdata.set(section, name, value) |
|
189 | cdata.set(section, name, value) | |
202 | self.fixconfig(section, name, value) |
|
190 | self.fixconfig(section, name, value) | |
203 |
|
191 | |||
204 | def _get_cdata(self, untrusted): |
|
192 | def _get_cdata(self, untrusted): | |
205 |
if untrusted |
|
193 | if untrusted: | |
206 | return self.ucdata |
|
194 | return self.ucdata | |
207 | return self.cdata |
|
195 | return self.cdata | |
208 |
|
196 | |||
@@ -223,7 +211,7 b' class ui(object):' | |||||
223 | def _configcommon(self, section, name, default, funcname, untrusted): |
|
211 | def _configcommon(self, section, name, default, funcname, untrusted): | |
224 | value = self._config(section, name, default, funcname, |
|
212 | value = self._config(section, name, default, funcname, | |
225 | untrusted, abort=True) |
|
213 | untrusted, abort=True) | |
226 |
if self.debugflag and not untrusted |
|
214 | if self.debugflag and not untrusted: | |
227 | uvalue = self._config(section, name, None, funcname, |
|
215 | uvalue = self._config(section, name, None, funcname, | |
228 | untrusted=True, abort=False) |
|
216 | untrusted=True, abort=False) | |
229 | if uvalue is not None and uvalue != value: |
|
217 | if uvalue is not None and uvalue != value: | |
@@ -268,7 +256,7 b' class ui(object):' | |||||
268 |
|
256 | |||
269 | def configitems(self, section, untrusted=False): |
|
257 | def configitems(self, section, untrusted=False): | |
270 | items = self._configitems(section, untrusted=untrusted, abort=True) |
|
258 | items = self._configitems(section, untrusted=untrusted, abort=True) | |
271 |
if self.debugflag and not untrusted |
|
259 | if self.debugflag and not untrusted: | |
272 | uitems = self._configitems(section, untrusted=True, abort=False) |
|
260 | uitems = self._configitems(section, untrusted=True, abort=False) | |
273 | for k in util.sort(uitems): |
|
261 | for k in util.sort(uitems): | |
274 | if uitems[k] != items.get(k): |
|
262 | if uitems[k] != items.get(k): |
General Comments 0
You need to be logged in to leave comments.
Login now