Bug 1427132

Summary: create an API for initializing repos
Product: [Fedora] Fedora Reporter: Daniel Mach <dmach>
Component: dnfAssignee: Jaroslav Mracek <jmracek>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 26CC: dmach, jmracek, packaging-team-maint, rpm-software-management, vmukhame
Target Milestone: ---Keywords: Reopened, Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: dnf-1.1.10-6.fc25 dnf-2.2.0-1.fc26 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-04-01 17:21:36 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Daniel Mach 2017-02-27 12:28:26 UTC
Currently the Repo() objects are created in the CLI code:
https://github.com/rpm-software-management/dnf/blob/master/dnf/cli/cli.py#L672

It would be nice if dnf had a supported (API) function/method to add repos,
ideally available directly through the dnf.Base class.
Every project that uses DNF and configures repos in the code rather than using /etc/yum.repos.d/* ends up with it's own code for this use case.

An example:
https://pagure.io/fork/lsedlar/pungi/blob/gather-libhif/f/pungi/dnf_wrapper.py#_61

Comment 1 Igor Gnatenko 2017-02-27 12:46:53 UTC
You mean something like this:
diff --git a/dnf/cli/cli.py b/dnf/cli/cli.py
index d561274a..9a091843 100644
--- a/dnf/cli/cli.py
+++ b/dnf/cli/cli.py
@@ -673,13 +673,7 @@ class Cli(object):
         self.base.read_all_repos(opts)
         if opts.repofrompath:
             for label, path in opts.repofrompath.items():
-                if '://' not in path:
-                    path = 'file://{}'.format(os.path.abspath(path))
-                repofp = dnf.repo.Repo(label, self.base.conf)
-                try:
-                    repofp.baseurl = path
-                except ValueError as e:
-                    raise dnf.exceptions.RepoError(e)
+                repofp = dnf.repo.from_path(label, path, self.base.conf)
                 self.base.repos.add(repofp)
                 logger.info(_("Added %s repo from %s"), label, path)
 
diff --git a/dnf/repo.py b/dnf/repo.py
index 338db6b5..10366d02 100644
--- a/dnf/repo.py
+++ b/dnf/repo.py
@@ -483,6 +483,18 @@ class Repo(dnf.conf.RepoConf):
         # :api
         return self._repofile
 
+    @classmethod
+    def from_path(cls, name, path, *args, **kwargs):
+        # :api
+        if '://' not in path:
+            path = 'file://{}'.format(os.path.abspath(path))
+        repofp = cls(name, *args, **kwargs)
+        try:
+            repofp.baseurl = path
+        except ValueError as e:
+            raise dnf.exceptions.RepoError(e)
+        return repofp
+
     @repofile.setter
     def repofile(self, value):
         self._repofile = value


?

Comment 2 Fedora End Of Life 2017-02-28 12:27:20 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 26 development cycle.
Changing version to '26'.

Comment 3 Jaroslav Mracek 2017-03-02 12:12:24 UTC
I will take care of that.

Comment 4 Igor Gnatenko 2017-03-02 12:14:21 UTC
(In reply to Jaroslav Mracek from comment #3)
> I will take care of that.

There's already patch waiting for reporter.

Comment 5 Jaroslav Mracek 2017-03-02 13:36:26 UTC
I have created patch that should support requested feature: https://github.com/rpm-software-management/dnf/pull/752

Comment 6 Daniel Mach 2017-03-02 13:44:55 UTC
The patch in pull request 752 looks good to me.

Comment 7 Fedora Update System 2017-03-15 08:56:35 UTC
dnf-1.1.10-6.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-b7cfb5cf10

Comment 8 Fedora Update System 2017-03-15 19:58:37 UTC
dnf-1.1.10-6.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-b7cfb5cf10

Comment 9 Fedora Update System 2017-03-16 22:22:02 UTC
dnf-1.1.10-6.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.

Comment 10 Fedora Update System 2017-03-21 12:07:41 UTC
dnf-2.1.1-1.fc26 libdnf-0.8.0-1.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-65586fa42b

Comment 11 Fedora Update System 2017-03-21 14:27:08 UTC
dnf-2.1.1-1.1.fc26, libdnf-0.8.0-1.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-65586fa42b

Comment 12 Fedora Update System 2017-03-27 19:20:41 UTC
dnf-2.2.0-1.fc26, libdnf-0.8.0-1.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-65586fa42b

Comment 13 Fedora Update System 2017-04-01 17:21:36 UTC
dnf-2.2.0-1.fc26, libdnf-0.8.0-1.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.