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
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 ?
This bug appears to have been reported against 'rawhide' during the Fedora 26 development cycle. Changing version to '26'.
I will take care of that.
(In reply to Jaroslav Mracek from comment #3) > I will take care of that. There's already patch waiting for reporter.
I have created patch that should support requested feature: https://github.com/rpm-software-management/dnf/pull/752
The patch in pull request 752 looks good to me.
dnf-1.1.10-6.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-b7cfb5cf10
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
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.
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
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
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
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.