aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2012-12-23 21:18:28 -0500
committerAnthony G. Basile <blueness@gentoo.org>2012-12-23 21:18:28 -0500
commit94a5e3365b3d6f3658e090838004e9a3bf9ab148 (patch)
tree8c12812adc389cd4369d43c2e4daeaaf3342f082
parentmisc/link_maps{,_portage}: compare reading /var/db/pkg directly and via portage (diff)
downloadelfix-94a5e3365b3d6f3658e090838004e9a3bf9ab148.tar.gz
elfix-94a5e3365b3d6f3658e090838004e9a3bf9ab148.tar.bz2
elfix-94a5e3365b3d6f3658e090838004e9a3bf9ab148.zip
misc/alt-revdep-pax: read NEEDED.ELF.2 via portage
-rwxr-xr-xmisc/alt-revdep-pax67
1 files changed, 25 insertions, 42 deletions
diff --git a/misc/alt-revdep-pax b/misc/alt-revdep-pax
index f35a9ea..69086af 100755
--- a/misc/alt-revdep-pax
+++ b/misc/alt-revdep-pax
@@ -31,6 +31,7 @@ import os
import sys
import re
import pax
+import portage
""" python2/3 compat input """
@@ -51,32 +52,20 @@ Here the sonames were obtained from the ELF object by scanelf -nm
"""
def get_object_needed():
- """
- import portage
vardb = portage.db[portage.root]["vartree"].dbapi
- vardb.aux_get('sys-apps/coreutils-8.20', ['NEEDED.ELF.2'])
- vardb.cpv_all() # list of all packages
- """
-
- var_db_pkg = '/var/db/pkg'
object_needed = {}
- for cat in os.listdir(var_db_pkg):
- catdir = '%s/%s' % (var_db_pkg, cat)
- for pkg in os.listdir(catdir):
- pkgdir = '%s/%s' % (catdir, pkg)
- need = '%s/%s' % (pkgdir, 'NEEDED.ELF.2')
- try:
- g = open(need, 'r')
- needs = g.readlines()
- for line in needs:
- line = line.strip()
- link = re.split(';', line)
- elf = link[1]
- sonames = re.split(',', link[4])
- object_needed[elf] = sonames
- except IOError:
- continue #File probably doesn't exist, which is okay
+
+ for pkg in vardb.cpv_all():
+ needs = vardb.aux_get(pkg, ['NEEDED.ELF.2'])[0].strip()
+ if not needs: #skip empty lines
+ continue
+ lines = re.split('\n', needs)
+ for line in lines:
+ link = re.split(';', line)
+ elf = link[1]
+ sonames = re.split(',', link[4])
+ object_needed[elf] = sonames
return object_needed
@@ -92,29 +81,23 @@ and its inverse which has structure
"""
def get_libraries():
- var_db_pkg = '/var/db/pkg'
+ vardb = portage.db[portage.root]["vartree"].dbapi
library2soname = {}
soname2library = {}
- for cat in os.listdir(var_db_pkg):
- catdir = '%s/%s' % (var_db_pkg, cat)
- for pkg in os.listdir(catdir):
- pkgdir = '%s/%s' % (catdir, pkg)
- need = '%s/%s' % (pkgdir, 'NEEDED.ELF.2')
- try:
- g = open(need, 'r')
- needs = g.readlines()
- for line in needs:
- line = line.strip()
- link = re.split(';', line)
- elf = link[1]
- soname = link[2]
- if soname: #no soname => executable
- library2soname[elf] = soname
- soname2library[soname] = elf
- except IOError:
- continue #File probably doesn't exist, which is okay
+ for pkg in vardb.cpv_all():
+ needs = vardb.aux_get(pkg, ['NEEDED.ELF.2'])[0].strip()
+ if not needs: #skip empty lines
+ continue
+ lines = re.split('\n', needs)
+ for line in lines:
+ link = re.split(';', line)
+ elf = link[1]
+ soname = link[2]
+ if soname: #no soname => executable
+ library2soname[elf] = soname
+ soname2library[soname] = elf
return ( library2soname, soname2library )