Bug 1427132 - create an API for initializing repos
create an API for initializing repos
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: dnf (Show other bugs)
26
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Jaroslav Mracek
Fedora Extras Quality Assurance
: Reopened, Triaged
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-02-27 07:28 EST by Daniel Mach
Modified: 2017-04-01 13:21 EDT (History)
5 users (show)

See Also:
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 13:21:36 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Daniel Mach 2017-02-27 07:28:26 EST
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 07:46:53 EST
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 07:27:20 EST
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 07:12:24 EST
I will take care of that.
Comment 4 Igor Gnatenko 2017-03-02 07:14:21 EST
(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 08:36:26 EST
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 08:44:55 EST
The patch in pull request 752 looks good to me.
Comment 7 Fedora Update System 2017-03-15 04:56:35 EDT
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 15:58:37 EDT
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 18:22:02 EDT
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 08:07:41 EDT
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 10:27:08 EDT
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 15:20:41 EDT
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 13:21:36 EDT
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.

Note You need to log in before you can comment on or make changes to this bug.