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

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