Skip to content

Commit fed60db

Browse files
jrohelm-blaha
authored andcommitted
[config] Do not crash if BaseConfig._config==None
1 parent bd221aa commit fed60db

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

dnf/conf/config.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ def __setattr__(self, name, value):
247247
def __str__(self):
248248
out = []
249249
out.append('[%s]' % self._section)
250-
for optBind in self._config.optBinds():
251-
out.append('%s: %s' % (optBind.first, optBind.second.getValueString()))
250+
if self._config:
251+
for optBind in self._config.optBinds():
252+
out.append('%s: %s' % (optBind.first, optBind.second.getValueString()))
252253
return '\n'.join(out)
253254

254255
def _get_option(self, name):
@@ -278,6 +279,8 @@ def _populate(self, parser, section, filename, priority=PRIO_DEFAULT):
278279
value = None
279280

280281
try:
282+
if not self._config:
283+
raise RuntimeError()
281284
self._config.optBinds().at(name).newString(priority, value)
282285
except RuntimeError:
283286
opt = self._get_option(name)
@@ -308,12 +311,13 @@ def dump(self):
308311
"""
309312
output = ['[%s]' % self._section]
310313

311-
for optBind in self._config.optBinds():
312-
# if not opt._is_runtimeonly():
313-
try:
314-
output.append('%s = %s' % (optBind.first, optBind.second.getValueString()))
315-
except RuntimeError:
316-
pass
314+
if self._config:
315+
for optBind in self._config.optBinds():
316+
# if not opt._is_runtimeonly():
317+
try:
318+
output.append('%s = %s' % (optBind.first, optBind.second.getValueString()))
319+
except RuntimeError:
320+
pass
317321

318322
return '\n'.join(output) + '\n'
319323

@@ -336,12 +340,14 @@ def _write(self, fileobj, section=None, always=()):
336340
# Updated the ConfigParser with the changed values
337341
cfg_options = self._parser.options(section)
338342

339-
for optBind in self._config.optBinds():
340-
# if (not option._is_runtimeonly() and
341-
if (always is None or optBind.first in always or
342-
optBind.second.getPriority() >= PRIO_DEFAULT or
343-
optBind.first in cfg_options):
344-
self._parser.set(section, optBind.first, optBind.second.getValueString())
343+
if self._config:
344+
for optBind in self._config.optBinds():
345+
# if (not option._is_runtimeonly() and
346+
if (always is None or optBind.first in always or
347+
optBind.second.getPriority() >= PRIO_DEFAULT or
348+
optBind.first in cfg_options):
349+
self._parser.set(section, optBind.first, optBind.second.getValueString())
350+
345351
# write the updated ConfigParser to the fileobj.
346352
self._parser.write(fileobj)
347353

0 commit comments

Comments
 (0)