I have the following code which gets all RPM packages and then extracts all files within these RPM packages.
However this does not list .py files which are symlinks,
How can I include symlink files in my search ? Can I update rpm command or is there an alternative ?
def run_command( self, command ):
result = subprocess.run( command, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True, check=True )
if result.returncode != 0:
raise subprocess.CalledProcessError( result.returncode, command,
result.stderr )
return result.stdout
def getRPMFiles( self ):
rpmFiles = []
# Get a list of all installed RPM packages
rpmPackagesList = self.run_command( "rpm -qa" ).splitlines()
allFiles = {}
for package in rpmPackagesList:
filesList = self.run_command( f"rpm -ql { package }" ).splitlines()
allFiles[ package ] = filesList
# Iteration logic to add items to rpmFiles variable
return rpmFiles
The code is correct. If the symlink is created in a scriptlet, then it is not owned by the package, and there is no way to get this info from rpmdb.
By the way - you can query the rpm using the Python library. See https://www.redhat.com/sysadmin/query-rpm-database-python