From 900b3fc7b866ddab76dd8a07b6d6e5950f1f2f39 Mon Sep 17 00:00:00 2001
From: Miroslav Suchý <msuchy@redhat.com>
Date: May 27 2020 12:37:53 +0000
Subject: [PATCH 1/5] fix bad-whitespace pylint warning


---

diff --git a/rpmfluff/check.py b/rpmfluff/check.py
index 192c2a1..d733798 100644
--- a/rpmfluff/check.py
+++ b/rpmfluff/check.py
@@ -100,14 +100,14 @@ class CheckTrigger(Check):
         for t in rpmHdr[rpm.RPMTAG_TRIGGERTYPE]:
             # print(t)
             # print(rpmHdr[rpm.RPMTAG_TRIGGERCONDS][index])
-            if t==_utf8_encode(self.trigger.event) and rpmHdr[rpm.RPMTAG_TRIGGERCONDS][index]==_utf8_encode(self.trigger.triggerConds):
-                if rpmHdr[rpm.RPMTAG_TRIGGERSCRIPTS][index]!=_utf8_encode(self.trigger.script):
-                    raise FailedCheck(self, 'script "%s" did not match expected "%s"'%(rpmHdr[rpm.RPMTAG_TRIGGERSCRIPTS][index],self.trigger.script))
+            if t == _utf8_encode(self.trigger.event) and rpmHdr[rpm.RPMTAG_TRIGGERCONDS][index] == _utf8_encode(self.trigger.triggerConds):
+                if rpmHdr[rpm.RPMTAG_TRIGGERSCRIPTS][index] != _utf8_encode(self.trigger.script):
+                    raise FailedCheck(self, 'script "%s" did not match expected "%s"'%(rpmHdr[rpm.RPMTAG_TRIGGERSCRIPTS][index], self.trigger.script))
                 expectedProgram = self.trigger.program
                 if expectedProgram is None:
                     expectedProgram = "/bin/sh"
-                if rpmHdr[rpm.RPMTAG_TRIGGERSCRIPTPROG][index]!=_utf8_encode(expectedProgram):
-                    raise FailedCheck(self, 'executable "%s" did not match expected "%s"'%(rpmHdr[rpm.RPMTAG_TRIGGERSCRIPTPROG][index],expectedProgram))
+                if rpmHdr[rpm.RPMTAG_TRIGGERSCRIPTPROG][index] != _utf8_encode(expectedProgram):
+                    raise FailedCheck(self, 'executable "%s" did not match expected "%s"'%(rpmHdr[rpm.RPMTAG_TRIGGERSCRIPTPROG][index], expectedProgram))
 
                 # We have a match:
                 return
diff --git a/rpmfluff/rpmbuild.py b/rpmfluff/rpmbuild.py
index c9dda8c..f5684d6 100644
--- a/rpmfluff/rpmbuild.py
+++ b/rpmfluff/rpmbuild.py
@@ -233,7 +233,7 @@ class SimpleRpmBuild(RpmBuild):
         """
         @return: get a subpackage by suffix (e.g. "devel"), or None/"" for the base package
         """
-        if suffix==None or suffix=='':
+        if suffix == None or suffix == '':
             return self.basePackage
 
         for sub in self.subPackages:
@@ -450,13 +450,13 @@ class SimpleRpmBuild(RpmBuild):
         if not name:
             name = self.name
 
-        if arch=="SRPMS":
-            archSuffix="src"
+        if arch == "SRPMS":
+            archSuffix = "src"
         else:
-            archSuffix=arch
+            archSuffix = arch
 
-        builtRpmName="%s-%s-%s.%s.rpm"%(name, self.version, expand_macros(self.release), archSuffix)
-        if arch=="SRPMS":
+        builtRpmName = "%s-%s-%s.%s.rpm"%(name, self.version, expand_macros(self.release), archSuffix)
+        if arch == "SRPMS":
             builtRpmDir = self.get_srpms_dir()
         else:
             builtRpmDir = os.path.join(self.get_rpms_dir(), arch)
@@ -549,7 +549,7 @@ class SimpleRpmBuild(RpmBuild):
         self.basePackage.add_conflicts(conflicts)
 
     def add_build_requires(self, requirement):
-        self.basePackage.section_requires  += "BuildRequires: %s\n"%requirement
+        self.basePackage.section_requires += "BuildRequires: %s\n"%requirement
 
     def add_trigger(self, trigger):
         "Add a trigger"
@@ -638,15 +638,15 @@ class SimpleRpmBuild(RpmBuild):
             self.section_install += "chmod %s $RPM_BUILD_ROOT/%s\n"%(mode, self.escape_path(installPath))
 
         sub = self.get_subpackage(subpackageSuffix)
-        tag=""
+        tag = ""
         if owner or group:
             tag += '%%attr(-,%s,%s) ' % (owner or '-', group or '-')
         if isConfig:
-            tag+="%config "
+            tag += "%config "
         if isDoc:
-            tag+="%doc "
+            tag += "%doc "
         if isGhost:
-            tag+="%ghost "
+            tag += "%ghost "
         sub.section_files += '%s"/%s"\n'%(tag, installPath)
 
     def add_installed_directory(self,
@@ -670,18 +670,18 @@ class SimpleRpmBuild(RpmBuild):
         sub = self.get_subpackage(subpackageSuffix)
         tag = ""
         if isConfig:
-            tag+="%config "
+            tag += "%config "
         if isDoc:
-            tag+="%doc "
+            tag += "%doc "
         if isGhost:
-            tag+="%ghost "
+            tag += "%ghost "
         sub.section_files += '%s"/%s"\n'%(tag, installedPath)
         self.add_payload_check(installedPath, subpackageSuffix)
 
     def add_simple_payload_file(self):
         """Trivial hook for adding a simple file to payload, hardcoding all params"""
-        self.add_installed_file(installPath = 'usr/share/doc/hello-world.txt',
-                                sourceFile = SourceFile('hello-world.txt', 'hello world\n'),
+        self.add_installed_file(installPath='usr/share/doc/hello-world.txt',
+                                sourceFile=SourceFile('hello-world.txt', 'hello world\n'),
                                 isDoc=True)
 
     def add_simple_payload_file_random(self, size=100):
@@ -692,14 +692,14 @@ class SimpleRpmBuild(RpmBuild):
         for _ in range(size):
             content = content + chr(random.randrange(32, 127))
         name = "%s-%s-%s-%s-%s-%s.txt" % (self.epoch, self.name, self.version, expand_macros(self.release), self.get_build_archs()[0], len(self.sources))
-        self.add_installed_file(installPath = 'usr/share/doc/%s' % name,
-                                sourceFile = SourceFile(name, content),
+        self.add_installed_file(installPath='usr/share/doc/%s' % name,
+                                sourceFile=SourceFile(name, content),
                                 isDoc=True)
 
     def add_simple_compilation(self,
                                sourceFileName="main.c",
                                sourceContent=hello_world,
-                               compileFlags = "",
+                               compileFlags="",
                                installPath="usr/bin/hello-world",
                                createParentDirs=True,
                                subpackageSuffix=None):
@@ -717,8 +717,8 @@ class SimpleRpmBuild(RpmBuild):
     def add_simple_library(self,
                            sourceFileName="foo.c",
                            sourceContent=simple_library_source,
-                           compileFlags = "",
-                           libraryName = 'libfoo.so',
+                           compileFlags="",
+                           libraryName='libfoo.so',
                            installPath="usr/lib/libfoo.so",
                            createParentDirs=True,
                            subpackageSuffix=None):
diff --git a/rpmfluff/sourcefile.py b/rpmfluff/sourcefile.py
index 6a06028..ab6811c 100644
--- a/rpmfluff/sourcefile.py
+++ b/rpmfluff/sourcefile.py
@@ -16,7 +16,7 @@
 import os.path
 
 class SourceFile:
-    def __init__(self, sourceName, content, encoding = 'utf8'):
+    def __init__(self, sourceName, content, encoding='utf8'):
         self.sourceName = sourceName
         self.content = content
         self.encoding = encoding
diff --git a/rpmfluff/test.py b/rpmfluff/test.py
index 5b4c001..cd0431b 100644
--- a/rpmfluff/test.py
+++ b/rpmfluff/test.py
@@ -29,7 +29,7 @@ from .sourcefile import SourceFile, GeneratedSourceFile
 from .trigger import Trigger
 from .yumrepobuild import YumRepoBuild
 
-testTrigger='print "This is the trigger!'
+testTrigger = 'print "This is the trigger!'
 
 class TestSimpleRpmBuild(unittest.TestCase):
     def assert_header_has_item(self, rpmFilename, tagId, item, msg=None):
@@ -406,7 +406,7 @@ class TestSimpleRpmBuild(unittest.TestCase):
     def test_subpackage_names_B(self):
         self.rpmbuild.add_devel_subpackage()
         self.rpmbuild.add_subpackage('ssl')
-        self.rpmbuild.makeDebugInfo=True
+        self.rpmbuild.makeDebugInfo = True
         self.assertEqual(self.rpmbuild.get_subpackage_names(), ['test-subpackage-names-B',
                                                                  'test-subpackage-names-B-devel',
                                                                  'test-subpackage-names-B-ssl',

From ccc252ca696303465b140c896a71d0eb682ce447 Mon Sep 17 00:00:00 2001
From: Miroslav Suchý <msuchy@redhat.com>
Date: May 27 2020 12:40:06 +0000
Subject: [PATCH 2/5] fix trailing-whitespace pylint warning


---

diff --git a/rpmfluff/__init__.py b/rpmfluff/__init__.py
index 4fd3f61..3aa2ee4 100644
--- a/rpmfluff/__init__.py
+++ b/rpmfluff/__init__.py
@@ -32,7 +32,7 @@ import subprocess
 import re
 
 from .check import Check, FailedCheck, CheckPayloadFile, CheckPayloadFile, \
-                   CheckSourceFile, CheckTrigger, CheckRequires, CheckProvides 
+                   CheckSourceFile, CheckTrigger, CheckRequires, CheckProvides
 from .make import make_png, make_gif, make_png
 from .rpmbuild import Buildable, RpmBuild, SimpleRpmBuild
 from .utils import expand_macros, get_rpm_header, _utf8_encode, CC

From be3575055b8c35731f8ebcd8631d18ba0748d701 Mon Sep 17 00:00:00 2001
From: Miroslav Suchý <msuchy@redhat.com>
Date: May 27 2020 12:42:08 +0000
Subject: [PATCH 3/5] fix reimported pylint warning


---

diff --git a/rpmfluff/__init__.py b/rpmfluff/__init__.py
index 3aa2ee4..ae3cc72 100644
--- a/rpmfluff/__init__.py
+++ b/rpmfluff/__init__.py
@@ -31,9 +31,9 @@ import rpm
 import subprocess
 import re
 
-from .check import Check, FailedCheck, CheckPayloadFile, CheckPayloadFile, \
+from .check import Check, FailedCheck, CheckPayloadFile, \
                    CheckSourceFile, CheckTrigger, CheckRequires, CheckProvides
-from .make import make_png, make_gif, make_png
+from .make import make_gif, make_png
 from .rpmbuild import Buildable, RpmBuild, SimpleRpmBuild
 from .utils import expand_macros, get_rpm_header, _utf8_encode, CC
 from .subpackage import Subpackage

From 524e1cd9dcd13b3c15948eaa528ffbc43a6802bf Mon Sep 17 00:00:00 2001
From: Miroslav Suchý <msuchy@redhat.com>
Date: May 27 2020 12:43:24 +0000
Subject: [PATCH 4/5] fix wrong-import-order pylint warning


---

diff --git a/rpmfluff/__init__.py b/rpmfluff/__init__.py
index ae3cc72..a35a57e 100644
--- a/rpmfluff/__init__.py
+++ b/rpmfluff/__init__.py
@@ -27,10 +27,12 @@ import os
 import os.path
 import shutil
 import sys
-import rpm
 import subprocess
 import re
 
+# 3rd party modules
+import rpm
+
 from .check import Check, FailedCheck, CheckPayloadFile, \
                    CheckSourceFile, CheckTrigger, CheckRequires, CheckProvides
 from .make import make_gif, make_png

From 6ef0471234f84ee770c0c027db01d1a42afc5db0 Mon Sep 17 00:00:00 2001
From: Miroslav Suchý <msuchy@redhat.com>
Date: May 27 2020 12:59:56 +0000
Subject: [PATCH 5/5] fix import-outside-toplevel pylint warning


I am going to not touch test.py as if there is failure in import it just fail that one test.

---

diff --git a/rpmfluff/rpmbuild.py b/rpmfluff/rpmbuild.py
index f5684d6..5d25604 100644
--- a/rpmfluff/rpmbuild.py
+++ b/rpmfluff/rpmbuild.py
@@ -13,8 +13,10 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
+import codecs
 import os
 import os.path
+import random
 import re
 import shutil
 import subprocess
@@ -298,7 +300,6 @@ class SimpleRpmBuild(RpmBuild):
         self.section_postun += postunLine
 
     def gather_spec_file(self, tmpDir):
-        import codecs
         if self.specbasename and self.specbasename != '':
             specFileName = os.path.join(tmpDir, "%s.spec" % self.specbasename)
         else:
@@ -686,7 +687,6 @@ class SimpleRpmBuild(RpmBuild):
 
     def add_simple_payload_file_random(self, size=100):
         """Trivial hook for adding a simple file to payload, random (ASCII printable chars) content of specified size (default is 100 bytes), name based on the packages ENVRA and count of the source files (to be unique)"""
-        import random
         random.seed()
         content = ''
         for _ in range(size):
@@ -765,7 +765,6 @@ class SimpleRpmBuild(RpmBuild):
         # (which would lead to duplicates in the merged log).
         # So we rot13 the desired message, and echo that through a shell
         # rot13 (using tr), getting the desired output to stderr
-        import codecs
         rot13Message = codecs.getencoder('rot-13')(message)[0]
         self.section_build += "echo '%s' | tr 'a-zA-Z' 'n-za-mN-ZA-N' 1>&2\n" % rot13Message
 
diff --git a/rpmfluff/sourcefile.py b/rpmfluff/sourcefile.py
index ab6811c..dd4d59a 100644
--- a/rpmfluff/sourcefile.py
+++ b/rpmfluff/sourcefile.py
@@ -13,6 +13,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
+import codecs
 import os.path
 
 class SourceFile:
@@ -22,7 +23,6 @@ class SourceFile:
         self.encoding = encoding
 
     def _get_dst_file(self, sourcesDir):
-        import codecs
         dstFileName = os.path.join(sourcesDir, self.sourceName)
         if isinstance(self.content, bytes):
             dstFile = open(dstFileName, "wb")

