#!/usr/bin/env python3 # Copyright (C) 2018 Denis 'GNUtoo' Carikli # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # import os import re import subprocess results = {} is_not_found_re = re.compile('found') is_local_re = re.compile('^/usr/local') """ @returns [library array] or None """ def ldd_get_not_found(path): libraries = [] ldd = subprocess.Popen(["sh", "-c", "ldd {0}".format(path)], stdout=subprocess.PIPE, stderr=None) output = str(ldd.communicate()[0]) for line in output.replace('\\t','').split('\\n'): if not re.search(is_not_found_re, line): continue library = line.split(' => ')[0] libraries.append(library) if len(libraries) > 0: return libraries else: return None """ @returns [package name] [package version] or None """ def pacman_get_package(path): pacman = subprocess.Popen(["pacman", "-Q", "-o", path], stdout=subprocess.PIPE, stderr=None) output = str(pacman.communicate()[0]) package = output.split('is owned by ')[1].replace("\\n'", '').split(" ") if len(package) > 0: return package else: return None def main(): affected_files = open('affected-files.txt') for path in affected_files: path=path.replace('\n','') if re.match(is_local_re, path): continue not_found_libs = ldd_get_not_found(path) if not_found_libs == None: continue package = pacman_get_package(path) if package == None: continue package_name = package[0] package_version = package[1] if package_name not in results.keys(): results[package_name] = {'version': package_version, 'files' : {}} results[package_name]['files'][path] = not_found_libs for package_name in results.keys(): print ("{0} ({1}):".format(package_name, results[package_name]['version'])) for path in results[package_name]['files'].keys(): libs_line = "" libs_line += "\t{0}:".format(path) for lib in results[package_name]['files'][path]: libs_line +=" {0}".format(lib) print(libs_line) if __name__ == '__main__': main()