[yum-git] 2 commits - cli.py yum/__init__.py
James Antill
james at linux.duke.edu
Mon Jan 28 19:31:14 UTC 2008
cli.py | 20 +++++++++++++
yum/__init__.py | 85 +++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 80 insertions(+), 25 deletions(-)
New commits:
commit 598c1fad3a60dae0e23a524e9159354fd0bca93e
Author: James Antill <james at and.org>
Date: Mon Jan 28 14:24:05 2008 -0500
Add --tmprepo option, to download .repo files and use them.
diff --git a/cli.py b/cli.py
index 79d9515..4500acd 100644
--- a/cli.py
+++ b/cli.py
@@ -44,6 +44,9 @@ from yum.rpmtrans import RPMTransaction
import signal
import yumcommands
+import urlgrabber.grabber
+import tempfile
+
def sigquit(signum, frame):
""" SIGQUIT handler for the yum cli. """
print >> sys.stderr, "Quit signal sent - exiting immediately"
@@ -1032,6 +1035,19 @@ class YumOptionParser(OptionParser):
self.base.usage()
sys.exit(1)
+ # Don't use self._splitArg()? ... or require URLs without commas?
+ for trepo in self._splitArg(opts.tmp_repos):
+ tfo = tempfile.NamedTemporaryFile()
+ fname = tfo.name
+ grab = urlgrabber.grabber.URLGrabber()
+ try:
+ grab.urlgrab(trepo, fname)
+ except urlgrabber.grabber.URLGrabError, e:
+ self.logger.warn("Failed to retrieve " + trepo)
+ continue
+
+ self.base.getReposFromConfigFile(fname, gpgcheck=True)
+
# setup the progress bars/callbacks
self.base.setupProgressCallbacks()
@@ -1138,6 +1154,10 @@ class YumOptionParser(OptionParser):
metavar='[plugin]')
self.add_option("--skip-broken", action="store_true", dest="skipbroken",
help=_("skip packages with depsolving problems"))
+ self.add_option("--tmprepo", action='append',
+ type='string', dest='tmp_repos', default=[],
+ help=_("enable one or more repositories from URLs"),
+ metavar='[url]')
commit b9b82a90973c1fb4e560d0fd60936e2821ef460a
Author: James Antill <james at and.org>
Date: Mon Jan 28 14:23:30 2008 -0500
Move .repo file loading into it's own function.
Add gpgcheck argument, so it fails if .repo doesn't have gpgcheck=true
Add repo/section name handling.
diff --git a/yum/__init__.py b/yum/__init__.py
index 0ec2d19..7e78b15 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -63,6 +63,8 @@ from constants import *
from yum.rpmtrans import RPMTransaction,SimpleCliCallBack
from yum.i18n import _
+import string
+
__version__ = '3.2.10'
class YumBase(depsolve.Depsolve):
@@ -191,6 +193,63 @@ class YumBase(depsolve.Depsolve):
def doFileLogSetup(self, uid, logfile):
logginglevels.setFileLog(uid, logfile)
+ def getReposFromConfigFile(self, repofn, gpgcheck=False, repo_age=None):
+ """read in repositories from a config .repo file"""
+
+ if repo_age is None:
+ repo_age = os.stat(repofn)[8]
+
+ 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():
+
+ # Check the repo.id against the valid chars
+ bad = None
+ for byte in section:
+ if byte in string.ascii_letters:
+ continue
+ if byte in string.digits:
+ continue
+ if byte in "-_.":
+ continue
+
+ bad = byte
+ break
+
+ if bad:
+ self.logger.warning("Bad name for repo: %s, byte = %s %d" %
+ (section, bad, section.find(byte)))
+ continue
+
+ try:
+ thisrepo = self.readRepoConfig(parser, section)
+ except (Errors.RepoError, Errors.ConfigError), e:
+ self.logger.warning(e)
+ continue
+ else:
+ thisrepo.repo_config_age = repo_age
+ thisrepo.repofile = repofn
+
+ if gpgcheck and not thisrepo.gpgcheck:
+ # Don't allow them to set gpgcheck=False
+ self.logger.warning("Repo %s tries to set gpgcheck=false" %
+ (thisrepo))
+ 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 getReposFromConfig(self):
"""read in repositories from config main and .repo files"""
@@ -228,31 +287,7 @@ class YumBase(depsolve.Depsolve):
thisrepo_age = os.stat(repofn)[8]
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
-
- # 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)
+ self.getReposFromConfigFile(repofn, repo_age=thisrepo_age)
def readRepoConfig(self, parser, section):
'''Parse an INI file section for a repository.
More information about the Yum-cvs-commits
mailing list