Please find attached a patch to incorporate the persistent
enable/disable of repositories by editing the .repo files.
Repositories mentioned in yum.conf are still not supported.
This is done using the following two methods:
YumRepository.enablePersistent(self)
YumRepository.disablePersistent(self)
This is just a proof of concept and your comments are awaited.
Happy hacking,
Debarshi
--
GPG key ID: 63D4A5A7
Key server: pgp.mit.edu
diff -urNp yum.orig/__init__.py yum/__init__.py
--- yum.orig/__init__.py 2007-07-05 08:21:54.000000000 +0530
+++ yum/__init__.py 2007-07-05 08:19:28.000000000 +0530
@@ -199,7 +199,6 @@ class YumBase(depsolve.Depsolve):
# Read .repo files from directories specified by the reposdir option
# (typically /etc/yum/repos.d)
- parser = ConfigParser()
for reposdir in self.conf.reposdir:
if os.path.exists(self.conf.installroot+'/'+reposdir):
reposdir = self.conf.installroot + '/' + reposdir
@@ -207,28 +206,25 @@ class YumBase(depsolve.Depsolve):
if os.path.isdir(reposdir):
for repofn in glob.glob('%s/*.repo' % reposdir):
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 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:
- reposlist.append(thisrepo)
+ for section in parser.sections():
+ try:
+ thisrepo = self.readRepoConfig(parser, section)
+ except (Errors.RepoError, Errors.ConfigError), e:
+ self.logger.warning(e)
+ else:
+ thisrepo.repofile = repofn
- # 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
+ 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.
diff -urNp yum.orig/yumRepo.py yum/yumRepo.py
--- yum.orig/yumRepo.py 2007-07-05 08:24:28.000000000 +0530
+++ yum/yumRepo.py 2007-07-05 08:17:45.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
@@ -319,9 +320,32 @@ 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
on then raise a repo error"""
_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel