#22 Remove unnecessary interpolation when logging.
Merged 4 years ago by pingou. Opened 4 years ago by qulogic.
qulogic/r2spec log-interpolation  into  master

file modified
+7 -7
@@ -58,12 +58,12 @@ 

          if mock_config is None or mock_config is False:

              cmd = 'LANG=C rpmbuild -%s %s > %s 2>&1' % (rpmarg,

                  specname, self.buildlog)

-             self.log.debug(cmd)

+             self.log.debug('Running %s', cmd)

              self.outcode = subprocess.call(cmd, shell=True)

          else:

              cmd = 'LANG=C rpmbuild -bs %s > %s 2>&1' % (

                  specname, self.buildlog)

-             self.log.debug(cmd)

+             self.log.debug('Running %s', cmd)

              self.outcode = subprocess.call(cmd, shell=True)

              self.get_rpm()

  
@@ -75,7 +75,7 @@ 

                      mock_resultdir, name)

              cmd = 'LANG=C %s >> %s.build.log 2>&1' % (

                  mockcommand, specname)

-             self.log.debug(cmd)

+             self.log.debug('Running %s', cmd)

              self.outcode = subprocess.call(cmd, shell=True)

              if self.outcode == 30:

                  # When mock stop while building the cache, then check
@@ -91,7 +91,7 @@ 

                  directory = get_mock_root()

                  self.buildlog = '/%s/%s-%s/result/%s' % (

                      directory, mock_config, name, filename)

-             self.log.debug('buildlog %s' % self.buildlog)

+             self.log.debug('buildlog %s', self.buildlog)

  

      def get_rpm(self):

          """ Parses the build.log to extract the rpm generated.
@@ -110,8 +110,8 @@ 

                      else:

                          self.rpm.append(rpm)

          except IOError as err:

-             self.log.info('Could not read the file "%s"' % self.buildlog)

-             self.log.debug('ERROR: %s' % err)

+             self.log.info('Could not read the file "%s"', self.buildlog)

+             self.log.debug('ERROR: %s', err)

  

      def remove_logs(self):

          """ Remove the log file generated while building the RPM. """
@@ -134,7 +134,7 @@ 

              stream.close()

          except IOError as err:

              self.log.info('An error occured during the build')

-             self.log.debug('ERROR: %s' % err)

+             self.log.debug('ERROR: %s', err)

              print('Stopping')

              return(1)

  

file modified
+6 -5
@@ -313,7 +313,7 @@ 

          """

          specfile = self.spec.get_specfile()

          if self.build.outcode == 0:

-             self.log.info("RPM %s done" % specfile)

+             self.log.info("RPM %s done", specfile)

              # Get the list of rpm generated

              self.build.get_rpm()

              print("RPM generated:")
@@ -366,8 +366,9 @@ 

              # Generate the spec file

              self.pack = super(R2rpm, self).main(args)

          else:

-             self.log.info('Spec file "%s" is already there, no need to regenerate it'

-                 % specfile)

+             self.log.info(

+                 'Spec file "%s" is already there, no need to regenerate it',

+                 specfile)

  

          if args.package or args.url:

              self.pack.download(args.force_dl)
@@ -399,11 +400,11 @@ 

                      self.__check_build_output()

              except BuildDepencenciesError as err:

                  print('Missing dependencies to build %s' % self.pack.name)

-                 self.log.info(err)

+                 self.log.info('%s', err)

                  return 1

              except BuildError as err:

                  print('An error occured during the build of %s' % self.pack.name)

-                 self.log.debug('Build ERROR: %s' % err)

+                 self.log.debug('Build ERROR: %s', err)

                  return 1

          if not args.keep_logs:

              self.build.remove_logs()

file modified
+18 -18
@@ -58,15 +58,15 @@ 

          sourcemotif = re.compile(r"Package:\s+%s\n" % name)

          result = sourcemotif.search(content)

          if result is not None:

-             log.info("Package found in : %s" % url)

+             log.info("Package found in : %s", url)

              versionmotif = re.compile(r"Package:\s+%s\nVersion:(.*)" % name)

              version = versionmotif.search(content).group(1).strip()

              return (version)

          else:

-             log.info("Not Found: %s in %s" % (name, url))

+             log.info("Not Found: %s in %s", name, url)

      except IOError as ex:

          print('Could not contact the repository at url: %s' % url)

-         log.debug('Error: %s' % ex)

+         log.debug('Error: %s', ex)

      return None

  

  
@@ -138,7 +138,7 @@ 

  

          url = self.source0.rsplit('/', 1)[0]

          url = '%s/%s' % (url, self.source)

-         self.log.info('Downloading %s' % url)

+         self.log.info('Downloading %s', url)

  

          remotefile = urllib_request.urlopen(url)

          with open(sources, 'wb') as localfile:
@@ -148,14 +148,14 @@ 

          """ Extract the sources into the current directory. """

          sourcedir = get_rpm_tag('_sourcedir')

          tarball = "%s/%s" % (sourcedir, self.source)

-         self.log.info("Opening: %s" % tarball)

+         self.log.info("Opening: %s", tarball)

          try:

              tar = tarfile.open(tarball)

              tar.extractall()

              tar.close()

          except TarError as err:

              self.log.debug("Error while extracting the tarball")

-             self.log.debug("ERROR: %s" % err)

+             self.log.debug("ERROR: %s", err)

  

      def get(self, key):

          """ Retrieve the given key from the description information known
@@ -175,7 +175,7 @@ 

          from in them.

          """

          description = '%s/DESCRIPTION' % self.name

-         self.log.info('Loading "%s"' % description)

+         self.log.info('Loading "%s"', description)

          if os.path.exists(self.name) and os.path.isfile(description):

              try:

                  stream = open(description, 'r')
@@ -183,9 +183,9 @@ 

                  stream.close()

              except IOError as err:

                  self.log.info(

-                 'An error occured while reading the DESCRIPTION file: %s' \

-                 % description)

-                 self.log.debug('ERROR: %s' % err)

+                     'An error occurred while reading the DESCRIPTION file: %s',

+                     description)

+                 self.log.debug('ERROR: %s', err)

              key = None

              for row in content.split('\n'):

                  if row.strip():
@@ -197,8 +197,8 @@ 

                          self.description[key] = self.description[key] + ' ' + \

                              row.strip()

          else:

-             self.log.info('Could not find a DESCRIPTION file "%s" to read' \

-                 % description)

+             self.log.info('Could not find a DESCRIPTION file "%s" to read',

+                           description)

  

      def read_config(self):

          """ Read the general configuration containing the repo information
@@ -212,13 +212,13 @@ 

          """ Remove the source we extracted in the current working

          directory.

          """

-         self.log.info('Removing extracted sources: "%s"' % self.name)

+         self.log.info('Removing extracted sources: "%s"', self.name)

          try:

              shutil.rmtree(self.name)

          except (IOError, OSError) as err:

-             self.log.info('Could not remove the extracted sources: "%s"'\

-                 % self.name)

-             self.log.debug('ERROR: %s' % err)

+             self.log.info('Could not remove the extracted sources: "%s"',

+                           self.name)

+             self.log.debug('ERROR: %s', err)

  

      def search_package_in_repo(self):

          """ Search a package in all R repositories listed in the general
@@ -235,8 +235,8 @@ 

                      break

          if version is None:

              self.log.info(

-             'Could not find package "%s" in any of the congifure repos' \

-             % self.name)

+                 'Could not find package "%s" in any of the configured repos',

+                 self.name)

              raise R2specError(

              'Could not find package "%s" in any of the configured repos' \

                  % self.name)

file modified
+8 -8
@@ -214,7 +214,7 @@ 

              mytemplate = Template(tplfile)

              self.spec = mytemplate.render(self.__dict)

          except IOError as err:

-             self.log.debug('ERROR: %s' % err)

+             self.log.debug('ERROR: %s', err)

              raise R2specError('Cannot read the file %s' % template)

  

      def get_specfile(self):
@@ -229,27 +229,27 @@ 

          """

          specfile = self.get_specfile()

          if os.path.exists(specfile) and os.path.isfile(specfile):

-             self.log.info('Reading file %s' % specfile)

+             self.log.info('Reading file %s', specfile)

              try:

                  stream = open(specfile, 'r')

                  self.spec = stream.read()

                  stream.close()

              except IOError as err:

-                 self.log.info('Cannot read the file %s' % specfile)

-                 self.log.debug('ERROR: %s' % err)

+                 self.log.info('Cannot read the file %s', specfile)

+                 self.log.debug('ERROR: %s', err)

  

      def write_spec(self, verbose=False):

          """ Write down the spec to the spec directory as returned by rpm.

          """

          specfile = self.get_specfile()

-         self.log.info('Writing file %s' % specfile)

+         self.log.info('Writing file %s', specfile)

          try:

              stream = open(specfile, 'w')

              stream.write(self.spec)

              stream.close()

-             self.log.debug('Spec file writen: %s' % specfile)

+             self.log.debug('Spec file written: %s', specfile)

              if verbose:

                  print('Spec file writen: %s' % specfile)

          except IOError as err:

-             self.log.info('Cannot write the file %s' % specfile)

-             self.log.debug('ERROR: %s' % err)

+             self.log.info('Cannot write the file %s', specfile)

+             self.log.debug('ERROR: %s', err)

The log methods are supposed to do the interpolation for you. This saves
a bit of work if there's no output.

Pull-Request has been merged by pingou

4 years ago