Add new API add_new_repo in RepoDict (RhBug:1427132)

This commit is contained in:
Jaroslav Mracek 2017-03-15 09:41:14 +01:00
parent 8d0dadc6ef
commit 37646c3254
2 changed files with 107 additions and 1 deletions

View File

@ -0,0 +1,102 @@
From efc5f9c5ae36935d05c51419d53e09ededcf0efe Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Mon, 13 Mar 2017 08:35:30 +0100
Subject: [PATCH] Add new API add_new_repo() in RepoDict() (RhBug:1427132)
It allows to initialize new repo object and add it into RepoDict.
https://bugzilla.redhat.com/show_bug.cgi?id=1427132
---
dnf/repodict.py | 25 +++++++++++++++++++++++++
dnf/util.py | 3 +++
doc/api_repos.rst | 7 +++++++
3 files changed, 35 insertions(+)
diff --git a/dnf/repodict.py b/dnf/repodict.py
index d1c1904..33739d2 100644
--- a/dnf/repodict.py
+++ b/dnf/repodict.py
@@ -20,9 +20,13 @@
from __future__ import unicode_literals
from dnf.exceptions import ConfigError
+from dnf.i18n import _
+
import dnf.util
import fnmatch
+import os
+logger = dnf.util.logger
class RepoDict(dict):
# :api
@@ -44,6 +48,27 @@ class RepoDict(dict):
def any_enabled(self):
return not dnf.util.empty(self.iter_enabled())
+ def add_new_repo(self, repoid, conf, baseurl=(), **kwargs):
+ # :api
+ """
+ Creates new repo object and add it into RepoDict.
+ :param repoid: Repo ID - string
+ :param conf: dnf Base().conf object
+ :param baseurl: List of strings
+ :param kwargs: keys and values that will be used to setattr on dnf.repo.Repo() object
+ :return: dnf.repo.Repo() object
+ """
+ repo = dnf.repo.Repo(repoid, conf.cachedir)
+ for path in baseurl:
+ if '://' not in path:
+ path = 'file://{}'.format(os.path.abspath(path))
+ repo.baseurl.append(path)
+ for (key, value) in kwargs.items():
+ setattr(repo, key, value)
+ self.add(repo)
+ logger.info(_("Added %s repo from %s"), repoid, ', '.join(baseurl))
+ return repo
+
def enabled(self):
return [r for r in self.values() if r.enabled]
diff --git a/dnf/util.py b/dnf/util.py
index b35aba5..c196958 100644
--- a/dnf/util.py
+++ b/dnf/util.py
@@ -29,6 +29,7 @@ import dnf.const
import dnf.pycomp
import itertools
import librepo
+import logging
import os
import pwd
import shutil
@@ -37,6 +38,8 @@ import sys
import tempfile
import time
+logger = logging.getLogger('dnf')
+
"""DNF Utilities.
Generally these are not a part of the public DNF API.
diff --git a/doc/api_repos.rst b/doc/api_repos.rst
index 96e10ac..295c330 100644
--- a/doc/api_repos.rst
+++ b/doc/api_repos.rst
@@ -46,6 +46,13 @@ Repository Configuration
Return an iterator over all enabled repos from the dict.
+ .. method:: add_new_repo(repoid, conf, baseurl=(), **kwargs)
+
+ Initialize new :class:`.Repo` object and add it to the repodict. It requires ``repoid``
+ (string), and :class:`dnf.conf.Conf` object. Optionally it can be speciffied baseurl (list), and
+ additionally key/value pairs from `kwargs` to set additional attribute of the :class:`.Repo`
+ object. It returns the :class:`.Repo` object.
+
.. module:: dnf.repo
.. function:: repo_id_invalid(repo_id)
--
2.9.3

View File

@ -25,7 +25,7 @@
Name: dnf
Version: 1.1.10
Release: 5%{?dist}
Release: 6%{?dist}
Summary: Package manager forked from Yum, using libsolv as a dependency resolver
# For a breakdown of the licensing, see PACKAGE-LICENSING
License: GPLv2+ and GPLv2 and GPL
@ -40,6 +40,7 @@ Patch0002: 0001-Add-RISC-V-architectures.patch
# https://github.com/rpm-software-management/dnf/commit/fba7ae2890ddc725fdad3fd092278e36dd029a83
Patch0003: 0001-SpacewalkRepo-object-has-no-attribute-repofile-RhBug.patch
Patch0004: 0001-subject-prefer-obsoletes-RhBug-1096506-RhBug-1332830.patch
Patch0005: 0001-Add-new-API-add_new_repo-in-RepoDict-RhBug-1427132.patch
BuildArch: noarch
BuildRequires: cmake
BuildRequires: gettext
@ -343,6 +344,9 @@ exit 0
%endif
%changelog
* Wed Mar 15 2017 Jaroslav Mracek <jmracek@redhat.com> - 1.1.10-6
- Add new API add_new_repo in RepoDict (RhBug:1427132)
* Tue Jan 17 2017 Igor Gnatenko <ignatenko@redhat.com> - 1.1.10-5
- Prefer obsoletes (RHBZ #1096506)