Created
September 21, 2016 21:28
-
-
Save kkirsche/e900cdfcb79b2ab977c163c3d1ee42a2 to your computer and use it in GitHub Desktop.
Find installed binary and configuration files on CentOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| import os | |
| import re | |
| import subprocess | |
| import yum | |
| yb = yum.YumBase() | |
| yb.setCacheDir() | |
| dependency_installed = yb.rpmdb.searchNevra(name='yum-utils') | |
| if not dependency_installed: | |
| logging.error("This tool requires that yum-utils is installed. Please " | |
| "install yum-utils with `yum install -y yum-utils` and " | |
| "try again.") | |
| os.exit(1) | |
| else: | |
| logging.debug("yum-utils is installed. Continuing") | |
| pkgs = yb.rpmdb.returnPackages() | |
| for pkg in pkgs: | |
| logging.debug("Processing package {}".format(pkg.name)) | |
| proc = subprocess.Popen('repoquery --list {}'.format(pkg.name), | |
| shell=True, | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.STDOUT) | |
| for line in iter(proc.stdout.readline, ''): | |
| pattern = r"^.*(\/bin\/|\/sbin\/|\/etc\/).*" | |
| cpattern = re.compile(pattern) | |
| if not cpattern.match(line): | |
| continue | |
| print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment