From f427400d5e741bd1073f1fcc928f3227326b0bee Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: Mar 20 2019 09:03:40 +0000
Subject: Remove python2.4 OptionParse fix


Fixes: https://pagure.io/koji/issue/1341

---

diff --git a/cli/koji b/cli/koji
index 0402158..1ea6d91 100755
--- a/cli/koji
+++ b/cli/koji
@@ -27,12 +27,12 @@
 from __future__ import absolute_import
 from __future__ import division
 import logging
-import optparse
 import os
 import re
 import six
 import sys
-import types
+
+from optparse import OptionParser, SUPPRESS_HELP
 
 import six.moves.configparser
 import six.moves.xmlrpc_client
@@ -41,7 +41,7 @@ import koji
 import koji.util
 import koji.plugin
 
-from koji_cli.lib import _, OptionParser, get_epilog_str, greetings, \
+from koji_cli.lib import _, get_epilog_str, greetings, \
         warn, categories
 from koji_cli.commands import *
 
@@ -123,7 +123,7 @@ def get_options():
     parser.add_option("--topdir", help=_("specify topdir"))
     parser.add_option("--weburl", help=_("url of the Koji web interface"))
     parser.add_option("--topurl", help=_("url for Koji file access"))
-    parser.add_option("--pkgurl", help=optparse.SUPPRESS_HELP)
+    parser.add_option("--pkgurl", help=SUPPRESS_HELP)
     parser.add_option("--help-commands", action="store_true", default=False, help=_("list commands"))
     (options, args) = parser.parse_args()
 
@@ -212,7 +212,7 @@ def handle_help(options, session, args):
     usage += _("\n(Specify the --help global option for a list of other help options)")
     parser = OptionParser(usage=usage)
     # the --admin opt is for backwards compatibility. It is equivalent to: koji help admin
-    parser.add_option("--admin", action="store_true", help=optparse.SUPPRESS_HELP)
+    parser.add_option("--admin", action="store_true", help=SUPPRESS_HELP)
 
     (options, args) = parser.parse_args(args)
 
diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py
index 4b8bce2..8efe4de 100644
--- a/cli/koji_cli/commands.py
+++ b/cli/koji_cli/commands.py
@@ -7,7 +7,6 @@ from collections import defaultdict, OrderedDict
 import fnmatch
 import json
 import logging
-import optparse
 import os
 import pprint
 import random
@@ -16,6 +15,7 @@ import stat
 import sys
 import time
 import traceback
+from optparse import OptionParser, SUPPRESS_HELP
 
 import dateutil.parser
 import six
@@ -36,7 +36,7 @@ except ImportError:  # pragma: no cover
 
 import koji
 from koji.util import md5_constructor, to_list, base64encode
-from koji_cli.lib import _, OptionParser, activate_session, parse_arches, \
+from koji_cli.lib import _, activate_session, parse_arches, \
         _unique_path, _running_in_bg, _progress_callback, watch_tasks, \
         arg_filter, linked_upload, list_task_output_all_volumes, \
         print_task_headers, print_task_recurse, download_file, watch_logs, \
@@ -225,7 +225,7 @@ def handle_add_host_to_channel(goptions, session, args):
     usage = _("usage: %prog add-host-to-channel [options] hostname channel")
     usage += _("\n(Specify the --help global option for a list of other help options)")
     parser = OptionParser(usage=usage)
-    parser.add_option("--list", action="store_true", help=optparse.SUPPRESS_HELP)
+    parser.add_option("--list", action="store_true", help=SUPPRESS_HELP)
     parser.add_option("--new", action="store_true", help=_("Create channel if needed"))
     (options, args) = parser.parse_args(args)
     if not options.list and len(args) != 2:
diff --git a/cli/koji_cli/lib.py b/cli/koji_cli/lib.py
index f328a1b..8e8bf99 100644
--- a/cli/koji_cli/lib.py
+++ b/cli/koji_cli/lib.py
@@ -21,17 +21,9 @@ except ImportError:  # pragma: no cover
 import koji
 from koji.util import to_list
 
-# fix OptionParser for python 2.3 (optparse verion 1.4.1+)
-# code taken from optparse version 1.5a2
+# for compatibility with plugins based on older version of lib
+# Use optparse imports directly in new code.
 OptionParser = optparse.OptionParser
-if optparse.__version__ == "1.4.1+":  # pragma: no cover
-    def _op_error(self, msg):
-        self.print_usage(sys.stderr)
-        msg = "%s: error: %s\n" % (self._get_prog_name(), msg)
-        if msg:
-            sys.stderr.write(msg)
-        sys.exit(2)
-    OptionParser.error = _op_error
 
 greetings = ('hello', 'hi', 'yo', "what's up", "g'day", 'back to work',
              'bonjour',
diff --git a/plugins/cli/runroot.py b/plugins/cli/runroot.py
index 8af9043..c4b9d08 100644
--- a/plugins/cli/runroot.py
+++ b/plugins/cli/runroot.py
@@ -1,10 +1,11 @@
 from __future__ import absolute_import
 import sys
 import time
+from optparse import OptionParser
 
 import koji
 from koji.plugin import export_cli
-from koji_cli.lib import _, activate_session, OptionParser, watch_tasks, \
+from koji_cli.lib import _, activate_session, watch_tasks, \
                          list_task_output_all_volumes, bytes_to_stdout
 
 
diff --git a/plugins/cli/save_failed_tree.py b/plugins/cli/save_failed_tree.py
index 5bf1a6d..22cc449 100644
--- a/plugins/cli/save_failed_tree.py
+++ b/plugins/cli/save_failed_tree.py
@@ -1,7 +1,10 @@
 from __future__ import absolute_import
+
+from optparse import OptionParser
+
 import koji
 from koji.plugin import export_cli
-from koji_cli.lib import _, activate_session, OptionParser, watch_tasks
+from koji_cli.lib import _, activate_session, watch_tasks
 
 @export_cli
 def handle_save_failed_tree(options, session, args):
diff --git a/util/koji-gc b/util/koji-gc
index 576614a..a269074 100755
--- a/util/koji-gc
+++ b/util/koji-gc
@@ -28,17 +28,6 @@ import six.moves.configparser
 from six.moves import email_mime_text as MIMEText
 
 
-OptionParser = optparse.OptionParser
-if optparse.__version__ == "1.4.1+":
-    def _op_error(self, msg):
-        self.print_usage(sys.stderr)
-        msg = "%s: error: %s\n" % (self._get_prog_name(), msg)
-        if msg:
-            sys.stderr.write(msg)
-        sys.exit(2)
-    OptionParser.error = _op_error
-
-
 def _(args):
     """Stub function for translation"""
     return args
@@ -47,7 +36,7 @@ def get_options():
     """process options from command line and config file"""
 
     usage = _("%prog [options]")
-    parser = OptionParser(usage=usage)
+    parser = optparse.OptionParser(usage=usage)
     parser.add_option("-c", "--config-file", metavar="FILE",
                       help=_("use alternate configuration file"))
     parser.add_option("--keytab", help=_("specify a Kerberos keytab to use"))
diff --git a/util/koji-shadow b/util/koji-shadow
index ee93e13..c0924fc 100755
--- a/util/koji-shadow
+++ b/util/koji-shadow
@@ -51,16 +51,6 @@ socket.setdefaulttimeout(180)  #XXX - too short?
 
 logfile = None
 
-OptionParser = optparse.OptionParser
-if optparse.__version__ == "1.4.1+":
-    def _op_error(self, msg):
-        self.print_usage(sys.stderr)
-        msg = "%s: error: %s\n" % (self._get_prog_name(), msg)
-        if msg:
-            sys.stderr.write(msg)
-        sys.exit(2)
-    OptionParser.error = _op_error
-
 
 def _(args):
     """Stub function for translation"""
@@ -80,7 +70,7 @@ def get_options():
     """process options from command line and config file"""
 
     usage = _("%prog [options]")
-    parser = OptionParser(usage=usage)
+    parser = optparse.OptionParser(usage=usage)
     parser.add_option("-c", "--config-file", metavar="FILE",
                       help=_("use alternate configuration file"))
     parser.add_option("--keytab", help=_("specify a Kerberos keytab to use"))

