Fix crash in COPR plugin

Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
This commit is contained in:
Igor Gnatenko 2017-07-02 11:36:09 +02:00
parent d9f13d6bce
commit 2198208b78
2 changed files with 95 additions and 2 deletions

View File

@ -0,0 +1,89 @@
From 366dbf4c3561a769a47dec10653aeb65db289437 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenko@redhat.com>
Date: Sun, 2 Jul 2017 11:34:47 +0200
Subject: [PATCH] Revert "Unify user confirmation in copr with dnf itself
(RhBug:1436321)"
This reverts commit 479f1251558c62cad97f9f3ef8f22bc0c8dcc47f.
---
plugins/copr.py | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/plugins/copr.py b/plugins/copr.py
index ff7edd9..c09dc20 100644
--- a/plugins/copr.py
+++ b/plugins/copr.py
@@ -37,6 +37,11 @@ PLUGIN_CONF = 'copr'
YES = set([_('yes'), _('y')])
NO = set([_('no'), _('n'), ''])
+# compatibility with Py2 and Py3 - rename raw_input() to input() on Py2
+try:
+ input = raw_input
+except NameError:
+ pass
if PY3:
from configparser import ConfigParser
else:
@@ -145,7 +150,7 @@ class CoprCommand(dnf.cli.Command):
.format(self.base.conf.get_reposdir, copr_username, copr_projectname)
if subcommand == "enable":
self._need_root()
- msg = _("""
+ self._ask_user("""
You are about to enable a Copr repository. Please note that this
repository is not part of the main distribution, and quality may vary.
@@ -157,8 +162,7 @@ and packages are not held to any quality or security level.
Please do not file bug reports about these packages in Fedora
Bugzilla. In case of problems, contact the owner of this repository.
-Do you want to continue?""")
- self._ask_user(msg)
+Do you want to continue? [y/N]: """)
self._download_repo(project_name, repo_filename, chroot)
logger.info(_("Repository successfully enabled."))
elif subcommand == "disable":
@@ -225,11 +229,20 @@ Do you want to continue?""")
formatted = self.base.output.fmtSection(text)
print(formatted)
- def _ask_user(self, msg):
- if self.base._promptWanted():
- if self.base.conf.assumeno or not self.base.output.userconfirm(
- msg='{} [y/N]: '.format(msg), defaultyes_msg='{} [Y/n]: '.format(msg)):
- raise dnf.exceptions.Error(_('Safe and good answer. Exiting.'))
+ def _ask_user(self, question):
+ if self.base.conf.assumeyes and not self.base.conf.assumeno:
+ return
+ elif self.base.conf.assumeno and not self.base.conf.assumeyes:
+ raise dnf.exceptions.Error(_('Safe and good answer. Exiting.'))
+
+ answer = None
+ while not ((answer in YES) or (answer in NO)):
+ answer = ucd(input(question)).lower()
+ answer = _(answer)
+ if answer in YES:
+ return
+ else:
+ raise dnf.exceptions.Error(_('Safe and good answer. Exiting.'))
@classmethod
def _need_root(cls):
@@ -352,11 +365,10 @@ class PlaygroundCommand(CoprCommand):
def _cmd_enable(self, chroot):
self._need_root()
- msg = _("""
+ self._ask_user("""
You are about to enable a Playground repository.
-Do you want to continue?""")
- self._ask_user(msg)
+Do you want to continue? [y/N]: """)
api_url = "{0}/api/playground/list/".format(
self.copr_url)
f = self.base.urlopen(api_url, mode="w+")
--
2.13.2

View File

@ -11,11 +11,12 @@
Name: dnf-plugins-core
Version: 2.1.2
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Core Plugins for DNF
License: GPLv2+
URL: https://github.com/rpm-software-management/dnf-plugins-core
Source0: %{url}/archive/%{name}-%{version}/%{name}-%{version}.tar.gz
Patch0001: 0001-Revert-Unify-user-confirmation-in-copr-with-dnf-itse.patch
BuildArch: noarch
BuildRequires: cmake
BuildRequires: gettext
@ -297,7 +298,7 @@ updated by newer versions.
%endif
%prep
%autosetup
%autosetup -p1
mkdir build-py2
%if %{with python3}
mkdir build-py3
@ -494,6 +495,9 @@ PYTHONPATH=./plugins nosetests-%{python3_version} -s tests/
%endif
%changelog
* Sun Jul 02 2017 Igor Gnatenko <ignatenkO@redhat.com> - 2.1.2-2
- Fix crash in COPR plugin
* Sat Jul 01 2017 Igor Gnatenko <ignatenko@redhat.com> - 2.1.2-1
- debuginfo-install: install only requested packages
- Unify user confirmation in copr with dnf itself