From a00df18546b30146135c76659d4c57a3879fb86b Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:55 +0000
Subject: [PATCH 1/13] sort imports in util


---

diff --git a/util/koji-gc b/util/koji-gc
index feec2fa..3a50ae7 100755
--- a/util/koji-gc
+++ b/util/koji-gc
@@ -7,27 +7,31 @@
 #       Mike McLean <mikem@redhat.com>
 
 from __future__ import absolute_import
-import six
-try:
-    import krbV
-except ImportError:  # pragma: no cover
-    krbV = None
-import koji
-from koji.util import LazyDict, LazyValue, to_list
-import koji.policy
+
 import datetime
 import fnmatch
 import optparse
 import os
 import pprint
 import smtplib
-import socket   # for socket.error
+import socket  # for socket.error
 import sys
 import time
-import six.moves.xmlrpc_client  # for ProtocolError and Fault
+from string import Template
+
+import six
 import six.moves.configparser
+import six.moves.xmlrpc_client  # for ProtocolError and Fault
 from six.moves import email_mime_text as MIMEText
-from string import Template
+
+import koji
+import koji.policy
+from koji.util import LazyDict, LazyValue, to_list
+
+try:
+    import krbV
+except ImportError:  # pragma: no cover
+    krbV = None
 
 
 def _(args):
diff --git a/util/koji-shadow b/util/koji-shadow
index 3b3afb3..f8e8300 100755
--- a/util/koji-shadow
+++ b/util/koji-shadow
@@ -23,26 +23,30 @@
 #       Karsten Hopp <karsten@redhat.com>
 
 from __future__ import absolute_import
-from six.moves import range
-import six
-try:
-    import krbV
-except ImportError:  # pragma: no cover
-    krbV = None
-import koji
-from koji.util import to_list
+
 import fnmatch
 import optparse
 import os
 import random
 import shutil
-import socket   # for socket.error and socket.setdefaulttimeout
+import socket  # for socket.error and socket.setdefaulttimeout
 import string
 import sys
 import time
 import urllib2
-import six.moves.xmlrpc_client  # for ProtocolError and Fault
+
 import rpm
+import six
+import six.moves.xmlrpc_client  # for ProtocolError and Fault
+from six.moves import range
+
+import koji
+from koji.util import to_list
+
+try:
+    import krbV
+except ImportError:  # pragma: no cover
+    krbV = None
 
 # koji.fp.o keeps stalling, probably network errors...
 # better to time out than to stall
diff --git a/util/koji-sweep-db b/util/koji-sweep-db
index 1d71007..265b5c0 100755
--- a/util/koji-sweep-db
+++ b/util/koji-sweep-db
@@ -1,12 +1,13 @@
 #!/usr/bin/python2
 
 import os
-
 from optparse import OptionParser
+
 from six.moves.configparser import RawConfigParser
 
 import koji.db
 
+
 def clean_sessions(cursor, vacuum):
     q = " FROM sessions WHERE update_time < now() - '1 day'::interval"
     if options.verbose:
diff --git a/util/kojira b/util/kojira
index 8a0d6a2..a9176b4 100755
--- a/util/kojira
+++ b/util/kojira
@@ -20,26 +20,26 @@
 # Authors:
 #       Mike McLean <mikem@redhat.com>
 
-from __future__ import absolute_import
-from __future__ import division
-import sys
-import os
-import koji
-from koji.util import rmtree, parseStatus, to_list
-from optparse import OptionParser
+from __future__ import absolute_import, division
+
 import errno
 import json
 import logging
 import logging.handlers
+import os
 import pprint
 import signal
 import stat
-import time
+import sys
 import threading
+import time
 import traceback
-import six
+from optparse import OptionParser
 
+import six
 
+import koji
+from koji.util import parseStatus, rmtree, to_list
 
 tag_cache = {}
 

From b8653736ddd3ffe620de69451c018e6d463d52ec Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:56 +0000
Subject: [PATCH 2/13] sort imports in www


---

diff --git a/www/kojiweb/index.py b/www/kojiweb/index.py
index b5ecd78..09aba88 100644
--- a/www/kojiweb/index.py
+++ b/www/kojiweb/index.py
@@ -20,27 +20,27 @@
 #       Mike Bonnet <mikeb@redhat.com>
 #       Mike McLean <mikem@redhat.com>
 
-from __future__ import absolute_import
-from __future__ import division
+from __future__ import absolute_import, division
+
+import datetime
 import hashlib
+import logging
+import mimetypes
 import os
 import os.path
 import re
 import sys
-import mimetypes
-import six.moves.http_cookies
-import datetime
-import logging
 import time
+
+import six
+import six.moves.http_cookies
+from six.moves import range
+
 import koji
 import kojiweb.util
-from koji.util import to_list
 from koji.server import ServerRedirect
-from kojiweb.util import _initValues
-from kojiweb.util import _genHTML
-from kojiweb.util import _getValidTokens
-from six.moves import range
-import six
+from koji.util import to_list
+from kojiweb.util import _genHTML, _getValidTokens, _initValues
 
 # Convenience definition of a commonly-used sort function
 _sortbyname = lambda x: x['name']
diff --git a/www/kojiweb/wsgi_publisher.py b/www/kojiweb/wsgi_publisher.py
index c3afd32..7f15a55 100644
--- a/www/kojiweb/wsgi_publisher.py
+++ b/www/kojiweb/wsgi_publisher.py
@@ -20,19 +20,21 @@
 #       Mike McLean <mikem@redhat.com>
 
 from __future__ import absolute_import
+
 import cgi
 import inspect
-import koji
-import koji.util
 import logging
 import os.path
 import pprint
 import sys
 import traceback
 
+import six
+
+import koji
+import koji.util
 from koji.server import ServerError, ServerRedirect
 from koji.util import dslice, to_list
-import six
 
 
 class URLNotFound(ServerError):
diff --git a/www/lib/kojiweb/util.py b/www/lib/kojiweb/util.py
index a7bdc09..4946261 100644
--- a/www/lib/kojiweb/util.py
+++ b/www/lib/kojiweb/util.py
@@ -19,25 +19,26 @@
 # Authors:
 #       Mike Bonnet <mikeb@redhat.com>
 #       Mike McLean <mikem@redhat.com>
-from __future__ import absolute_import
-from __future__ import division
+from __future__ import absolute_import, division
+
 import cgi
-import Cheetah.Template
 import datetime
 import hashlib
-import koji
 import os
-import six
 import ssl
 import stat
 import time
-
-from six.moves import range
 #a bunch of exception classes that explainError needs
 from socket import error as socket_error
-from six.moves.xmlrpc_client import ProtocolError
 from xml.parsers.expat import ExpatError
 
+import Cheetah.Template
+import six
+from six.moves import range
+from six.moves.xmlrpc_client import ProtocolError
+
+import koji
+
 
 class NoSuchException(Exception):
     pass

From 77bc43c07aefceae0f2d726af3abe814d09fbe3b Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:56 +0000
Subject: [PATCH 3/13] sort imports in vm


---

diff --git a/vm/kojikamid.py b/vm/kojikamid.py
index ed10101..4058caf 100755
--- a/vm/kojikamid.py
+++ b/vm/kojikamid.py
@@ -27,26 +27,28 @@
 # in a cygwin shell.
 
 from __future__ import absolute_import
-from optparse import OptionParser
-from six.moves.configparser import ConfigParser, SafeConfigParser
+
+import base64
+import glob
+import hashlib
+import logging
 import os
+import re
 import subprocess
 import sys
 import tempfile
+import threading
 import time
-# urllib is required by the SCM class which is substituted into this file
-# do not remove the import below
-from six.moves import urllib
-import six.moves.xmlrpc_client
-import base64
-import hashlib
-import logging
 import traceback
-import threading
-import re
-import glob
 import zipfile
+from optparse import OptionParser
+
 import six
+import six.moves.xmlrpc_client
+# urllib is required by the SCM class which is substituted into this file
+# do not remove the import below
+from six.moves import urllib
+from six.moves.configparser import ConfigParser, SafeConfigParser
 
 MANAGER_PORT = 7000
 
diff --git a/vm/kojivmd b/vm/kojivmd
index d0274db..77ee051 100755
--- a/vm/kojivmd
+++ b/vm/kojivmd
@@ -20,34 +20,37 @@
 # Authors:
 #       Mike Bonnet <mikeb@redhat.com>
 
-from __future__ import absolute_import
-from __future__ import division
-import koji
-import koji.util
-from koji.daemon import SCM, TaskManager
-from koji.tasks import ServerExit, ServerRestart, BaseTaskHandler, MultiPlatformTask
-from koji.tasks import RestartTask, RestartVerifyTask
+from __future__ import absolute_import, division
+
+import base64
+import fnmatch
 import hashlib
-import sys
 import logging
 import os
-import six.moves.xmlrpc_client
+import pwd
+import random
 import signal
-import time
+import socket
 import subprocess
+import sys
+import threading
+import time
+from contextlib import closing
+from optparse import OptionParser
+
 import libvirt
 import libxml2
-import random
+import requests
 import rpm
-import socket
+import six.moves.xmlrpc_client
 import six.moves.xmlrpc_server
-import threading
-import base64
-import pwd
-import requests
-import fnmatch
-from contextlib import closing
-from optparse import OptionParser
+
+import koji
+import koji.util
+from koji.daemon import SCM, TaskManager
+from koji.tasks import (BaseTaskHandler, MultiPlatformTask, RestartTask,
+                        RestartVerifyTask, ServerExit, ServerRestart)
+
 try:
     import krbV
 except ImportError:  # pragma: no cover

From 90cc76573f7bed8e680f7cebd2aeabaa128f3756 Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:56 +0000
Subject: [PATCH 4/13] sort imports in plugins


---

diff --git a/plugins/builder/runroot.py b/plugins/builder/runroot.py
index 5490d96..1a3c0db 100644
--- a/plugins/builder/runroot.py
+++ b/plugins/builder/runroot.py
@@ -1,18 +1,20 @@
 # kojid plugin
 
 from __future__ import absolute_import
-import koji
-import six.moves.configparser
+
 import os
 import platform
 import re
 import subprocess
 
+import six.moves.configparser
+
+import koji
 import koji.tasks
+from __main__ import BuildRoot
+from koji.daemon import log_output
 from koji.tasks import scan_mounts
 from koji.util import isSuccess, parseStatus
-from koji.daemon import log_output
-from __main__ import BuildRoot
 
 __all__ = ('RunRootTask',)
 
diff --git a/plugins/builder/save_failed_tree.py b/plugins/builder/save_failed_tree.py
index f449088..0a4aa05 100644
--- a/plugins/builder/save_failed_tree.py
+++ b/plugins/builder/save_failed_tree.py
@@ -1,4 +1,5 @@
 from __future__ import absolute_import
+
 import fnmatch
 import os
 import sys
diff --git a/plugins/cli/runroot.py b/plugins/cli/runroot.py
index c4b9d08..ba448c4 100644
--- a/plugins/cli/runroot.py
+++ b/plugins/cli/runroot.py
@@ -1,12 +1,13 @@
 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, watch_tasks, \
-                         list_task_output_all_volumes, bytes_to_stdout
+from koji_cli.lib import (_, activate_session, bytes_to_stdout,
+                          list_task_output_all_volumes, watch_tasks)
 
 
 @export_cli
diff --git a/plugins/cli/save_failed_tree.py b/plugins/cli/save_failed_tree.py
index 22cc449..6a0cb00 100644
--- a/plugins/cli/save_failed_tree.py
+++ b/plugins/cli/save_failed_tree.py
@@ -6,6 +6,7 @@ import koji
 from koji.plugin import export_cli
 from koji_cli.lib import _, activate_session, watch_tasks
 
+
 @export_cli
 def handle_save_failed_tree(options, session, args):
     "Create tarball with whole buildtree"
diff --git a/plugins/hub/echo.py b/plugins/hub/echo.py
index 859e05c..1fb63af 100644
--- a/plugins/hub/echo.py
+++ b/plugins/hub/echo.py
@@ -6,10 +6,13 @@
 #     Mike Bonnet <mikeb@redhat.com>
 
 from __future__ import absolute_import
-from koji.plugin import callbacks, callback, ignore_error
-from koji.util import to_list
+
 import logging
 
+from koji.plugin import callback, callbacks, ignore_error
+from koji.util import to_list
+
+
 @callback(*to_list(callbacks.keys()))
 @ignore_error
 def echo(cbtype, *args, **kws):
diff --git a/plugins/hub/protonmsg.py b/plugins/hub/protonmsg.py
index c62d5ef..fdc1aab 100644
--- a/plugins/hub/protonmsg.py
+++ b/plugins/hub/protonmsg.py
@@ -6,15 +6,18 @@
 #     Mike Bonnet <mikeb@redhat.com>
 
 from __future__ import absolute_import
-import koji
-from koji.plugin import callback, ignore_error, convert_datetime
-from koji.context import context
-import logging
+
 import json
+import logging
 import random
+
 from proton import Message, SSLDomain
-from proton.reactor import Container
 from proton.handlers import MessagingHandler
+from proton.reactor import Container
+
+import koji
+from koji.context import context
+from koji.plugin import callback, convert_datetime, ignore_error
 
 CONFIG_FILE = '/etc/koji-hub/plugins/protonmsg.conf'
 CONFIG = None
diff --git a/plugins/hub/rpm2maven.py b/plugins/hub/rpm2maven.py
index f35e086..bbf7581 100644
--- a/plugins/hub/rpm2maven.py
+++ b/plugins/hub/rpm2maven.py
@@ -6,15 +6,16 @@
 #     Mike Bonnet <mikeb@redhat.com>
 
 from __future__ import absolute_import
-import koji
-from koji.context import context
-from koji.plugin import callback
-from koji.util import joinpath
-from koji.util import rmtree
+
 import fnmatch
 import os
 import subprocess
 
+import koji
+from koji.context import context
+from koji.plugin import callback
+from koji.util import joinpath, rmtree
+
 CONFIG_FILE = '/etc/koji-hub/plugins/rpm2maven.conf'
 
 config = None
diff --git a/plugins/hub/runroot_hub.py b/plugins/hub/runroot_hub.py
index 4dc46f2..e963101 100644
--- a/plugins/hub/runroot_hub.py
+++ b/plugins/hub/runroot_hub.py
@@ -4,15 +4,17 @@
 
 
 from __future__ import absolute_import
-from koji.context import context
-from koji.plugin import export
-import koji
+
 import random
 import sys
 
+import koji
+import kojihub
+from koji.context import context
+from koji.plugin import export
+
 #XXX - have to import kojihub for make_task
 sys.path.insert(0, '/usr/share/koji-hub/')
-import kojihub
 
 __all__ = ('runroot',)
 
@@ -60,4 +62,3 @@ def runroot(tagInfo, arch, command, channel=None, **opts):
 
     args = koji.encode_args(tagInfo, arch, command, **opts)
     return kojihub.make_task('runroot', args, **taskopts)
-
diff --git a/plugins/hub/save_failed_tree.py b/plugins/hub/save_failed_tree.py
index bb1f262..f5863ab 100644
--- a/plugins/hub/save_failed_tree.py
+++ b/plugins/hub/save_failed_tree.py
@@ -1,11 +1,13 @@
 from __future__ import absolute_import
+
 import sys
+
 import koji
+import kojihub
 from koji.context import context
 from koji.plugin import export
 
 sys.path.insert(0, '/usr/share/koji-hub/')
-import kojihub
 
 __all__ = ('saveFailedTree',)
 

From 4d29a87e9bcac54432d1a204bca5c9de19890593 Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:57 +0000
Subject: [PATCH 5/13] sort imports in koji


---

diff --git a/koji/__init__.py b/koji/__init__.py
index 6acd1bb..9c609c8 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -22,32 +22,56 @@
 #       Mike Bonnet <mikeb@redhat.com>
 
 
-from __future__ import absolute_import
-from __future__ import division
+from __future__ import absolute_import, division
+
+import base64
+import datetime
+import errno
+import hashlib
+import imp
+import logging
+import logging.handlers
+import optparse
+import os
+import os.path
+import pwd
+import random
+import re
+import shutil
+import signal
+import socket
+import struct
 import sys
-from six.moves import range
-from six.moves import zip
+import tempfile
+import time
+import traceback
+import warnings
+import weakref
+import xml.sax
+import xml.sax.handler
+from fnmatch import fnmatch
+
+import requests
 import six
+import six.moves.configparser
+import six.moves.http_client
+import six.moves.urllib
+from six.moves import range, zip
+
+from koji.xmlrpcplus import Fault, dumps, getparser, loads, xmlrpc_client
+
+from . import util
+
 krbV = None
 try:
     import krbV
 except ImportError:  # pragma: no cover
     pass
-import base64
-import datetime
 dns_resolver = None
 try:
     import dns.resolver as dns_resolver
 except ImportError:  # pragma: no cover
     pass
-import six.moves.configparser
-import errno
-from fnmatch import fnmatch
-import hashlib
-import six.moves.http_client
-import imp
-import logging
-import logging.handlers
 SSL_Error = None
 try:
     from OpenSSL.SSL import Error as SSL_Error
@@ -57,13 +81,6 @@ except Exception:  # pragma: no cover
     # unfortunately the workaround at the above link does not always work, so
     # we ignore it here
     pass
-import optparse
-import os
-import os.path
-import pwd
-import random
-import re
-import requests
 try:
     import requests_kerberos
 except ImportError:  # pragma: no cover
@@ -72,20 +89,6 @@ try:
     import rpm
 except ImportError:
     rpm = None
-import shutil
-import signal
-import socket
-import struct
-import tempfile
-import time
-import traceback
-import warnings
-import weakref
-import xml.sax
-import xml.sax.handler
-import six.moves.urllib
-from . import util
-from koji.xmlrpcplus import getparser, loads, dumps, Fault, xmlrpc_client
 
 
 PROFILE_MODULES = {}  # {module_name: module_instance}
diff --git a/koji/arch.py b/koji/arch.py
index 1327ac6..dc1fde8 100644
--- a/koji/arch.py
+++ b/koji/arch.py
@@ -1,11 +1,12 @@
 # This code is from the rpmUtils.arch module of yum
 # yum is licensed as GPLv2+
 
-import os
-import rpm
 import ctypes
+import os
 import struct
 
+import rpm
+
 _ppc64_native_is_best = True
 
 # dict mapping arch -> ( multicompat, best personality, biarch personality )
diff --git a/koji/auth.py b/koji/auth.py
index 9d91bfc..c44d43f 100644
--- a/koji/auth.py
+++ b/koji/auth.py
@@ -20,22 +20,25 @@
 #       Mike Bonnet <mikeb@redhat.com>
 
 from __future__ import absolute_import
-import socket
-import string
+
+import base64
 import random
 import re
-import base64
+import socket
+import string
+
+import six
+from six.moves import range, urllib, zip
+
+import koji
+
+from .context import context
+from .util import to_list
+
 try:
     import krbV
 except ImportError:
     krbV = None
-import koji
-from .context import context
-from six.moves import range
-from six.moves import urllib
-from six.moves import zip
-import six
-from .util import to_list
 
 # 1 - load session if provided
 #       - check uri for session id
diff --git a/koji/context.py b/koji/context.py
index 274ef33..87e43a1 100644
--- a/koji/context.py
+++ b/koji/context.py
@@ -24,8 +24,10 @@
 #    - auth data
 
 from __future__ import absolute_import
-import six.moves._thread
+
 import six
+import six.moves._thread
+
 
 class _data(object):
     pass
diff --git a/koji/daemon.py b/koji/daemon.py
index 3d9919e..e7775cc 100644
--- a/koji/daemon.py
+++ b/koji/daemon.py
@@ -20,27 +20,28 @@
 #       Mike McLean <mikem@redhat.com>
 #       Mike Bonnet <mikeb@redhat.com>
 
-from __future__ import absolute_import
-from __future__ import division
-import koji
-import koji.tasks
-import koji.xmlrpcplus
-from koji.tasks import safe_rmtree
-from koji.util import adler32_constructor, parseStatus, \
-                      dslice, to_list, base64encode
+from __future__ import absolute_import, division
+
+import errno
 import hashlib
+import logging
 import os
 import signal
-import logging
-from fnmatch import fnmatch
-import time
 import subprocess
 import sys
+import time
 import traceback
-import errno
-from six.moves import range
-from six.moves import urllib
+from fnmatch import fnmatch
+
 import six
+from six.moves import range, urllib
+
+import koji
+import koji.tasks
+import koji.xmlrpcplus
+from koji.tasks import safe_rmtree
+from koji.util import (adler32_constructor, base64encode, dslice, parseStatus,
+                       to_list)
 
 
 def incremental_upload(session, fname, fd, path, retries=5, logger=None):
diff --git a/koji/db.py b/koji/db.py
index 125e5ee..8a085bf 100644
--- a/koji/db.py
+++ b/koji/db.py
@@ -22,8 +22,8 @@
 
 
 from __future__ import absolute_import
+
 import logging
-import psycopg2
 # import psycopg2.extensions
 # # don't convert timestamp fields to DateTime objects
 # del psycopg2.extensions.string_types[1114]
@@ -35,6 +35,9 @@ import re
 import sys
 import time
 import traceback
+
+import psycopg2
+
 from . import context
 
 POSITIONAL_RE = re.compile(r'%[a-z]')
diff --git a/koji/plugin.py b/koji/plugin.py
index 5250e87..d6e8555 100644
--- a/koji/plugin.py
+++ b/koji/plugin.py
@@ -20,12 +20,15 @@
 #       Mike Bonnet <mikeb@redhat.com>
 
 from __future__ import absolute_import
+
 import imp
-import koji
 import logging
 import sys
 import traceback
+
 import six
+
+import koji
 from koji.util import encode_datetime_recurse
 
 # the available callback hooks and a list
diff --git a/koji/policy.py b/koji/policy.py
index bb0ed00..853016e 100644
--- a/koji/policy.py
+++ b/koji/policy.py
@@ -18,12 +18,13 @@
 #       Mike McLean <mikem@redhat.com>
 
 from __future__ import absolute_import
+
 import fnmatch
 import logging
 
-import koji
 import six
 
+import koji
 from koji.util import to_list
 
 
diff --git a/koji/rpmdiff.py b/koji/rpmdiff.py
index 7f78754..12f72af 100644
--- a/koji/rpmdiff.py
+++ b/koji/rpmdiff.py
@@ -19,14 +19,17 @@
 # It was modified to be used as standalone library for the Koji project.
 
 from __future__ import absolute_import
+
 import hashlib
+import itertools
 import json
-import rpm
 import os
-import itertools
+
+import rpm
 import six
 from six.moves import zip
 
+
 class BytesJSONEncoder(json.JSONEncoder):
     def default(self, o):
         if six.PY3 and isinstance(o, bytes):
diff --git a/koji/util.py b/koji/util.py
index af3d116..ab9e96d 100644
--- a/koji/util.py
+++ b/koji/util.py
@@ -18,15 +18,12 @@
 #       Mike McLean <mikem@redhat.com>
 #       Mike Bonnet <mikeb@redhat.com>
 
-from __future__ import absolute_import
-from __future__ import division
+from __future__ import absolute_import, division
+
 import base64
 import calendar
 import datetime
 import hashlib
-from koji.xmlrpcplus import DateTime
-from fnmatch import fnmatch
-import koji
 import logging
 import os
 import os.path
@@ -37,11 +34,16 @@ import stat
 import struct
 import sys
 import time
+import warnings
+from fnmatch import fnmatch
 from zlib import adler32
-from six.moves import range
+
 import six
-import warnings
-from six.moves import zip
+from six.moves import range, zip
+
+import koji
+from koji.xmlrpcplus import DateTime
+
 
 # imported from kojiweb and kojihub
 def md5_constructor(*args, **kwargs):
diff --git a/koji/xmlrpcplus.py b/koji/xmlrpcplus.py
index f818cbc..a3d18a6 100644
--- a/koji/xmlrpcplus.py
+++ b/koji/xmlrpcplus.py
@@ -3,10 +3,11 @@ Custom xmlrpc handling for Koji
 """
 
 from __future__ import absolute_import
-import six
-import six.moves.xmlrpc_client as xmlrpc_client
+
 import types
 
+import six
+import six.moves.xmlrpc_client as xmlrpc_client
 
 # duplicate a few values that we need
 getparser = xmlrpc_client.getparser

From a58148a7ed1f6808f6d3a048b2f3a35f7260852a Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:57 +0000
Subject: [PATCH 6/13] sort imports in hub


---

diff --git a/hub/kojihub.py b/hub/kojihub.py
index 8b3488e..5e3c84f 100644
--- a/hub/kojihub.py
+++ b/hub/kojihub.py
@@ -23,9 +23,9 @@
 #       Cristian Balint <cbalint@redhat.com>
 
 from __future__ import absolute_import
+
 import base64
 import calendar
-import koji.rpmdiff
 import datetime
 import errno
 import fcntl
@@ -43,18 +43,12 @@ import tarfile
 import tempfile
 import time
 import traceback
-import six.moves.xmlrpc_client
 import zipfile
-try:
-    # py 3.6+
-    import secrets
-except ImportError:
-    import random
-    secrets = None
 
 import rpm
 import six
-
+import six.moves.xmlrpc_client
+from six.moves import range
 from six.moves.urllib.parse import parse_qs
 
 import koji
@@ -62,18 +56,20 @@ import koji.auth
 import koji.db
 import koji.plugin
 import koji.policy
-import koji.xmlrpcplus
+import koji.rpmdiff
 import koji.tasks
+import koji.xmlrpcplus
 from koji.context import context
-from koji.util import base64encode
-from koji.util import decode_bytes
-from koji.util import dslice
-from koji.util import joinpath
-from koji.util import move_and_symlink
-from koji.util import multi_fnmatch
-from koji.util import safer_move
-from koji.util import to_list
-from six.moves import range
+from koji.util import (base64encode, decode_bytes, dslice, joinpath,
+                       move_and_symlink, multi_fnmatch, safer_move, to_list)
+
+try:
+    # py 3.6+
+    import secrets
+except ImportError:
+    import random
+    secrets = None
+
 
 logger = logging.getLogger('koji.hub')
 
diff --git a/hub/kojixmlrpc.py b/hub/kojixmlrpc.py
index d59b9c9..621284f 100644
--- a/hub/kojixmlrpc.py
+++ b/hub/kojixmlrpc.py
@@ -18,18 +18,21 @@
 # Authors:
 #       Mike McLean <mikem@redhat.com>
 
-from __future__ import absolute_import
-from __future__ import division
+from __future__ import absolute_import, division
+
 import datetime
 import inspect
 import logging
 import os
+import pprint
+import resource
 import sys
-import time
 import threading
+import time
 import traceback
-import pprint
-import resource
+
+import six
+from six.moves import range
 
 import koji
 import koji.auth
@@ -37,11 +40,9 @@ import koji.db
 import koji.plugin
 import koji.policy
 import koji.util
-# import xmlrpclib functions from koji to use tweaked Marshaller
-from koji.xmlrpcplus import getparser, dumps, Fault, ExtendedMarshaller
 from koji.context import context
-from six.moves import range
-import six
+# import xmlrpclib functions from koji to use tweaked Marshaller
+from koji.xmlrpcplus import ExtendedMarshaller, Fault, dumps, getparser
 
 
 class Marshaller(ExtendedMarshaller):

From 8c21aa7e6db2bc0ed748e2b38935e2b221c91949 Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:57 +0000
Subject: [PATCH 7/13] sort imports in cli


---

diff --git a/cli/koji b/cli/koji
index 3ae4d94..9783f50 100755
--- a/cli/koji
+++ b/cli/koji
@@ -24,26 +24,23 @@
 #       Mike Bonnet <mikeb@redhat.com>
 #       Cristian Balint <cbalint@redhat.com>
 
-from __future__ import absolute_import
-from __future__ import division
+from __future__ import absolute_import, division
+
 import logging
 import os
 import re
-import six
 import sys
+from optparse import SUPPRESS_HELP, OptionParser
 
-from optparse import OptionParser, SUPPRESS_HELP
-
+import six
 import six.moves.configparser
 import six.moves.xmlrpc_client
 
 import koji
-import koji.util
 import koji.plugin
-
-from koji_cli.lib import _, get_epilog_str, greetings, \
-        warn, categories
+import koji.util
 from koji_cli.commands import *
+from koji_cli.lib import _, categories, get_epilog_str, greetings, warn
 
 
 def register_plugin(plugin):
diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py
index f3c77a4..13056c5 100644
--- a/cli/koji_cli/commands.py
+++ b/cli/koji_cli/commands.py
@@ -1,8 +1,6 @@
-from __future__ import absolute_import
-from __future__ import division
+from __future__ import absolute_import, division
 
 import ast
-from collections import defaultdict, OrderedDict
 import fnmatch
 import hashlib
 import json
@@ -15,15 +13,22 @@ import stat
 import sys
 import time
 import traceback
-from optparse import OptionParser, SUPPRESS_HELP
+from collections import OrderedDict, defaultdict
+from optparse import SUPPRESS_HELP, OptionParser
 
 import dateutil.parser
 import six
 import six.moves.xmlrpc_client
-from six.moves import filter
-from six.moves import map
-from six.moves import zip
-from six.moves import range
+from six.moves import filter, map, range, zip
+
+import koji
+from koji.util import base64encode, to_list
+from koji_cli.lib import (_, _list_tasks, _progress_callback, _running_in_bg,
+                          activate_session, arg_filter, download_file, error,
+                          format_inheritance_flags, greetings, linked_upload,
+                          list_task_output_all_volumes, parse_arches,
+                          print_task_headers, print_task_recurse, unique_path,
+                          warn, watch_logs, watch_tasks)
 
 try:
     import libcomps
@@ -34,15 +39,6 @@ except ImportError:  # pragma: no cover
     except ImportError:
         yumcomps = None
 
-import koji
-from koji.util import to_list, base64encode
-from koji_cli.lib import _, activate_session, parse_arches, \
-        _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, \
-        error, warn, greetings, _list_tasks, unique_path, \
-        format_inheritance_flags, get_usage_str
-
 
 def _printable_unicode(s):
     if six.PY2:
diff --git a/cli/koji_cli/lib.py b/cli/koji_cli/lib.py
index a49a5c6..2243960 100644
--- a/cli/koji_cli/lib.py
+++ b/cli/koji_cli/lib.py
@@ -1,27 +1,29 @@
 # coding=utf-8
-from __future__ import absolute_import
-from __future__ import division
+from __future__ import absolute_import, division
+
 import optparse
 import os
 import random
-import requests
-import six
 import socket
 import string
 import sys
 import time
 from contextlib import closing
+
+import requests
+import six
 from six.moves import range
 
+import koji
+# import parse_arches to current namespace for backward compatibility
+from koji import parse_arches
+from koji.util import to_list
+
 try:
     import krbV
 except ImportError:  # pragma: no cover
     krbV = None
 
-import koji
-from koji.util import to_list
-# import parse_arches to current namespace for backward compatibility
-from koji import parse_arches
 
 # for compatibility with plugins based on older version of lib
 # Use optparse imports directly in new code.

From 79a387e90ade3d5ec86664133f7645a5d4f66bf1 Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:58 +0000
Subject: [PATCH 8/13] sort imports in builder


---

diff --git a/builder/kojid b/builder/kojid
index 54cbf5a..fc7e0e0 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -21,10 +21,8 @@
 #       Mike McLean <mikem@redhat.com>
 #       Mike Bonnet <mikeb@redhat.com>
 
-from __future__ import absolute_import
-from __future__ import division
+from __future__ import absolute_import, division
 
-import Cheetah.Template
 import copy
 import glob
 import grp
@@ -35,11 +33,8 @@ import os
 import pwd
 import random
 import re
-import rpm
 import shutil
 import signal
-import six
-import six.moves.xmlrpc_client
 import smtplib
 import socket
 import sys
@@ -49,18 +44,24 @@ import xml.dom.minidom
 import zipfile
 from fnmatch import fnmatch
 from gzip import GzipFile
-from optparse import OptionParser, SUPPRESS_HELP
+from optparse import SUPPRESS_HELP, OptionParser
 
+import Cheetah.Template
+import rpm
+import six
+import six.moves.xmlrpc_client
 from multilib import multilib
+
 import koji
 import koji.arch
 import koji.plugin
 import koji.rpmdiff
-import koji.util
 import koji.tasks
-from koji.daemon import incremental_upload, log_output, TaskManager, SCM
-from koji.tasks import ServerExit, ServerRestart, BaseTaskHandler, MultiPlatformTask
-from koji.util import parseStatus, isSuccess, dslice, dslice_ex, to_list
+import koji.util
+from koji.daemon import SCM, TaskManager, incremental_upload, log_output
+from koji.tasks import (BaseTaskHandler, MultiPlatformTask, ServerExit,
+                        ServerRestart)
+from koji.util import dslice, dslice_ex, isSuccess, parseStatus, to_list
 
 try:
     import krbV
diff --git a/builder/mergerepos b/builder/mergerepos
index dcd7647..7628a78 100755
--- a/builder/mergerepos
+++ b/builder/mergerepos
@@ -22,15 +22,17 @@
 # written by Seth Vidal
 
 from __future__ import absolute_import
-import createrepo
+
 import os.path
-import rpmUtils.miscutils
 import shutil
 import sys
 import tempfile
+from optparse import OptionParser
+
+import createrepo
+import rpmUtils.miscutils
 import yum
 import yum.misc
-from optparse import OptionParser
 
 # Expand a canonical arch to the full list of
 # arches that should be included in the repo.

From 558f7be2d2e0288b17d43f40e625b93926d33268 Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:58 +0000
Subject: [PATCH 9/13] fix newline betwwen koji and relative imports


---

diff --git a/koji/__init__.py b/koji/__init__.py
index 9c609c8..6808162 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -59,7 +59,6 @@ import six.moves.urllib
 from six.moves import range, zip
 
 from koji.xmlrpcplus import Fault, dumps, getparser, loads, xmlrpc_client
-
 from . import util
 
 krbV = None
diff --git a/koji/auth.py b/koji/auth.py
index c44d43f..8520069 100644
--- a/koji/auth.py
+++ b/koji/auth.py
@@ -31,7 +31,6 @@ import six
 from six.moves import range, urllib, zip
 
 import koji
-
 from .context import context
 from .util import to_list
 

From 63c50c2a311895e7db7c507d1695d5c36f7c581f Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:58 +0000
Subject: [PATCH 10/13] sort imports for other scripts


---

diff --git a/devtools/fakehub b/devtools/fakehub
index 3b21dfa..c1b777d 100755
--- a/devtools/fakehub
+++ b/devtools/fakehub
@@ -1,12 +1,13 @@
 #!/usr/bin/python2
 
-from __future__ import absolute_import
-from __future__ import print_function
+from __future__ import absolute_import, print_function
+
 import ast
 import os
 import os.path
 import pprint
 import sys
+
 from six.moves import cStringIO
 from six.moves.urllib.parse import quote
 
diff --git a/devtools/fakeweb b/devtools/fakeweb
index 469c693..12454e3 100755
--- a/devtools/fakeweb
+++ b/devtools/fakeweb
@@ -1,16 +1,16 @@
 #!/usr/bin/python2
 
-from __future__ import absolute_import
-from __future__ import print_function
+from __future__ import absolute_import, print_function
+
 import mimetypes
 import os
 import os.path
 import pprint
 import sys
+from wsgiref.simple_server import make_server
+from wsgiref.util import setup_testing_defaults
 
 from six.moves.urllib.parse import quote
-from wsgiref.util import setup_testing_defaults
-from wsgiref.simple_server import make_server
 
 CWD = os.getcwd()
 sys.path.insert(0, CWD)
diff --git a/runtests b/runtests
index 5eeea2c..29ab808 100755
--- a/runtests
+++ b/runtests
@@ -1,8 +1,8 @@
 #!/usr/bin/python2
 
-from multiprocessing import Pool
 import subprocess
 import tempfile
+from multiprocessing import Pool
 
 
 def explode_ref(ref, dest):
diff --git a/setup.py b/setup.py
index c91bcd2..ea8b81b 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,10 @@
 from __future__ import absolute_import
+
 import sys
+
 from setuptools import setup
 
+
 def get_install_requires():
     # To install all build requires:
     # $ dnf install python-pip git krb5-devel gcc redhat-rpm-config \

From 5b83c682e47e901fa777d61668671bcce7d5bf11 Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:58 +0000
Subject: [PATCH 11/13] remove unused imports


---

diff --git a/cli/koji b/cli/koji
index 9783f50..fb9e105 100755
--- a/cli/koji
+++ b/cli/koji
@@ -39,7 +39,7 @@ import six.moves.xmlrpc_client
 import koji
 import koji.plugin
 import koji.util
-from koji_cli.commands import *
+from koji_cli.commands import *  # noqa: F401, F403
 from koji_cli.lib import _, categories, get_epilog_str, greetings, warn
 
 
diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py
index 13056c5..a7238de 100644
--- a/cli/koji_cli/commands.py
+++ b/cli/koji_cli/commands.py
@@ -26,9 +26,9 @@ from koji.util import base64encode, to_list
 from koji_cli.lib import (_, _list_tasks, _progress_callback, _running_in_bg,
                           activate_session, arg_filter, download_file, error,
                           format_inheritance_flags, greetings, linked_upload,
-                          list_task_output_all_volumes, parse_arches,
-                          print_task_headers, print_task_recurse, unique_path,
-                          warn, watch_logs, watch_tasks)
+                          list_task_output_all_volumes, print_task_headers,
+                          print_task_recurse, unique_path, warn, watch_logs,
+                          watch_tasks)
 
 try:
     import libcomps
diff --git a/koji/__init__.py b/koji/__init__.py
index 6808162..d0f9a6c 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -37,7 +37,6 @@ import os.path
 import pwd
 import random
 import re
-import shutil
 import signal
 import socket
 import struct
diff --git a/koji/tasks.py b/koji/tasks.py
index 1fea289..12edc70 100644
--- a/koji/tasks.py
+++ b/koji/tasks.py
@@ -25,7 +25,6 @@ import logging
 import os
 import pprint
 import random
-import shutil
 import signal
 import time
 
diff --git a/vm/kojikamid.py b/vm/kojikamid.py
index 4058caf..f4f26ae 100755
--- a/vm/kojikamid.py
+++ b/vm/kojikamid.py
@@ -47,7 +47,7 @@ import six
 import six.moves.xmlrpc_client
 # urllib is required by the SCM class which is substituted into this file
 # do not remove the import below
-from six.moves import urllib
+from six.moves import urllib  # noqa: F401
 from six.moves.configparser import ConfigParser, SafeConfigParser
 
 MANAGER_PORT = 7000
diff --git a/vm/kojivmd b/vm/kojivmd
index 77ee051..b37a955 100755
--- a/vm/kojivmd
+++ b/vm/kojivmd
@@ -41,14 +41,14 @@ from optparse import OptionParser
 import libvirt
 import libxml2
 import requests
-import rpm
 import six.moves.xmlrpc_client
 import six.moves.xmlrpc_server
 
 import koji
 import koji.util
 from koji.daemon import SCM, TaskManager
-from koji.tasks import (BaseTaskHandler, MultiPlatformTask, RestartTask,
+# TaskHandlers are required to be imported, do not remove them
+from koji.tasks import (BaseTaskHandler, MultiPlatformTask, RestartTask,  # noqa: F401
                         RestartVerifyTask, ServerExit, ServerRestart)
 
 try:
diff --git a/www/lib/kojiweb/util.py b/www/lib/kojiweb/util.py
index 4946261..3e8a08c 100644
--- a/www/lib/kojiweb/util.py
+++ b/www/lib/kojiweb/util.py
@@ -27,7 +27,6 @@ import hashlib
 import os
 import ssl
 import stat
-import time
 #a bunch of exception classes that explainError needs
 from socket import error as socket_error
 from xml.parsers.expat import ExpatError

From 1e1a760da07939ee6ecb3b914fb8a0a9c1849e19 Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:00:58 +0000
Subject: [PATCH 12/13] `make flake8` targets and .flake8 config


it requires
```
pip install flake8
pip install flake8-import-order
```

or

```
dnf install python3-flake8 python3-flake8-import-order
```

---

diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..65dba9a
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,20 @@
+[flake8]
+select = I,C,F4
+ignore = F
+exclude = .git,
+          __pycache__,
+          tests,
+          docs,
+          ./koji-*
+filename = *.py
+           ./cli/koji
+           ./builder/kojid
+           ./builder/mergerepos
+           ./hub/rpmdiff
+           ./util/kojira
+           ./util/koji-gc
+           ./util/koji-shadow
+           ./util/koji-sweep-db
+           ./vm/kojivmd
+application_import_names = koji,koji_cli,kojihub,kojiweb,__main__
+import_order_style = pep8
diff --git a/Makefile b/Makefile
index a1b9496..995b23f 100644
--- a/Makefile
+++ b/Makefile
@@ -135,6 +135,9 @@ pypi:
 pypi-upload:
 	twine upload dist/*
 
+flake8:
+	flake8
+
 tag::
 	git tag -a $(TAG)
 	@echo "Tagged with: $(TAG)"

From cb2480fd5b21e721fa5496dfb21a0047e410e809 Mon Sep 17 00:00:00 2001
From: Yu Ming Zhu <yzhu@redhat.com>
Date: Dec 12 2019 11:12:11 +0000
Subject: [PATCH 13/13] fix import of get_usage_str in commands.py


---

diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py
index a7238de..faca3a9 100644
--- a/cli/koji_cli/commands.py
+++ b/cli/koji_cli/commands.py
@@ -25,10 +25,10 @@ import koji
 from koji.util import base64encode, to_list
 from koji_cli.lib import (_, _list_tasks, _progress_callback, _running_in_bg,
                           activate_session, arg_filter, download_file, error,
-                          format_inheritance_flags, greetings, linked_upload,
-                          list_task_output_all_volumes, print_task_headers,
-                          print_task_recurse, unique_path, warn, watch_logs,
-                          watch_tasks)
+                          format_inheritance_flags, get_usage_str, greetings,
+                          linked_upload, list_task_output_all_volumes,
+                          print_task_headers, print_task_recurse, unique_path,
+                          warn, watch_logs, watch_tasks)
 
 try:
     import libcomps

