Manually convert most remaining format statements

%d accepts floats and other things, so manual fixes are needed after
conversion.

After flynt -ll 2000 --aggressive, each was manually checked if the
casts with int() are needed.

Two statements are still missing in ls370res

Change-Id: I2651ddbe60695aa19582882a97d0f71bcb05c1ef
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30901
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
This commit is contained in:
Alexander Zaft
2023-04-14 09:43:08 +02:00
parent 32b6d6ffc2
commit 0bf4b6cdf2
15 changed files with 58 additions and 64 deletions

View File

@@ -96,4 +96,4 @@ class HeLevel(HasIO, Readable):
return self.query('hf')
def write_sample_rate(self, value):
return self.query('hf=%d' % value)
return self.query(f'hf={int(value)}')

View File

@@ -64,7 +64,7 @@ class Switcher(HasIO, ChannelSwitcher):
# disable unused channels
for ch in range(1, 16):
if ch not in self._channels:
self.communicate('INSET %d,0,0,0,0,0;INSET?%d' % (ch, ch))
self.communicate(f'INSET {ch},0,0,0,0,0;INSET?{ch}')
channelno, autoscan = literal_eval(self.communicate('SCAN?'))
if channelno in self._channels and self._channels[channelno].enabled:
if not autoscan:
@@ -74,7 +74,7 @@ class Switcher(HasIO, ChannelSwitcher):
if channelno is None:
self.status = 'ERROR', 'no enabled channel'
return
self.communicate('SCAN %d,0;SCAN?' % channelno)
self.communicate(f'SCAN {channelno},0;SCAN?')
def doPoll(self):
"""poll buttons
@@ -87,7 +87,7 @@ class Switcher(HasIO, ChannelSwitcher):
if autoscan:
# pressed autoscan button: switch off HW autoscan and toggle soft autoscan
self.autoscan = not self.autoscan
self.communicate('SCAN %d,0;SCAN?' % self.value)
self.communicate(f'SCAN {self.value},0;SCAN?')
if channelno != self.value:
# channel changed by keyboard, do not yet return new channel
self.write_target(channelno)
@@ -135,7 +135,7 @@ class Switcher(HasIO, ChannelSwitcher):
self.measure_delay = chan.dwell
def set_active_channel(self, chan):
self.communicate('SCAN %d,0;SCAN?' % chan.channel)
self.communicate(f'SCAN {chan.channel},0;SCAN?')
chan._last_range_change = time.monotonic()
self.set_delays(chan)
@@ -187,7 +187,7 @@ class ResChannel(Channel):
return [self.Status.DISABLED, 'disabled']
if not self.channel == self.switcher.value == self.switcher.target:
return Done
result = int(self.communicate('RDGST?%d' % self.channel))
result = int(self.communicate(f'RDGST?{self.channel}'))
result &= 0x37 # mask T_OVER and T_UNDER (change this when implementing temperatures instead of resistivities)
statustext = ' '.join(formatStatusBits(result, STATUS_BIT_LABELS))
if statustext:
@@ -199,7 +199,7 @@ class ResChannel(Channel):
now = time.monotonic()
if now + 0.5 < max(self._last_range_change, self.switcher._start_switch) + self.pause:
return None
result = self.communicate('RDGR?%d' % self.channel)
result = self.communicate(f'RDGR?{self.channel}')
result = float(result)
if self.autorange:
self.fix_autorange()
@@ -236,7 +236,7 @@ class ResChannel(Channel):
@CommonReadHandler(rdgrng_params)
def read_rdgrng(self):
iscur, exc, rng, autorange, excoff = literal_eval(
self.communicate('RDGRNG?%d' % self.channel))
self.communicate(f'RDGRNG?{self.channel}'))
self._prev_rdgrng = iscur, exc
if autorange: # pressed autorange button
if not self._toggle_autorange:
@@ -283,7 +283,7 @@ class ResChannel(Channel):
def read_inset(self):
# ignore curve no and temperature coefficient
enabled, dwell, pause, _, _ = literal_eval(
self.communicate('INSET?%d' % self.channel))
self.communicate(f'INSET?{self.channel}'))
self.enabled = enabled
self.dwell = dwell
self.pause = pause
@@ -291,7 +291,7 @@ class ResChannel(Channel):
@CommonWriteHandler(inset_params)
def write_inset(self, change):
_, _, _, curve, tempco = literal_eval(
self.communicate('INSET?%d' % self.channel))
self.communicate(f'INSET?{self.channel}'))
self.enabled, self.dwell, self.pause, _, _ = literal_eval(
self.communicate('INSET %d,%d,%d,%d,%d,%d;INSET?%d' % (
self.channel, change['enabled'], change['dwell'], change['pause'], curve, tempco,
@@ -303,14 +303,14 @@ class ResChannel(Channel):
self.switcher.set_delays(self)
def read_filter(self):
on, settle, _ = literal_eval(self.communicate('FILTER?%d' % self.channel))
on, settle, _ = literal_eval(self.communicate(f'FILTER?{self.channel}'))
return settle if on else 0
def write_filter(self, value):
on = 1 if value else 0
value = max(1, value)
on, settle, _ = literal_eval(self.communicate(
'FILTER %d,%d,%g,80;FILTER?%d' % (self.channel, on, value, self.channel)))
f'FILTER {self.channel},{on},{value:g},80;FILTER?{self.channel}'))
if not on:
settle = 0
return settle

View File

@@ -94,7 +94,7 @@ class Main(Communicator):
if channel.enabled:
mask |= 1 << self._channel_to_index.get(channelname, 0)
# send, read and convert to floats and ints
data = self.communicate('GETDAT? %d' % mask)
data = self.communicate(f'GETDAT? {mask}')
reply = data.split(',')
mask = int(reply.pop(0))
reply.pop(0) # pop timestamp
@@ -204,7 +204,7 @@ class DriverChannel(Channel):
@CommonReadHandler(param_names)
def read_params(self):
no, self.current, self.powerlimit = literal_eval(
self.communicate('DRVOUT? %d' % self.no))
self.communicate(f'DRVOUT? {self.no}'))
if self.no != no:
raise HardwareError('DRVOUT command: channel number in reply does not match')
@@ -215,7 +215,7 @@ class DriverChannel(Channel):
:param values: a dict like object containing the parameters to be written
"""
self.read_params() # make sure parameters are up to date
self.comm_write('DRVOUT %(no)d,%(current)g,%(powerlimit)g' % values)
self.comm_write(f"DRVOUT {values['no']},{values['current']:g},{values['powerlimit']:g}")
self.read_params() # read back
@@ -238,7 +238,7 @@ class BridgeChannel(Channel):
@CommonReadHandler(param_names)
def read_params(self):
no, excitation, powerlimit, self.dcflag, self.readingmode, voltagelimit = literal_eval(
self.communicate('BRIDGE? %d' % self.no))
self.communicate(f'BRIDGE? {self.no}'))
if self.no != no:
raise HardwareError('DRVOUT command: channel number in reply does not match')
self.enabled = excitation != 0 and powerlimit != 0 and voltagelimit != 0
@@ -260,8 +260,9 @@ class BridgeChannel(Channel):
values['excitation'] = 0
values['powerlimit'] = 0
values['voltagelimit'] = 0
self.comm_write('BRIDGE %(no)d,%(enabled)g,%(powerlimit)g,%(dcflag)d,'
'%(readingmode)d,%(voltagelimit)g' % values)
self.comm_write(f"BRIDGE {values['no']},{values['enabled']:g},' \
f'{values['powerlimit']:g},{int(values['dcflag'])},{int(values['readingmode'])},' \
f'{values['voltagelimit']:g}")
self.read_params() # read back
@@ -322,7 +323,7 @@ class Chamber(PpmsDrivable):
self.status = self.status_map[status_code]
else:
self.value = self.value_map['unknown']
self.status = (StatusType.ERROR, 'unknown status code %d' % status_code)
self.status = (StatusType.ERROR, f'unknown status code {status_code}')
def read_target(self):
opcode = int(self.communicate('CHAMBER?'))
@@ -332,7 +333,7 @@ class Chamber(PpmsDrivable):
if value == self.target.noop:
return self.target.noop
opcode = self.name2opcode[self.target.enum(value).name]
assert self.communicate('CHAMBER %d' % opcode) == 'OK'
assert self.communicate(f'CHAMBER {opcode}') == 'OK'
return self.read_target()
@@ -408,7 +409,7 @@ class Temp(PpmsDrivable):
self.calc_expected(setpoint, ramp)
self.log.debug(
'change_temp v %r s %r r %r w %r l %r', self.value, setpoint, ramp, wait_at10, ramp_at_limit)
self.comm_write('TEMP %g,%g,%d' % (setpoint, ramp, approachmode))
self.comm_write(f'TEMP {setpoint:g},{ramp:g},{int(approachmode)}')
self.read_params()
def update_value_status(self, value, packed_status):
@@ -417,7 +418,7 @@ class Temp(PpmsDrivable):
return
self.value = value
status_code = packed_status & 0xf
status = self.STATUS_MAP.get(status_code, (StatusType.ERROR, 'unknown status code %d' % status_code))
status = self.STATUS_MAP.get(status_code, (StatusType.ERROR, f'unknown status code {status_code}'))
now = time.time()
if value > 11:
# when starting from T > 50, this will be 15 min.
@@ -542,8 +543,7 @@ class Field(PpmsDrivable):
self.ramp = ramp * 6e-3
def _write_params(self, target, ramp, approachmode, persistentmode):
self.comm_write('FIELD %g,%g,%d,%d' % (
target * 1e+4, ramp / 6e-3, approachmode, persistentmode))
self.comm_write(f'FIELD {target * 10000.0:g},{ramp / 0.006:g},{int(approachmode)},{int(persistentmode)}')
self.read_params()
def update_value_status(self, value, packed_status):
@@ -552,7 +552,7 @@ class Field(PpmsDrivable):
return
self.value = round(value * 1e-4, 7)
status_code = (packed_status >> 4) & 0xf
status = self.STATUS_MAP.get(status_code, (StatusType.ERROR, 'unknown status code %d' % status_code))
status = self.STATUS_MAP.get(status_code, (StatusType.ERROR, f'unknown status code {status_code}'))
now = time.time()
if self._last_change: # there was a change, which is not yet confirmed by hw
if status_code == 1: # persistent mode
@@ -661,7 +661,7 @@ class Position(PpmsDrivable):
def _write_params(self, target, speed):
speed = int(round(min(14, max(0, 15 - speed / 0.8)), 0))
self.comm_write('MOVE %g,%d,%d' % (target, 0, speed))
self.comm_write(f'MOVE {target:g},{0},{speed}')
return self.read_params()
def update_value_status(self, value, packed_status):
@@ -673,7 +673,7 @@ class Position(PpmsDrivable):
return
self.value = value
status_code = (packed_status >> 12) & 0xf
status = self.STATUS_MAP.get(status_code, (StatusType.ERROR, 'unknown status code %d' % status_code))
status = self.STATUS_MAP.get(status_code, (StatusType.ERROR, f'unknown status code {status_code}'))
if self._last_change: # there was a change, which is not yet confirmed by hw
now = time.time()
if now > self._last_change + 5:

View File

@@ -198,7 +198,7 @@ class PpmsSim:
def getdat(self, mask):
mask = int(mask) & 0x8000ff # all channels up to i2 plus ts
output = ['%d' % mask, f'{time.time() - self.start:.2f}']
output = [f'{mask}', f'{time.time() - self.start:.2f}']
for i, chan in self.CHANNELS.items():
if (1 << i) & mask:
output.append(f"{getattr(self, chan):.7g}")

View File

@@ -128,7 +128,7 @@ class Motor(PersistentMixin, HasIO, Drivable):
power_down_delay = writable('', FloatRange(0, 60., unit='sec', fmtstr='%.2f'),
default=0.1, group='motorparam')
baudrate = Parameter('', EnumType({'%d' % v: i for i, v in enumerate(BAUDRATES)}),
baudrate = Parameter('', EnumType({f'{v}': i for i, v in enumerate(BAUDRATES)}),
readonly=False, default=0, visibility=3, group='more')
pollinterval = Parameter(group='more')
@@ -154,7 +154,7 @@ class Motor(PersistentMixin, HasIO, Drivable):
baudrate = getattr(self.io._conn.connection, 'baudrate', None)
if baudrate:
if baudrate not in BAUDRATES:
raise CommunicationFailedError('unsupported baud rate: %d' % baudrate)
raise CommunicationFailedError(f'unsupported baud rate: {int(baudrate)}')
self.io.timeout = 0.03 + 200 / baudrate
exc = None
@@ -178,7 +178,7 @@ class Motor(PersistentMixin, HasIO, Drivable):
if status != 100:
self.log.warning('bad status from cmd %r %s: %d', cmd, adr, status)
if radr != 2 or modadr != self.address or cmd != rcmd:
raise CommunicationFailedError('bad reply %r to command %s %d' % (reply, cmd, adr))
raise CommunicationFailedError(f'bad reply {reply!r} to command {cmd} {adr}')
return result
def startModule(self, start_events):
@@ -229,8 +229,7 @@ class Motor(PersistentMixin, HasIO, Drivable):
if readback:
result = self.comm(GET_AXIS_PAR, adr)
if result != rawvalue:
raise HardwareError('result for adr=%d scale=%g does not match %g != %g'
% (adr, scale, result * scale, value))
raise HardwareError(f'result for adr={adr} scale={scale:g} does not match {result * scale:g} != {value:g}')
return result * scale
return rawvalue * scale