Skip to content

Commit

Permalink
Fixes pylint W1202
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Hracek <phracek@redhat.com>
  • Loading branch information
phracek committed Apr 8, 2015
1 parent 15248c1 commit 3aa0ffb
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 113 deletions.
37 changes: 16 additions & 21 deletions rebasehelper/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ def _get_spec_file(self):
"""
self.spec_file_path = PathHelper.find_first_file(self.execution_dir, '*.spec', 0)
if not self.spec_file_path:
raise RebaseHelperError("Could not find any SPEC file in the current directory '{0}'".format(
self.execution_dir))
raise RebaseHelperError("Could not find any SPEC file in the current directory '%s'", self.execution_dir)

def _delete_old_builds(self):
"""
Expand Down Expand Up @@ -200,7 +199,7 @@ def _delete_workspace_dir(self):
Deletes workspace directory and loggs message
:return:
"""
logger.debug("Removing the workspace directory '{0}'".format(self.workspace_dir))
logger.debug("Removing the workspace directory '%s'", self.workspace_dir)
shutil.rmtree(self.workspace_dir)

def _check_workspace_dir(self):
Expand All @@ -209,7 +208,7 @@ def _check_workspace_dir(self):
:return:
"""
if os.path.exists(self.workspace_dir):
logger.warning("Workspace directory '{0}' exists, removing it".format(os.path.basename(self.workspace_dir)))
logger.warning("Workspace directory '%s' exists, removing it", os.path.basename(self.workspace_dir))
self._delete_workspace_dir()
os.makedirs(self.workspace_dir)

Expand All @@ -220,7 +219,7 @@ def _check_results_dir(self):
"""
# TODO: We may not want to delete the directory in the future
if os.path.exists(self.results_dir):
logger.warning("Results directory '{0}' exists, removing it".format(os.path.basename(self.results_dir)))
logger.warning("Results directory '%s' exists, removing it", os.path.basename(self.results_dir))
shutil.rmtree(self.results_dir)
os.makedirs(self.results_dir)

Expand All @@ -236,15 +235,14 @@ def extract_archive(archive_path, destination):
try:
archive = Archive(archive_path)
except NotImplementedError as ni_e:
raise RebaseHelperError('{0}. Supported archives are {1}'.format(
ni_e.message, Archive.get_supported_archives()))
raise RebaseHelperError('%s. Supported archives are %s', ni_e.message, Archive.get_supported_archives())

try:
archive.extract(destination)
except IOError:
raise RebaseHelperError("Archive '{0}' can not be extracted".format(archive_path))
raise RebaseHelperError("Archive '%s' can not be extracted", archive_path)
except (EOFError, SystemError):
raise RebaseHelperError("Archive '{0}' is damaged".format(archive_path))
raise RebaseHelperError("Archive '%s' is damaged", archive_path)

@staticmethod
def extract_sources(archive_path, destination):
Expand Down Expand Up @@ -314,8 +312,7 @@ def build_packages(self):
try:
builder = Builder(self.conf.buildtool)
except NotImplementedError as ni_e:
raise RebaseHelperError('{0}. Supported build tools are {1}'.format(
ni_e.message, Builder.get_supported_tools()))
raise RebaseHelperError('%s. Supported build tools are %s', ni_e.message, Builder.get_supported_tools())

for version in ['old', 'new']:
spec_object = self.spec_file if version == 'old' else self.rebase_spec_file
Expand Down Expand Up @@ -349,25 +346,24 @@ def build_packages(self):
build_log = 'build.log'
build_log_path = os.path.join(rpm_dir, build_log)
if version == 'old':
raise RebaseHelperError('Building old RPM package failed. Check log {0}'.format(build_log_path))
raise RebaseHelperError('Building old RPM package failed. Check log %s', build_log_path)
logger.error('Building binary packages failed.')
try:
files = BuildLogAnalyzer.parse_log(rpm_dir, build_log)
except BuildLogAnalyzerMissingError:
raise RebaseHelperError('Build log {0} does not exist'.format(build_log_path))
raise RebaseHelperError('Build log %s does not exist', build_log_path)
except BuildLogAnalyzerMakeError:
raise RebaseHelperError('Building package failed during build. Check log {0}'.format(build_log_path))
raise RebaseHelperError('Building package failed during build. Check log %s', build_log_path)
except BuildLogAnalyzerPatchError:
raise RebaseHelperError('Building package failed during patching. Check log {0}'.format(build_log_path))
raise RebaseHelperError('Building package failed during patching. Check log %s', build_log_path)

if files['missing']:
logger.info('Files not packaged in the SPEC file:\n{f}'.format(f='\n'.join(files['added'])))
elif files['deleted']:
logger.warning('Removed files packaged in SPEC file:\n{f}'.format(
f='\n'.join(files['deleted'])))
else:
raise RebaseHelperError("Build failed, but no issues were found in the build log {0}".format(
build_log))
raise RebaseHelperError("Build failed, but no issues were found in the build log %s", build_log)
self.rebase_spec_file.modify_spec_files_section(files)

if not self.conf.non_interactive:
Expand All @@ -394,10 +390,9 @@ def pkgdiff_packages(self):
try:
pkgchecker = Checker(self.conf.pkgcomparetool)
except NotImplementedError:
raise RebaseHelperError('You have to specify one of these check tools {0}'.format(
Checker.get_supported_tools()))
raise RebaseHelperError('You have to specify one of these check tools %s', Checker.get_supported_tools())
else:
logger.info('Comparing packages using {0}...'.format(self.conf.pkgcomparetool))
logger.info('Comparing packages using %s...', self.conf.pkgcomparetool)
results_dict = pkgchecker.run_check(self.results_dir)
for key, val in six.iteritems(results_dict):
if val:
Expand Down Expand Up @@ -431,7 +426,7 @@ def run(self):
self._delete_workspace_dir()

if self.debug_log_file:
logger.info("Detailed debug log is located in '{0}'".format(self.debug_log_file))
logger.info("Detailed debug log is located in '%s'", self.debug_log_file)

if __name__ == '__main__':
a = Application(None)
Expand Down
3 changes: 1 addition & 2 deletions rebasehelper/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ def extract(self, path=None):
if path is None:
TypeError("Expected argument 'path' (pos 1) is missing")

logger.debug("Extracting '{0}' into '{1}'".format(
self._filename, path))
logger.debug("Extracting '%s' into '%s'", self._filename, path)

archive = self._archive_type.open(self._filename)
archive.extractall(path)
Expand Down
38 changes: 19 additions & 19 deletions rebasehelper/build_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ def __init__(self, sources, patches, spec, results_dir):

def __enter__(self):
obj = super(BuildTemporaryEnvironment, self).__enter__()
log_message = "Copying '{0}' to '{1}'"
log_message = "Copying '%s' to '%s'"
# create the directory structure
self._create_directory_sctructure()
# copy sources
for source in self.sources:
logger.debug(log_message.format(source, self._env[self.TEMPDIR_SOURCES]))
logger.debug(log_message, source, self._env[self.TEMPDIR_SOURCES])
shutil.copy(source, self._env[self.TEMPDIR_SOURCES])
# copy patches
for patch in self.patches:
logger.debug(log_message.format(patch, self._env[self.TEMPDIR_SOURCES]))
logger.debug(log_message, patch, self._env[self.TEMPDIR_SOURCES])
shutil.copy(patch, self._env[self.TEMPDIR_SOURCES])
# copy SPEC file
spec_name = os.path.basename(self.spec)
self._env[self.TEMPDIR_SPEC] = os.path.join(self._env[self.TEMPDIR_SPECS], spec_name)
shutil.copy(self.spec, self._env[self.TEMPDIR_SPEC])
logger.debug(log_message.format(self.spec, self._env[self.TEMPDIR_SPEC]))
logger.debug(log_message, self.spec, self._env[self.TEMPDIR_SPEC])

return obj

Expand All @@ -103,14 +103,14 @@ def _build_env_exit_callback(self, results_dir, **kwargs):
:return:
"""
os.makedirs(results_dir)
log_message = "Copying '{0}' '{1}' to '{2}'"
log_message = "Copying '%s' '%s' to '%s'"
# copy logs
for log in PathHelper.find_all_files(kwargs[self.TEMPDIR_RESULTS], '*.log'):
logger.debug(log_message.format('log', log, results_dir))
logger.debug(log_message, 'log', log, results_dir)
shutil.copy(log, results_dir)
# copy packages
for package in PathHelper.find_all_files(kwargs[self.TEMPDIR], '*.rpm'):
logger.debug(log_message.format('package', package, results_dir))
logger.debug(log_message, 'package', package, results_dir)
shutil.copy(package, results_dir)


Expand Down Expand Up @@ -163,7 +163,7 @@ def _create_directory_sctructure(self):
# create directory structure
for dir_name in ['SOURCES', 'SPECS', 'RESULTS']:
self._env[self.TEMPDIR + '_' + dir_name] = os.path.join(self._env[self.TEMPDIR], dir_name)
logger.debug("Creating '{0}'".format(self._env[self.TEMPDIR + '_' + dir_name]))
logger.debug("Creating '%s'", self._env[self.TEMPDIR + '_' + dir_name])
os.makedirs(self._env[self.TEMPDIR + '_' + dir_name])


Expand Down Expand Up @@ -248,10 +248,10 @@ def build(cls, spec, sources, patches, results_dir, root=None, arch=None, **kwar

# use the SRPM frpm results_dir
srpm = os.path.join(srpm_results_dir, os.path.basename(srpm))
logger.debug("Successfully built SRPM: '{0}'".format(str(srpm)))
logger.debug("Successfully built SRPM: '%s'", str(srpm))
# gather logs
logs = [l for l in PathHelper.find_all_files(srpm_results_dir, '*.log')]
logger.debug("logs: '{0}'".format(str(logs)))
logger.debug("logs: '%s'", str(logs))

# build RPM
rpm_results_dir = os.path.join(results_dir, "RPM")
Expand All @@ -271,11 +271,11 @@ def build(cls, spec, sources, patches, results_dir, root=None, arch=None, **kwar
logger.info("Building RPM finished successfully")

rpms = [os.path.join(rpm_results_dir, os.path.basename(f)) for f in rpms]
logger.debug("Successfully built RPMs: '{0}'".format(str(rpms)))
logger.debug("Successfully built RPMs: '%s'", str(rpms))

# gather logs
logs.extend([l for l in PathHelper.find_all_files(rpm_results_dir, '*.log')])
logger.debug("logs: '{0}'".format(str(logs)))
logger.debug("logs: '%s'", str(logs))

return {'srpm': srpm,
'rpm': rpms,
Expand Down Expand Up @@ -305,12 +305,12 @@ def _create_directory_sctructure(self):
# create rpmbuild directory structure
for dir_name in ['RESULTS', 'rpmbuild']:
self._env[self.TEMPDIR + '_' + dir_name.upper()] = os.path.join(self._env[self.TEMPDIR], dir_name)
logger.debug("Creating '{0}'".format(self._env[self.TEMPDIR + '_' + dir_name.upper()]))
logger.debug("Creating '%s'", self._env[self.TEMPDIR + '_' + dir_name.upper()])
os.makedirs(self._env[self.TEMPDIR + '_' + dir_name.upper()])
for dir_name in ['BUILD', 'BUILDROOT', 'RPMS', 'SOURCES', 'SPECS', 'SRPMS']:
self._env[self.TEMPDIR + '_' + dir_name] = os.path.join(self._env[self.TEMPDIR_RPMBUILD],
dir_name)
logger.debug("Creating '{0}'".format(self._env[self.TEMPDIR + '_' + dir_name]))
logger.debug("Creating '%s'", self._env[self.TEMPDIR + '_' + dir_name])
os.makedirs(self._env[self.TEMPDIR + '_' + dir_name])


Expand Down Expand Up @@ -407,10 +407,10 @@ def build(cls, spec, sources, patches, results_dir, **kwargs):

# srpm path in results_dir
srpm = os.path.join(srpm_results_dir, os.path.basename(srpm))
logger.debug("Successfully built SRPM: '{0}'".format(str(srpm)))
logger.debug("Successfully built SRPM: '%s'", str(srpm))
# gather logs
logs = [l for l in PathHelper.find_all_files(srpm_results_dir, '*.log')]
logger.debug("logs: '{0}'".format(str(logs)))
logger.debug("logs: '%s'", str(logs))

# build RPMs
rpm_results_dir = os.path.join(results_dir, "RPM")
Expand All @@ -427,11 +427,11 @@ def build(cls, spec, sources, patches, results_dir, **kwargs):

# RPMs paths in results_dir
rpms = [os.path.join(rpm_results_dir, os.path.basename(f)) for f in rpms]
logger.debug("Successfully built RPMs: '{0}'".format(str(rpms)))
logger.debug("Successfully built RPMs: '%s'", str(rpms))

# gather logs
logs.extend([l for l in PathHelper.find_all_files(rpm_results_dir, '*.log')])
logger.debug("logs: '{0}'".format(str(logs)))
logger.debug("logs: '%s'", str(logs))

return {'srpm': srpm,
'rpm': rpms,
Expand Down Expand Up @@ -461,7 +461,7 @@ def __str__(self):

def build(self, *args, **kwargs):
""" Build sources. """
logger.debug("Building sources using '{0}'".format(self._tool_name))
logger.debug("Building sources using '%s'", self._tool_name)
return self._tool.build(*args, **kwargs)

@classmethod
Expand Down
13 changes: 7 additions & 6 deletions rebasehelper/build_log_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _parse_build_log(cls, log_name):
with open(log_name, 'r') as f:
lines = f.read()
if not lines:
logger.debug('Problem with openning log {name}'.format(name=log_name))
logger.debug('Problem with openning log %s', log_name)
raise BuildLogAnalyzerMissingError

# Test for finding files which exists in sources
Expand All @@ -90,27 +90,28 @@ def _parse_build_log(cls, log_name):
section = cls._find_section(lines, missing_reg, e_reg)
if section:
section = section.replace('File not found by glob:', '').replace('File not found:', '')
logger.debug('Found missing files which are not in SPEC file: {files}'.format(files=section))
logger.debug('Found missing files which are not in SPEC file: %s', section)
files['missing'] = cls._get_files_from_string(section)
else:
section = cls._find_section(lines, missing_source_reg, e_reg)
if section:
if cls._find_make_error(lines):
raise BuildLogAnalyzerMakeError('Look at the build log {name}'.format(name=log_name))
raise BuildLogAnalyzerMakeError('Look at the build log %s', log_name)
else:
if cls._find_patch_error(lines):
raise BuildLogAnalyzerPatchError('Patching failed during building. Look at the build log {log}'.format(log=log_name))
raise BuildLogAnalyzerPatchError('Patching failed during building. '
'Look at the build log %s', log_name)
else:
files_from_section = cls._get_files_from_string(section)
if files_from_section:
logger.debug('Found files which does not exist in source: {files}'.format(files=section))
logger.debug('Found files which does not exist in source: %s', section)
files['deleted'] = files_from_section
else:
logger.info('Not known issue')
raise RuntimeError
else:
logger.info('We did not find a reason why build failed.')
logger.info('Look at the build log {log}'.format(log=log_name))
logger.info('Look at the build log %s', log_name)

return files

Expand Down
8 changes: 4 additions & 4 deletions rebasehelper/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _create_xml(cls, name, input_structure):
with open(file_name, 'w') as f:
f.writelines(lines)
except IOError:
raise RebaseHelperError("Unable to create XML file for pkgdiff tool '{0}'".format(file_name))
raise RebaseHelperError("Unable to create XML file for pkgdiff tool '%s'", file_name)

return file_name

Expand All @@ -206,7 +206,7 @@ def fill_dictionary(cls, result_dir):
for tag in settings.CHECKER_TAGS:
results_dict[tag] = []
for file_name in [os.path.join(result_dir, x) for x in XML_FILES]:
logger.info('Processing {0} file.'.format(file_name))
logger.info('Processing %s file.', file_name)
try:
with open(file_name, "r") as f:
lines = f.readlines()
Expand Down Expand Up @@ -302,7 +302,7 @@ def run_check(cls, results_dir):
other return codes means error
"""
if int(ret_code) != 0 and int(ret_code) != 1:
raise RebaseHelperError('Execution of {0} failed.\nCommand line is: {1}'.format(cls.CMD, cmd))
raise RebaseHelperError('Execution of %s failed.\nCommand line is: %s', cls.CMD, cmd)
OutputLogger.set_info_text('Result HTML page from pkgdiff is store in: ', cls.pkgdiff_results_full_path)
return cls.process_xml_results(cls.results_dir)

Expand Down Expand Up @@ -330,7 +330,7 @@ def __str__(self):

def run_check(self, results_dir):
""" Run the check """
logger.debug("Running tests on packages using '{0}'".format(self._tool_name))
logger.debug("Running tests on packages using '%s'", self._tool_name)
return self._tool.run_check(results_dir)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion rebasehelper/diff_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def diff(self, old, new):
"""
Diff between two files
"""
logger.debug("Diff between files {0} and {1}".format(old, new))
logger.debug("Diff between files %s and %s", old, new)
return self._tool.run_diff(old, new)

def merge(self, old_dir, new_dir, failed_files):
Expand Down

0 comments on commit 3aa0ffb

Please sign in to comment.