Blame SOURCES/0020-Shorter-verification-that-the-project-exists.patch

9f4a6f
From bf230d570763acc6ccd4f4b3951f4b8325a8e4b8 Mon Sep 17 00:00:00 2001
9f4a6f
From: Silvie Chlupova <sisi.chlupova@gmail.com>
9f4a6f
Date: Fri, 3 Sep 2021 15:45:43 +0200
9f4a6f
Subject: [PATCH] Shorter verification that the project exists
9f4a6f
9f4a6f
---
9f4a6f
 plugins/copr.py | 16 ++++++----------
9f4a6f
 1 file changed, 6 insertions(+), 10 deletions(-)
9f4a6f
9f4a6f
diff --git a/plugins/copr.py b/plugins/copr.py
9f4a6f
index 9f597dd..1539c0d 100644
9f4a6f
--- a/plugins/copr.py
9f4a6f
+++ b/plugins/copr.py
9f4a6f
@@ -70,8 +70,10 @@ NO = set([_('no'), _('n'), ''])
9f4a6f
 
9f4a6f
 if PY3:
9f4a6f
     from configparser import ConfigParser, NoOptionError, NoSectionError
9f4a6f
+    from urllib.request import urlopen, HTTPError
9f4a6f
 else:
9f4a6f
     from ConfigParser import ConfigParser, NoOptionError, NoSectionError
9f4a6f
+    from urllib2 import urlopen, HTTPError
9f4a6f
 
9f4a6f
 @dnf.plugin.register_command
9f4a6f
 class CoprCommand(dnf.cli.Command):
9f4a6f
@@ -478,17 +480,11 @@ Bugzilla. In case of problems, contact the owner of this repository.
9f4a6f
             if os.path.exists(repo_filename):
9f4a6f
                 os.remove(repo_filename)
9f4a6f
             if '404' in str(e):
9f4a6f
-                if PY3:
9f4a6f
-                    import urllib.request
9f4a6f
-                    try:
9f4a6f
-                        res = urllib.request.urlopen(self.copr_url + "/coprs/" + project_name)
9f4a6f
-                        status_code = res.getcode()
9f4a6f
-                    except urllib.error.HTTPError as e:
9f4a6f
-                        status_code = e.getcode()
9f4a6f
-                else:
9f4a6f
-                    import urllib
9f4a6f
-                    res = urllib.urlopen(self.copr_url + "/coprs/" + project_name)
9f4a6f
+                try:
9f4a6f
+                    res = urlopen(self.copr_url + "/coprs/" + project_name)
9f4a6f
                     status_code = res.getcode()
9f4a6f
+                except HTTPError as e:
9f4a6f
+                    status_code = e.getcode()
9f4a6f
                 if str(status_code) != '404':
9f4a6f
                     raise dnf.exceptions.Error(_("This repository does not have"
9f4a6f
                                                  " any builds yet so you cannot enable it now."))
9f4a6f
-- 
9f4a6f
2.36.1
9f4a6f