[PATCH 4/9] Add _writeRawConfigFile() so we can change yum.conf values.

James Antill james at and.org
Wed Feb 12 23:27:10 UTC 2014


---
 yum/config.py |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/yum/config.py b/yum/config.py
index 09a4dcc..f213fc1 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -1301,6 +1301,48 @@ def writeRawRepoFile(repo,only=None):
     fp.write(str(ini))
     fp.close()
 
+# Copied from yum-config-manager ... how we alter yu.conf ... used in "yum fs"
+def _writeRawConfigFile(filename, section_id, yumvar,
+                        cfgoptions, items, optionobj,
+                        only=None):
+    """
+    From writeRawRepoFile, but so we can alter [main] too.
+    """
+    ini = INIConfig(open(filename))
+
+    osection_id = section_id
+    # b/c repoids can have $values in them we need to map both ways to figure
+    # out which one is which
+    if section_id not in ini._sections:
+        for sect in ini._sections.keys():
+            if varReplace(sect, yumvar) == section_id:
+                section_id = sect
+
+    # Updated the ConfigParser with the changed values
+    cfgOptions = cfgoptions(osection_id)
+    for name,value in items():
+        if value is None: # Proxy
+            continue
+
+        if only is not None and name not in only:
+            continue
+
+        option = optionobj(name)
+        ovalue = option.tostring(value)
+        #  If the value is the same, but just interpreted ... when we don't want
+        # to keep the interpreted values.
+        if (name in ini[section_id] and
+            ovalue == varReplace(ini[section_id][name], yumvar)):
+            ovalue = ini[section_id][name]
+
+        if name not in cfgOptions and option.default == value:
+            continue
+
+        ini[section_id][name] = ovalue
+    fp =file(filename, "w")
+    fp.write(str(ini))
+    fp.close()
+
 #def main():
 #    mainconf = readMainConfig(readStartupConfig('/etc/yum/yum.conf', '/'))
 #    print mainconf.cachedir
-- 
1.7.7.6



More information about the Yum-devel mailing list