mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 10:10:46 +00:00
daq: Fix teardown() removing temporary files
The teardown() method was introduced in bb1552151a32 ("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:
parent
4df2b9a4c4
commit
182f4e7b3f
@ -52,6 +52,7 @@ class DaqInstrument(Instrument):
|
|||||||
self.keep_raw = keep_raw
|
self.keep_raw = keep_raw
|
||||||
self._need_reset = True
|
self._need_reset = True
|
||||||
self._raw_files = []
|
self._raw_files = []
|
||||||
|
self.tempdir = None
|
||||||
if DaqClient is None:
|
if DaqClient is None:
|
||||||
raise HostError('Could not import "daqpower": {}'.format(import_error_mesg))
|
raise HostError('Could not import "daqpower": {}'.format(import_error_mesg))
|
||||||
if labels is None:
|
if labels is None:
|
||||||
@ -97,12 +98,12 @@ class DaqInstrument(Instrument):
|
|||||||
self._need_reset = True
|
self._need_reset = True
|
||||||
|
|
||||||
def get_data(self, outfile): # pylint: disable=R0914
|
def get_data(self, outfile): # pylint: disable=R0914
|
||||||
tempdir = tempfile.mkdtemp(prefix='daq-raw-')
|
self.tempdir = tempfile.mkdtemp(prefix='daq-raw-')
|
||||||
self.daq_client.get_data(tempdir)
|
self.daq_client.get_data(self.tempdir)
|
||||||
raw_file_map = {}
|
raw_file_map = {}
|
||||||
for entry in os.listdir(tempdir):
|
for entry in os.listdir(self.tempdir):
|
||||||
site = os.path.splitext(entry)[0]
|
site = os.path.splitext(entry)[0]
|
||||||
path = os.path.join(tempdir, entry)
|
path = os.path.join(self.tempdir, entry)
|
||||||
raw_file_map[site] = path
|
raw_file_map[site] = path
|
||||||
self._raw_files.append(path)
|
self._raw_files.append(path)
|
||||||
|
|
||||||
@ -118,7 +119,7 @@ class DaqInstrument(Instrument):
|
|||||||
file_handles.append(fh)
|
file_handles.append(fh)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
message = 'Could not get DAQ trace for {}; Obtained traces are in {}'
|
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
|
# The first row is the headers
|
||||||
channel_order = []
|
channel_order = []
|
||||||
@ -155,5 +156,5 @@ class DaqInstrument(Instrument):
|
|||||||
def teardown(self):
|
def teardown(self):
|
||||||
self.daq_client.close()
|
self.daq_client.close()
|
||||||
if not self.keep_raw:
|
if not self.keep_raw:
|
||||||
if os.path.isdir(tempdir):
|
if os.path.isdir(self.tempdir):
|
||||||
shutil.rmtree(tempdir)
|
shutil.rmtree(self.tempdir)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user