1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

instruments: Add keep_raw parameter to control teardown deletion

Add a `keep_raw` parameter that prevents raw files from being deleted
during teardown in case they are still required.
This commit is contained in:
Marc Bonnici 2019-10-03 11:21:03 +01:00 committed by setrofim
parent bb1552151a
commit 0d6c6883dd
4 changed files with 21 additions and 10 deletions

View File

@ -58,12 +58,14 @@ class AcmeCapeInstrument(Instrument):
iio_capture=which('iio-capture'), iio_capture=which('iio-capture'),
host='baylibre-acme.local', host='baylibre-acme.local',
iio_device='iio:device0', iio_device='iio:device0',
buffer_size=256): buffer_size=256,
keep_raw=False):
super(AcmeCapeInstrument, self).__init__(target) super(AcmeCapeInstrument, self).__init__(target)
self.iio_capture = iio_capture self.iio_capture = iio_capture
self.host = host self.host = host
self.iio_device = iio_device self.iio_device = iio_device
self.buffer_size = buffer_size self.buffer_size = buffer_size
self.keep_raw = keep_raw
self.sample_rate_hz = 100 self.sample_rate_hz = 100
if self.iio_capture is None: if self.iio_capture is None:
raise HostError('Missing iio-capture binary') raise HostError('Missing iio-capture binary')
@ -161,5 +163,6 @@ class AcmeCapeInstrument(Instrument):
return [self.raw_data_file] return [self.raw_data_file]
def teardown(self): def teardown(self):
if os.path.isfile(self.raw_data_file): if not self.keep_raw:
os.remove(self.raw_data_file) if os.path.isfile(self.raw_data_file):
os.remove(self.raw_data_file)

View File

@ -71,7 +71,7 @@ class ArmEnergyProbeInstrument(Instrument):
MAX_CHANNELS = 12 # 4 Arm Energy Probes MAX_CHANNELS = 12 # 4 Arm Energy Probes
def __init__(self, target, config_file='./config-aep', ): def __init__(self, target, config_file='./config-aep', keep_raw=False):
super(ArmEnergyProbeInstrument, self).__init__(target) super(ArmEnergyProbeInstrument, self).__init__(target)
self.arm_probe = which('arm-probe') self.arm_probe = which('arm-probe')
if self.arm_probe is None: if self.arm_probe is None:
@ -80,6 +80,7 @@ class ArmEnergyProbeInstrument(Instrument):
self.attributes = ['power', 'voltage', 'current'] self.attributes = ['power', 'voltage', 'current']
self.sample_rate_hz = 10000 self.sample_rate_hz = 10000
self.config_file = config_file self.config_file = config_file
self.keep_raw = keep_raw
self.parser = AepParser() self.parser = AepParser()
#TODO make it generic #TODO make it generic
@ -144,5 +145,6 @@ class ArmEnergyProbeInstrument(Instrument):
return [self.output_file_raw] return [self.output_file_raw]
def teardown(self): def teardown(self):
if os.path.isfile(self.output_file_raw): if not self.keep_raw:
os.remove(self.output_file_raw) if os.path.isfile(self.output_file_raw):
os.remove(self.output_file_raw)

View File

@ -45,9 +45,11 @@ class DaqInstrument(Instrument):
dv_range=0.2, dv_range=0.2,
sample_rate_hz=10000, sample_rate_hz=10000,
channel_map=(0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23), channel_map=(0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23),
keep_raw=False
): ):
# pylint: disable=no-member # pylint: disable=no-member
super(DaqInstrument, self).__init__(target) super(DaqInstrument, self).__init__(target)
self.keep_raw = keep_raw
self._need_reset = True self._need_reset = True
self._raw_files = [] self._raw_files = []
if execute_command is None: if execute_command is None:
@ -155,8 +157,9 @@ class DaqInstrument(Instrument):
def teardown(self): def teardown(self):
self.execute('close') self.execute('close')
if os.path.isdir(tempdir): if not self.keep_raw:
shutil.rmtree(tempdir) if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
def execute(self, command, **kwargs): def execute(self, command, **kwargs):
return execute_command(self.server_config, command, **kwargs) return execute_command(self.server_config, command, **kwargs)

View File

@ -34,9 +34,11 @@ class EnergyProbeInstrument(Instrument):
def __init__(self, target, resistor_values, def __init__(self, target, resistor_values,
labels=None, labels=None,
device_entry='/dev/ttyACM0', device_entry='/dev/ttyACM0',
keep_raw=False
): ):
super(EnergyProbeInstrument, self).__init__(target) super(EnergyProbeInstrument, self).__init__(target)
self.resistor_values = resistor_values self.resistor_values = resistor_values
self.keep_raw = keep_raw
if labels is not None: if labels is not None:
self.labels = labels self.labels = labels
else: else:
@ -128,5 +130,6 @@ class EnergyProbeInstrument(Instrument):
return [self.raw_data_file] return [self.raw_data_file]
def teardown(self): def teardown(self):
if os.path.isfile(self.raw_data_file): if self.keep_raw:
os.remove(self.raw_data_file) if os.path.isfile(self.raw_data_file):
os.remove(self.raw_data_file)