From 48fff26928b66c03bf284e7f84d9e49d69440497 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Aug 29 2019 03:51:03 +0000 Subject: Remove unnecessary interpolation when logging. The log methods are supposed to do the interpolation for you. This saves a bit of work if there's no output. --- diff --git a/r2spec/build.py b/r2spec/build.py index 6e51378..bdf1e39 100644 --- a/r2spec/build.py +++ b/r2spec/build.py @@ -58,12 +58,12 @@ class Build: 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 @@ class Build: 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 @@ class Build: 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 @@ class Build: 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 @@ class Build: 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) diff --git a/r2spec/r2spec_obj.py b/r2spec/r2spec_obj.py index b826c2b..e08f69d 100644 --- a/r2spec/r2spec_obj.py +++ b/r2spec/r2spec_obj.py @@ -313,7 +313,7 @@ class R2rpm(R2spec): """ 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 @@ class R2rpm(R2spec): # 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 @@ class R2rpm(R2spec): 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() diff --git a/r2spec/rpackage.py b/r2spec/rpackage.py index a4a0f9b..f5b5873 100644 --- a/r2spec/rpackage.py +++ b/r2spec/rpackage.py @@ -58,15 +58,15 @@ def package_in_repo(url, name): 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 @@ class RPackage(object): 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 @@ class RPackage(object): """ 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 @@ class RPackage(object): 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 @@ class RPackage(object): 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 @@ class RPackage(object): 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 @@ class RPackage(object): """ 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 @@ class RPackage(object): 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) diff --git a/r2spec/spec.py b/r2spec/spec.py index 351379b..39ad341 100644 --- a/r2spec/spec.py +++ b/r2spec/spec.py @@ -214,7 +214,7 @@ class Spec: 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 @@ class Spec: """ 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)