1
0
mirror of https://github.com/ARM-software/devlib.git synced 2024-10-06 02:40:50 +01:00

daq: Fix teardown() removing temporary files

The teardown() method was introduced in bb1552151a ("instruments:
Add teardown method to clean up tempfiles") but it uses an undeclared
variable tempdir. Make tempdir an object variable so that it can be
used in teardown().
This commit is contained in:
Javi Merino 2019-11-26 15:39:10 +00:00 committed by Marc Bonnici
parent 4df2b9a4c4
commit 182f4e7b3f

View File

@ -52,6 +52,7 @@ class DaqInstrument(Instrument):
self.keep_raw = keep_raw
self._need_reset = True
self._raw_files = []
self.tempdir = None
if DaqClient is None:
raise HostError('Could not import "daqpower": {}'.format(import_error_mesg))
if labels is None:
@ -97,12 +98,12 @@ class DaqInstrument(Instrument):
self._need_reset = True
def get_data(self, outfile): # pylint: disable=R0914
tempdir = tempfile.mkdtemp(prefix='daq-raw-')
self.daq_client.get_data(tempdir)
self.tempdir = tempfile.mkdtemp(prefix='daq-raw-')
self.daq_client.get_data(self.tempdir)
raw_file_map = {}
for entry in os.listdir(tempdir):
for entry in os.listdir(self.tempdir):
site = os.path.splitext(entry)[0]
path = os.path.join(tempdir, entry)
path = os.path.join(self.tempdir, entry)
raw_file_map[site] = path
self._raw_files.append(path)
@ -118,7 +119,7 @@ class DaqInstrument(Instrument):
file_handles.append(fh)
except KeyError:
message = 'Could not get DAQ trace for {}; Obtained traces are in {}'
raise HostError(message.format(site, tempdir))
raise HostError(message.format(site, self.tempdir))
# The first row is the headers
channel_order = []
@ -155,5 +156,5 @@ class DaqInstrument(Instrument):
def teardown(self):
self.daq_client.close()
if not self.keep_raw:
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
if os.path.isdir(self.tempdir):
shutil.rmtree(self.tempdir)