#35 Fix some pylint warnings
Merged 2 years ago by jhutar. Opened 2 years ago by msuchy.
msuchy/rpmfluff pylint1  into  master

file modified
+6 -4
@@ -27,13 +27,15 @@ 

  import os.path

  import shutil

  import sys

- import rpm

  import subprocess

  import re

  

- from .check import Check, FailedCheck, CheckPayloadFile, CheckPayloadFile, \

-                    CheckSourceFile, CheckTrigger, CheckRequires, CheckProvides 

- from .make import make_png, make_gif, make_png

+ # 3rd party modules

+ import rpm

+ 

+ from .check import Check, FailedCheck, CheckPayloadFile, \

+                    CheckSourceFile, CheckTrigger, CheckRequires, CheckProvides

+ 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

file modified
+5 -5
@@ -100,14 +100,14 @@ 

          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

file modified
+23 -24
@@ -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
@@ -233,7 +235,7 @@ 

          """

          @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:
@@ -298,7 +300,6 @@ 

          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:
@@ -450,13 +451,13 @@ 

          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 +550,7 @@ 

          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 +639,15 @@ 

              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,36 +671,35 @@ 

          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):

          """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):

              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 @@ 

      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):
@@ -765,7 +765,6 @@ 

          # (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

  

file modified
+2 -2
@@ -13,16 +13,16 @@ 

  # 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:

-     def __init__(self, sourceName, content, encoding = 'utf8'):

+     def __init__(self, sourceName, content, encoding='utf8'):

          self.sourceName = sourceName

          self.content = content

          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")

file modified
+2 -2
@@ -29,7 +29,7 @@ 

  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 @@ 

      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',