commit:     b196a92359419799bd414be7f5643fd5b8545e37
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Wed May 28 16:32:49 2014 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed May 28 16:32:49 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=b196a923

misc/ldd: refactor all_dt_needed_paths for recursion

---
 misc/ldd/ldd.py | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/misc/ldd/ldd.py b/misc/ldd/ldd.py
index 5a15786..1819607 100755
--- a/misc/ldd/ldd.py
+++ b/misc/ldd/ldd.py
@@ -96,6 +96,22 @@ def dynamic_dt_needed_paths( dt_needed, eclass, paths):
 
     return dt_needed_paths
 
+
+def all_dt_needed_paths(f, paths):
+    with open(f, 'rb') as file:
+        try:
+            readelf = ReadElf(file)
+            eclass = readelf.elf_class()
+            # This needs to be iterated until we traverse the entire linkage 
tree
+            dt_needed = readelf.dynamic_dt_needed()
+            dt_needed_paths = dynamic_dt_needed_paths( dt_needed, eclass, 
paths)
+            for n, lib in dt_needed_paths.items():
+                sys.stdout.write('\t%s => %s\n' % (n, lib))
+        except ELFError as ex:
+            sys.stderr.write('ELF error: %s\n' % ex)
+            sys.exit(1)
+
+
 SCRIPT_DESCRIPTION = 'Print shared library dependencies'
 VERSION_STRING = '%%prog: based on pyelftools %s' % __version__
 
@@ -118,20 +134,9 @@ def main():
     paths = ldpaths()
 
     for f in args:
-        with open(f, 'rb') as file:
-            try:
-                readelf = ReadElf(file)
-                if len(args) > 1:
-                    sys.stdout.write('%s : \n' % f)
-                eclass = readelf.elf_class()
-                # This needs to be iterated until we traverse the entire 
linkage tree
-                dt_needed = readelf.dynamic_dt_needed()
-                dt_needed_paths = dynamic_dt_needed_paths( dt_needed, eclass, 
paths)
-                for n, lib in dt_needed_paths.items():
-                    sys.stdout.write('\t%s => %s\n' % (n, lib))
-            except ELFError as ex:
-                sys.stderr.write('ELF error: %s\n' % ex)
-                sys.exit(1)
+        if len(args) > 1:
+            sys.stdout.write('%s : \n' % f)
+        all_dt_needed_paths(f, paths)
 
 if __name__ == '__main__':
     main()

Reply via email to