| Server IP : 112.74.42.100 / Your IP : 216.73.216.142 Web Server : nginx/1.20.2 System : Linux iZwz96lx4pjqiy84w4hni7Z 5.10.134-17.3.al8.x86_64 #1 SMP Thu Oct 31 14:29:57 CST 2024 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /lib/python3.6/site-packages/dnf-plugins/ |
Upload File : |
#!/usr/bin/env python3
#
# Version:2.0
#
# To install this plugin, just drop it into
# /usr/lib/python3.6/site-packages/dnf-plugins, and
# make sure you have 'plugins=1' in your /etc/yum.conf.
# You also need to create the following configuration
# file, if not installed through an RPM:
#
# /etc/yum/pluginconf.d/releasever_adapter.conf:
# [main]
# enabled=1
# [releasevermapping]
# 2.1903 = 7
# 3 = 8
# [reposlist]
# include=docker-ce.repo, epel.repo, hashicorp.repo
#
import os
import dnf
import logging
import dnf.conf
import libdnf.conf
from dnf.i18n import _, ucd
include = None
release_dict = None
done_repos = set()
logger = logging.getLogger('dnf')
repo_dir = "/etc/yum.repos.d"
class ReleaseverAdaptation(dnf.Plugin):
"""DNF Plugin to parse baseurl in repositories"""
name = 'releasever_adapter'
def __init__(self, base, cli):
super().__init__(base, cli)
self.base = base
self.dnf_base = dnf.Base()
def config(self):
conf = self.read_config(self.base.conf)
release_dict = dict(conf.items('releasevermapping'))
include = conf.get('reposlist', 'include')
repo_names = include.replace(' ', '').split(',')
reader = self.read_repos(repo_names, repo_dir)
repo_lists = self.base.repos
for repo in reader:
if repo.id in done_repos:
continue
type = "baseurl" if repo.baseurl else "metalink" if \
repo.metalink else "mirrorlist"
good_urls = self.parse_baseurl({"baseurl": repo.baseurl,
"metalink": [repo.metalink],
"mirrorlist": [repo.mirrorlist]}[type],
release_dict)
setattr(repo_lists[repo.id], type, good_urls if repo.baseurl else good_urls[0])
repo_lists[repo.id].failovermethod = 'priority'
done_repos.add(repo_lists[repo.id].id)
def parse_baseurl(self, urllists, releasever_dict):
releasever = self.get_releasever()
basearch = self.get_basearch()
good_urls = []
for url in urllists:
url = url.replace('$releasever', releasever_dict[releasever]).replace('$basearch', basearch)
good_urls.append(url)
return good_urls
def read_repos(self, repo_names, repo_dir, opts = None):
repos = []
reader = RepoReader(self.dnf_base.conf, opts, repo_names, repo_dir)
for repo in reader:
if not repo.enabled:
continue
try:
repos.append(repo)
except dnf.exceptions.ConfigError as e:
logger.warning(e)
return repos
def get_releasever(self):
return self.base.conf.substitutions['releasever']
def get_basearch(self):
return self.base.conf.substitutions['basearch']
class RepoReader(object):
def __init__(self, conf, opts, repo_names, repo_dir):
self.conf = conf
self.opts = opts
self.repo_dir = repo_dir
self.names = repo_names
def __iter__(self):
# get the repos from the main yum.conf file
for r in self._get_repos(self.conf.config_file_path):
yield r
# read .repo files from directories specified by repo_dir and repo_name
for repo_name in self.names:
repofn = os.path.join(self.repo_dir, repo_name)
try:
for r in self._get_repos(repofn):
yield r
except dnf.exceptions.ConfigError:
logger.warning(_("Warning: failed loading '%s', skipping."), repofn)
def _build_repo(self, parser, id_, repofn):
"""Build a repository using the parsed data."""
substituted_id = libdnf.conf.ConfigParser.substitute(id_, self.conf.substitutions)
# Check the repo.id against the valid chars
invalid = dnf.repo.repo_id_invalid(substituted_id)
if invalid is not None:
if substituted_id != id_:
msg = _("Bad id for repo: {} ({}), byte = {} {}").format(substituted_id, id_,
substituted_id[invalid],
invalid)
else:
msg = _("Bad id for repo: {}, byte = {} {}").format(id_, id_[invalid], invalid)
raise dnf.exceptions.ConfigError(msg)
repo = dnf.repo.Repo(substituted_id, self.conf)
try:
repo._populate(parser, id_, repofn, dnf.conf.PRIO_REPOCONFIG)
except ValueError as e:
if substituted_id != id_:
msg = _("Repository '{}' ({}): Error parsing config: {}").format(substituted_id,
id_, e)
else:
msg = _("Repository '{}': Error parsing config: {}").format(id_, e)
raise dnf.exceptions.ConfigError(msg)
# Ensure that the repo name is set
if repo._get_priority('name') == dnf.conf.PRIO_DEFAULT:
if substituted_id != id_:
msg = _("Repository '{}' ({}) is missing name in configuration, using id.").format(
substituted_id, id_)
else:
msg = _("Repository '{}' is missing name in configuration, using id.").format(id_)
logger.warning(msg)
repo.name = ucd(repo.name)
repo._substitutions.update(self.conf.substitutions)
repo.cfg = parser
return repo
def _get_repos(self, repofn):
"""Parse and yield all repositories from a config file."""
parser = libdnf.conf.ConfigParser()
try:
parser.read(repofn)
except RuntimeError as e:
raise dnf.exceptions.ConfigError(_('Parsing file "{}" failed: {}').format(repofn, e))
except IOError as e:
logger.warning(e)
# Check sections in the .repo file that was just slurped up
for section in parser.getData():
if section == 'main':
continue
try:
thisrepo = self._build_repo(parser, ucd(section), repofn)
except (dnf.exceptions.RepoError, dnf.exceptions.ConfigError) as e:
logger.warning(e)
continue
else:
thisrepo.repofile = repofn
thisrepo._configure_from_options(self.opts)
yield thisrepo