Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _parse_build_log(cls, log_name):
"""
Function analyzes log files in our case build.log
:param log_name:
:return: list of files which are either missing or not exists
"""
files = {}
with open(log_name, 'r') as f:
lines = f.read()
if not lines:
logger.debug('Problem with openning log %s', log_name)
raise BuildLogAnalyzerMissingError
# Test for finding files which exists in sources
# but are not mentioned in spec file
missing_re = r'error:\s+Installed\s+'
missing_source_re = r'RPM build errors:'
e_reg = 'EXCEPTION:'
if cls._find_patch_error(lines):
raise BuildLogAnalyzerPatchError('Patching failed during building. '
'Look at the build log %s', log_name)
section = cls._find_section(lines, missing_re, 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: %s', section)
files['missing'] = cls._get_files_from_string(section)
else:
"""Runs setup script with given list of arguments and writes script
output to the given file"""
functions = {self.SETUP_TYPE_CONFIGURE: self._run_setup_configure,
self.SETUP_TYPE_CMAKE: self._run_setup_cmake}
if not self._setup_script_path or not self._setup_script_type:
self._setup_script_path, self._setup_script_type = self._find_setup()
if self._setup_script_path and self._setup_script_type:
ret = functions[self._setup_script_type](args, output)
if ret == 0:
self._setup_done = True
return True
else:
logger.debug("Sources: Setup script failed")
return False
else:
logger.debug("Sources: Could not find setup script")
return False
if self._pre_make_check() is False:
return False
if self._build_done is False:
logger.debug("Sources: Sources need to be built before intsall")
return False
cmd = ["make"]
if path is not None:
cmd.append("DESTDIR=" + path)
cmd = cmd + args + ["install"]
ret = ProcessHelper.run_subprocess_cwd(cmd,
self._makefile_path,
output)
if ret == 0:
return True
else:
logger.debug("Sources: 'make install' failed")
return False
def clean(self):
"""Runs make clean"""
if self._pre_make_check() is False:
return False
cmd = ["make", "clean"]
ret = ProcessHelper.run_subprocess_cwd(cmd,
self._makefile_path,
ProcessHelper.DEV_NULL)
if ret == 0:
self._build_done = False
return True
else:
logger.debug("Sources: 'make clean' failed")
return False
def _find_setup(self):
functions = [(
self.SETUP_TYPE_CONFIGURE, self._find_setup_path_configure),
(self.SETUP_TYPE_CMAKE, self._find_setup_path_cmake)]
for setup_type, find_setup_path in functions:
setup_path = find_setup_path()
if setup_path is not None:
logger.debug("Sources: Found {0} script in {1}".format(
setup_type, setup_path))
return setup_path, setup_type
return None, None
def _pre_make_check(self):
if self._setup_done is False:
logger.debug(
"Sources: Setup script needs to be executed before make")
return False
if self._makefile_path is None:
self._makefile_path = self._find_makefile()
if self._makefile_path is None:
logger.debug("Sources: Could not find Makefile")
return False
return True
def install(self, path=None, args=[], output=None):
"""Runs make install with DESTDIR='path' and writes output to the given
file"""
if self._pre_make_check() is False:
return False
if self._build_done is False:
logger.debug("Sources: Sources need to be built before intsall")
return False
cmd = ["make"]
if path is not None:
cmd.append("DESTDIR=" + path)
cmd = cmd + args + ["install"]
ret = ProcessHelper.run_subprocess_cwd(cmd,
self._makefile_path,
output)
if ret == 0:
return True
else:
logger.debug("Sources: 'make install' failed")
return False
def __enter__(self):
obj = super(BuildTemporaryEnvironment, self).__enter__()
log_message = "Copying '%s' to '%s'"
# create the directory structure
self._create_directory_structure()
# copy sources
for source in self.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, 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, self.spec, self._env[self.TEMPDIR_SPEC])
return obj
def _find_makefile(self):
logger.debug(
"Sources: Looking for Makefile in {0}".format(self.get_path()))
return PathHelper.find_first_dir_with_file(self.get_path(), "Makefile")