Convert depfixer.Elf class into a context manager.

This allows for automatic closing of its internal file handle.
pull/716/head
Elliott Sales de Andrade 8 years ago
parent 4c71695e41
commit fe0aa7daff
  1. 12
      mesonbuild/scripts/depfixer.py

@ -115,11 +115,21 @@ class Elf(DataSizes):
self.bfile = bfile
self.verbose = verbose
self.bf = open(bfile, 'r+b')
try:
(self.ptrsize, self.is_le) = self.detect_elf_type()
super().__init__(self.ptrsize, self.is_le)
self.parse_header()
self.parse_sections()
self.parse_dynamic()
except:
self.bf.close()
raise
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.bf.close()
def detect_elf_type(self):
data = self.bf.read(6)
@ -308,7 +318,7 @@ def run(args):
print('Don\'t run this unless you know what you are doing.')
print('%s: <binary file> <prefix>' % sys.argv[0])
exit(1)
e = Elf(args[0])
with Elf(args[0]) as e:
if len(args) == 1:
e.print_rpath()
e.print_runpath()

Loading…
Cancel
Save