async def get_present_libraries(self, target: BuildTarget) -> List[str]: present_libraries = [] for file in target.all_dependency_files: if file.endswith('.so') or '.so.' in file: if Library.find_library_in_list(file, self.libraries): present_libraries.append(file) return present_libraries
def run_commands(self, commands_file: str, abs_paths_root: str, logger, exact_versions: bool) -> (str, int): """ :return the name of created file (target) """ cur_dir = os.getcwd() res = [] try: logger.debug("HERE") os.chdir(self.root_dir) # Considering that all the paths were substitute for the absolute ones lines = [ re.sub(r'\s/', f' {abs_paths_root}', line) for line in open(commands_file).readlines() ] logger.debug("Lines Before: " + '\n'.join(lines)) for i in range(len(lines)): for library in re.findall(r'\${(.*?)}', lines[i]): lines[i] = re.sub( r'\${' + library + '}', Library.find_library_in_list(library, self.present_libraries, exact_versions).abs_path, lines[i]) logger.debug("Lines After: " + '\n'.join(lines)) for command in lines: r = sp.Popen(command, shell=True, stdout=sp.PIPE, stderr=sp.PIPE) out, err = r.communicate() output = f"Command: {command}" + f"\nSTDOUT: {out.decode('utf-8')}\n" + \ f"STDERR: {err.decode('utf-8')}" print(output) res.append(output) if r.returncode != 0: return '\n'.join(res), r.returncode except Exception as e: logger.debug(e) return '\n'.join(res), -1 finally: os.chdir(cur_dir) return '\n'.join(res), 0