[yum-git] Branch 'yum-3_2_X' - yum/config.py yum/yumRepo.py

Tim Lauridsen timlau at linux.duke.edu
Tue Jun 3 08:50:39 UTC 2008


 yum/config.py  |   28 ++++++++++++++++++++++------
 yum/yumRepo.py |    8 ++------
 2 files changed, 24 insertions(+), 12 deletions(-)

New commits:
commit 5119fa0e90324c2618348cb1aa31a7793e3caeba
Author: Tim Lauridsen <tla at rasmil.dk>
Date:   Tue Jun 3 10:40:07 2008 +0200

    make repo.enable/disablePersistant() dont messup the repo files by replacing  etc. (rhbz# 446098)

diff --git a/yum/config.py b/yum/config.py
index 218008b..2881709 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -25,12 +25,9 @@ import rpm
 import copy
 import urlparse
 from parser import ConfigPreProcessor
-try:
-    from iniparse.compat import NoSectionError, NoOptionError, ConfigParser
-    from iniparse.compat import ParsingError
-except ImportError:
-    from ConfigParser import NoSectionError, NoOptionError, ConfigParser
-    from ConfigParser import ParsingError
+from iniparse import INIConfig
+from iniparse.compat import NoSectionError, NoOptionError, ConfigParser
+from iniparse.compat import ParsingError
 import rpmUtils.transaction
 import rpmUtils.arch
 import Errors
@@ -815,6 +812,25 @@ def _getsysver(installroot, distroverpkg):
     del ts
     return releasever
 
+def writeRawRepoFile(repo,only=None):
+    """
+    Writes changes in a repo object back to a .repo file.
+    @param repo: Repo Object
+    @param only: List of attributes to work on (None = All)
+    It work by reading the repo file, changes the values there shall be changed and write it back to disk.
+    """
+    ini = INIConfig(open(repo.repofile))
+    # Updated the ConfigParser with the changed values    
+    cfgOptions = repo.cfg.options(repo.id)
+    for name,value in repo.iteritems():
+        option = repo.optionobj(name)
+        if option.default != value or name in cfgOptions :
+            if only == None or name in only:
+                ini[repo.id][name] = option.tostring(value)
+    fp =file(repo.repofile,"w")               
+    fp.write(str(ini))
+    fp.close()
+
 #def main():
 #    mainconf = readMainConfig('/etc/yum/yum.conf', '/')
 #    repoconf = readRepoConfig(mainconf.cfg, 'core', mainconf)
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 1527181..b3c07ba 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -343,10 +343,8 @@ class YumRepository(Repository, config.RepoConf):
     def enablePersistent(self):
         """Persistently enables this repository."""
         self.enable()
-        self.cfg.set(self.id, 'enabled', '1')
-
         try:
-            self.cfg.write(file(self.repofile, 'w'))
+            config.writeRawRepoFile(self,only=['enabled'])
         except IOError, e:
             if e.errno == 13:
                 self.logger.warning(e)
@@ -356,10 +354,8 @@ class YumRepository(Repository, config.RepoConf):
     def disablePersistent(self):
         """Persistently disables this repository."""
         self.disable()
-        self.cfg.set(self.id, 'enabled', '0')
-
         try:
-            self.cfg.write(file(self.repofile, 'w'))
+            config.writeRawRepoFile(self,only=['enabled'])
         except IOError, e:
             if e.errno == 13:
                 self.logger.warning(e)



More information about the Yum-cvs-commits mailing list