Please find attached a patch against yum-3.2.2-3 to incorporate the
persistent enable/disable of repositories by editing the .repo files.

This is done using the following two methods:
YumRepository.enablePersistent(self)
YumRepository.disablePersistent(self)

I have re-worked the patch to use iniparse, and repositories mentioned
in yum.conf are now supported.

Comments?

Happy hacking,
Debarshi
-- 
GPG key ID: 63D4A5A7
Key server: pgp.mit.edu
diff -urNp yum.orig/config.py yum/config.py
--- yum.orig/config.py	2007-08-21 13:33:47.000000000 +0530
+++ yum/config.py	2007-08-21 14:18:26.000000000 +0530
@@ -21,7 +21,12 @@ import rpm
 import copy
 import urlparse
 from parser import ConfigPreProcessor
-from ConfigParser import NoSectionError, NoOptionError, ConfigParser, ParsingError
+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
 import rpmUtils.transaction
 import rpmUtils.arch
 import Errors
Binary files yum.orig/config.pyc and yum/config.pyc differ
diff -urNp yum.orig/__init__.py yum/__init__.py
--- yum.orig/__init__.py	2007-08-21 13:33:47.000000000 +0530
+++ yum/__init__.py	2007-08-21 14:47:20.000000000 +0530
@@ -27,7 +27,10 @@ import glob
 import fnmatch
 import logging
 import logging.config
-from ConfigParser import ParsingError, ConfigParser
+try:
+    from iniparse.compat import ParsingError, ConfigParser
+except ImportError:
+    from ConfigParser import ParsingError, ConfigParser
 import Errors
 import rpmsack
 import rpmUtils.updates
@@ -186,7 +189,6 @@ class YumBase(depsolve.Depsolve):
 
         #FIXME this method could be a simpler
 
-        reposlist = []
         # Check yum.conf for repositories
         for section in self.conf.cfg.sections():
             # All sections except [main] are repositories
@@ -199,13 +201,17 @@ class YumBase(depsolve.Depsolve):
                 self.logger.warning(e)
             else:
                 thisrepo.repo_config_age = self.conf.config_file_age
-                reposlist.append(thisrepo)
+                thisrepo.repofile = self.conf.config_file_path
+
+            try:
+                self._repos.add(thisrepo)
+            except Errors.RepoError, e:
+                self.logger.warning(e)
 
         # Read .repo files from directories specified by the reposdir option
         # (typically /etc/yum/repos.d)
         repo_config_age = self.conf.config_file_age
         
-        parser = ConfigParser()
         for reposdir in self.conf.reposdir:
             if os.path.exists(self.conf.installroot+'/'+reposdir):
                 reposdir = self.conf.installroot + '/' + reposdir
@@ -213,33 +219,33 @@ class YumBase(depsolve.Depsolve):
             if os.path.isdir(reposdir):
                 for repofn in glob.glob('%s/*.repo' % reposdir):
                     thisrepo_age = os.stat(repofn)[8]
-                    if thisrepo_age > repo_config_age:
-                        repo_config_age = thisrepo_age
+                    if thisrepo_age < repo_config_age:
+                        thisrepo_age = repo_config_age
                         
                     confpp_obj = ConfigPreProcessor(repofn, vars=self.yumvar)
+                    parser = ConfigParser()
                     try:
                         parser.readfp(confpp_obj)
                     except ParsingError, e:
                         msg = str(e)
                         raise Errors.ConfigError, msg
+                    
+                    # Check sections in the .repo file that was just slurped up
+                    for section in parser.sections():
+                        try:
+                            thisrepo = self.readRepoConfig(parser, section)
+                        except (Errors.RepoError, Errors.ConfigError), e:
+                            self.logger.warning(e)
+                        else:
+                            thisrepo.repo_config_age = thisrepo_age
+                            thisrepo.repofile = repofn
 
-        # Check sections in the .repo files that were just slurped up
-        for section in parser.sections():
-            try:
-                thisrepo = self.readRepoConfig(parser, section)
-            except (Errors.RepoError, Errors.ConfigError), e:
-                self.logger.warning(e)
-            else:
-                thisrepo.repo_config_age = repo_config_age
-                reposlist.append(thisrepo)
-
-        # Got our list of repo objects, add them to the repos collection
-        for thisrepo in reposlist:
-            try:
-                self._repos.add(thisrepo)
-            except Errors.RepoError, e: 
-                self.logger.warning(e)
-                continue
+                        # Got our list of repo objects, add them to the repos
+                        # collection
+                        try:
+                            self._repos.add(thisrepo)
+                        except Errors.RepoError, e:
+                            self.logger.warning(e)
 
     def readRepoConfig(self, parser, section):
         '''Parse an INI file section for a repository.
Binary files yum.orig/__init__.pyc and yum/__init__.pyc differ
diff -urNp yum.orig/plugins.py yum/plugins.py
--- yum.orig/plugins.py	2007-08-21 13:33:47.000000000 +0530
+++ yum/plugins.py	2007-08-21 14:20:59.000000000 +0530
@@ -22,7 +22,10 @@ import gettext
 import logging
 import logginglevels
 from constants import *
-import ConfigParser
+try:
+    import iniparse.compat as ConfigParser
+except ImportError:
+    import ConfigParser
 import config 
 import Errors
 from parser import ConfigPreProcessor
Binary files yum.orig/plugins.pyc and yum/plugins.pyc differ
diff -urNp yum.orig/yumRepo.py yum/yumRepo.py
--- yum.orig/yumRepo.py	2007-08-21 13:33:47.000000000 +0530
+++ yum/yumRepo.py	2007-08-21 14:13:47.000000000 +0530
@@ -211,6 +211,7 @@ class YumRepository(Repository, config.R
         config.RepoConf.__init__(self)
         Repository.__init__(self, repoid)
 
+        self.repofile = None
         self._urls = []
         self.enablegroups = 0 
         self.groupsfilename = 'yumgroups.xml' # something some freaks might
@@ -320,8 +321,31 @@ class YumRepository(Repository, config.R
 
         return output
 
-    def enable(self):
-        Repository.enable(self)
+    def enablePersistent(self):
+        """Persistently enables this repository."""
+        self.enable()
+        self.cfg.set(self.id, 'enabled', '1')
+
+        try:
+            self.cfg.write(file(self.repofile, 'w'))
+        except IOError, e:
+            if e.errno == 13:
+                self.logger.warning(e)
+            else:
+                raise IOError, str(e)
+
+    def disablePersistent(self):
+        """Persistently disables this repository."""
+        self.disable()
+        self.cfg.set(self.id, 'enabled', '0')
+
+        try:
+            self.cfg.write(file(self.repofile, 'w'))
+        except IOError, e:
+            if e.errno == 13:
+                self.logger.warning(e)
+            else:
+                raise IOError, str(e)
 
     def check(self):
         """self-check the repo information  - if we don't have enough to move
Binary files yum.orig/yumRepo.pyc and yum/yumRepo.pyc differ
_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel

Reply via email to