[yum-cvs] yum/config.py yum/__init__.py yum/plugins.py yum/yumRepo.py
Seth Vidal
skvidal at linux.duke.edu
Tue Aug 28 18:47:34 UTC 2007
yum/__init__.py | 54 ++++++++++++++++++++++++++++++------------------------
yum/config.py | 7 ++++++-
yum/plugins.py | 5 ++++-
yum/yumRepo.py | 28 ++++++++++++++++++++++++++--
4 files changed, 66 insertions(+), 28 deletions(-)
New commits:
commit 23f0fe4c49b65e5bd619d1b12f74eb7b5b14aa9f
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Tue Aug 28 14:44:55 2007 -0400
merge patch to use iniparser and allow better interaction to .repo files from Debarishi Ray
diff --git a/yum/__init__.py b/yum/__init__.py
index f4c3fe0..f8d1c8a 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -26,7 +26,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
@@ -187,7 +190,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
@@ -200,13 +202,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
@@ -214,33 +220,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 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
+
+ # 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
+
+ # 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.
diff --git a/yum/config.py b/yum/config.py
index 633006a..293cb9d 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -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
diff --git a/yum/plugins.py b/yum/plugins.py
index 3269525..2e674e6 100644
--- a/yum/plugins.py
+++ b/yum/plugins.py
@@ -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
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index c45fb85..a8f43db 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -212,6 +212,7 @@ class YumRepository(Repository, config.RepoConf):
config.RepoConf.__init__(self)
Repository.__init__(self, repoid)
+ self.repofile = None
self._urls = []
self.enablegroups = 0
self.groupsfilename = 'yumgroups.xml' # something some freaks might
@@ -325,8 +326,31 @@ class YumRepository(Repository, config.RepoConf):
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
More information about the Yum-cvs-commits
mailing list