|
Brian Stinson |
a74cb7 |
From 8bcd196fd95e70fd1f0be16d2c274e39a1cabe2e Mon Sep 17 00:00:00 2001
|
|
Brian Stinson |
a74cb7 |
From: Jaroslav Rohel <jrohel@redhat.com>
|
|
Brian Stinson |
a74cb7 |
Date: Thu, 21 Nov 2019 11:45:03 +0100
|
|
Brian Stinson |
a74cb7 |
Subject: [PATCH] Do a substitution of variables in repo_id (RhBug:1748841)
|
|
Brian Stinson |
a74cb7 |
|
|
Brian Stinson |
a74cb7 |
Example of repo file:
|
|
Brian Stinson |
a74cb7 |
[test-$basearch-$releasever]
|
|
Brian Stinson |
a74cb7 |
Name=Test-$basearch-$releasever
|
|
Brian Stinson |
a74cb7 |
baseurl=file:///mnt/
|
|
Brian Stinson |
a74cb7 |
gpgcheck=0
|
|
Brian Stinson |
a74cb7 |
enabled=1
|
|
Brian Stinson |
a74cb7 |
|
|
Brian Stinson |
a74cb7 |
https://bugzilla.redhat.com/show_bug.cgi?id=1748841
|
|
Brian Stinson |
a74cb7 |
---
|
|
Brian Stinson |
a74cb7 |
dnf/conf/read.py | 40 +++++++++++++++++++++++++++-------------
|
|
Brian Stinson |
a74cb7 |
1 file changed, 27 insertions(+), 13 deletions(-)
|
|
Brian Stinson |
a74cb7 |
|
|
Brian Stinson |
a74cb7 |
diff --git a/dnf/conf/read.py b/dnf/conf/read.py
|
|
Brian Stinson |
a74cb7 |
index a526a71..1efac22 100644
|
|
Brian Stinson |
a74cb7 |
--- a/dnf/conf/read.py
|
|
Brian Stinson |
a74cb7 |
+++ b/dnf/conf/read.py
|
|
Brian Stinson |
a74cb7 |
@@ -43,7 +43,7 @@ class RepoReader(object):
|
|
Brian Stinson |
a74cb7 |
|
|
Brian Stinson |
a74cb7 |
# read .repo files from directories specified by conf.reposdir
|
|
Brian Stinson |
a74cb7 |
for repofn in (repofn for reposdir in self.conf.reposdir
|
|
Brian Stinson |
a74cb7 |
- for repofn in sorted(glob.glob('%s/*.repo' % reposdir))):
|
|
Brian Stinson |
a74cb7 |
+ for repofn in sorted(glob.glob('{}/*.repo'.format(reposdir)))):
|
|
Brian Stinson |
a74cb7 |
try:
|
|
Brian Stinson |
a74cb7 |
for r in self._get_repos(repofn):
|
|
Brian Stinson |
a74cb7 |
yield r
|
|
Brian Stinson |
a74cb7 |
@@ -54,17 +54,38 @@ class RepoReader(object):
|
|
Brian Stinson |
a74cb7 |
def _build_repo(self, parser, id_, repofn):
|
|
Brian Stinson |
a74cb7 |
"""Build a repository using the parsed data."""
|
|
Brian Stinson |
a74cb7 |
|
|
Brian Stinson |
a74cb7 |
- repo = dnf.repo.Repo(id_, self.conf)
|
|
Brian Stinson |
a74cb7 |
+ substituted_id = libdnf.conf.ConfigParser.substitute(id_, self.conf.substitutions)
|
|
Brian Stinson |
a74cb7 |
+
|
|
Brian Stinson |
a74cb7 |
+ # Check the repo.id against the valid chars
|
|
Brian Stinson |
a74cb7 |
+ invalid = dnf.repo.repo_id_invalid(substituted_id)
|
|
Brian Stinson |
a74cb7 |
+ if invalid is not None:
|
|
Brian Stinson |
a74cb7 |
+ if substituted_id != id_:
|
|
Brian Stinson |
a74cb7 |
+ msg = _("Bad id for repo: {} ({}), byte = {} {}").format(substituted_id, id_,
|
|
Brian Stinson |
a74cb7 |
+ substituted_id[invalid],
|
|
Brian Stinson |
a74cb7 |
+ invalid)
|
|
Brian Stinson |
a74cb7 |
+ else:
|
|
Brian Stinson |
a74cb7 |
+ msg = _("Bad id for repo: {}, byte = {} {}").format(id_, id_[invalid], invalid)
|
|
Brian Stinson |
a74cb7 |
+ raise dnf.exceptions.ConfigError(msg)
|
|
Brian Stinson |
a74cb7 |
+
|
|
Brian Stinson |
a74cb7 |
+ repo = dnf.repo.Repo(substituted_id, self.conf)
|
|
Brian Stinson |
a74cb7 |
try:
|
|
Brian Stinson |
a74cb7 |
repo._populate(parser, id_, repofn, dnf.conf.PRIO_REPOCONFIG)
|
|
Brian Stinson |
a74cb7 |
except ValueError as e:
|
|
Brian Stinson |
a74cb7 |
- msg = _("Repository '%s': Error parsing config: %s") % (id_, e)
|
|
Brian Stinson |
a74cb7 |
+ if substituted_id != id_:
|
|
Brian Stinson |
a74cb7 |
+ msg = _("Repository '{}' ({}): Error parsing config: {}").format(substituted_id,
|
|
Brian Stinson |
a74cb7 |
+ id_, e)
|
|
Brian Stinson |
a74cb7 |
+ else:
|
|
Brian Stinson |
a74cb7 |
+ msg = _("Repository '{}': Error parsing config: {}").format(id_, e)
|
|
Brian Stinson |
a74cb7 |
raise dnf.exceptions.ConfigError(msg)
|
|
Brian Stinson |
a74cb7 |
|
|
Brian Stinson |
a74cb7 |
# Ensure that the repo name is set
|
|
Brian Stinson |
a74cb7 |
if repo._get_priority('name') == dnf.conf.PRIO_DEFAULT:
|
|
Brian Stinson |
a74cb7 |
- msg = _("Repository '%s' is missing name in configuration, using id.")
|
|
Brian Stinson |
a74cb7 |
- logger.warning(msg, id_)
|
|
Brian Stinson |
a74cb7 |
+ if substituted_id != id_:
|
|
Brian Stinson |
a74cb7 |
+ msg = _("Repository '{}' ({}) is missing name in configuration, using id.").format(
|
|
Brian Stinson |
a74cb7 |
+ substituted_id, id_)
|
|
Brian Stinson |
a74cb7 |
+ else:
|
|
Brian Stinson |
a74cb7 |
+ msg = _("Repository '{}' is missing name in configuration, using id.").format(id_)
|
|
Brian Stinson |
a74cb7 |
+ logger.warning(msg)
|
|
Brian Stinson |
a74cb7 |
repo.name = ucd(repo.name)
|
|
Brian Stinson |
a74cb7 |
repo._substitutions.update(self.conf.substitutions)
|
|
Brian Stinson |
a74cb7 |
repo.cfg = parser
|
|
Brian Stinson |
a74cb7 |
@@ -80,23 +101,16 @@ class RepoReader(object):
|
|
Brian Stinson |
a74cb7 |
try:
|
|
Brian Stinson |
a74cb7 |
parser.read(repofn)
|
|
Brian Stinson |
a74cb7 |
except RuntimeError as e:
|
|
Brian Stinson |
a74cb7 |
- raise dnf.exceptions.ConfigError(_('Parsing file "%s" failed: %s') % (repofn, e))
|
|
Brian Stinson |
a74cb7 |
+ raise dnf.exceptions.ConfigError(_('Parsing file "{}" failed: {}').format(repofn, e))
|
|
Brian Stinson |
a74cb7 |
except IOError as e:
|
|
Brian Stinson |
a74cb7 |
logger.warning(e)
|
|
Brian Stinson |
a74cb7 |
|
|
Brian Stinson |
a74cb7 |
# Check sections in the .repo file that was just slurped up
|
|
Brian Stinson |
a74cb7 |
for section in parser.getData():
|
|
Brian Stinson |
a74cb7 |
|
|
Brian Stinson |
a74cb7 |
if section == 'main':
|
|
Brian Stinson |
a74cb7 |
continue
|
|
Brian Stinson |
a74cb7 |
|
|
Brian Stinson |
a74cb7 |
- # Check the repo.id against the valid chars
|
|
Brian Stinson |
a74cb7 |
- invalid = dnf.repo.repo_id_invalid(section)
|
|
Brian Stinson |
a74cb7 |
- if invalid is not None:
|
|
Brian Stinson |
a74cb7 |
- logger.warning(_("Bad id for repo: %s, byte = %s %d"), section,
|
|
Brian Stinson |
a74cb7 |
- section[invalid], invalid)
|
|
Brian Stinson |
a74cb7 |
- continue
|
|
Brian Stinson |
a74cb7 |
-
|
|
Brian Stinson |
a74cb7 |
try:
|
|
Brian Stinson |
a74cb7 |
thisrepo = self._build_repo(parser, ucd(section), repofn)
|
|
Brian Stinson |
a74cb7 |
except (dnf.exceptions.RepoError, dnf.exceptions.ConfigError) as e:
|
|
Brian Stinson |
a74cb7 |
--
|
|
Brian Stinson |
a74cb7 |
libgit2 0.28.2
|
|
Brian Stinson |
a74cb7 |
|