Skip to content

Commit 3a55ce0

Browse files
committed
fixes #190
1 parent fd98e45 commit 3a55ce0

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

apstools/migration/spec2ophyd.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
"""
44
read SPEC config file and convert to ophyd setup commands
5+
6+
output of ophyd configuration to stdout
57
"""
68

79

810
from collections import OrderedDict
911
import re
1012

1113

12-
CONFIG_FILE = 'config'
14+
CONFIG_FILE = 'config-8idi'
1315
KNOWN_DEVICES = "PSE_MAC_MOT VM_EPICS_M1 VM_EPICS_SC".split()
1416

1517

@@ -76,6 +78,7 @@ def pop_word(line, int_result=False):
7678
self.mne, self.name = pop_word(r)
7779
self.device = None
7880
self.pvname = None
81+
self.motpar = []
7982

8083
def __str__(self):
8184
items = [self.item_name_value(k) for k in "index mne name".split()]
@@ -158,6 +161,7 @@ def __init__(self, config_file):
158161

159162
def read_config(self, config_file=None):
160163
self.config_file = config_file or self.config_file
164+
motor = None
161165
with open(self.config_file, 'r') as f:
162166
for line in f.readlines():
163167
line = line.strip()
@@ -173,8 +177,9 @@ def read_config(self, config_file=None):
173177
# 0-based numbering
174178
device.index = len(self.devices[device.name])
175179
self.devices[device.name].append(device)
176-
elif word0 == "MOTPAR:read_mode":
177-
self.unhandled.append(line)
180+
elif word0.startswith("MOTPAR:"):
181+
if motor is not None:
182+
motor.motpar.append(line[len("MOTPAR:"):])
178183
elif re.match("CNT\d*", line) is not None:
179184
counter = SpecCounter(line)
180185
counter.setDevice(self.devices)
@@ -197,24 +202,30 @@ def create_ophyd_setup(spec_config):
197202
if not import_shown:
198203
print("from ophyd.scaler import ScalerCH")
199204
import_shown = True
200-
print("{} = {}('{}', name='{}')".format(
201-
mne, "ScalerCH", device.prefix, mne))
205+
print(f"{mne} = ScalerCH('{device.prefix}', name='{mne}')")
202206
chans = []
203207
for counter in spec_config.counters.values():
204208
if counter.device == device:
205209
key = "chan%02d" % (counter.chan+1)
206-
print("# {} : {} ({})".format(key, counter.mne, counter.name))
210+
print(f"# {key} : {counter.mne} ({counter.name})")
207211
chans.append(key)
208212
if len(chans) > 0:
209-
print("{}.channels.read_attrs = {}".format(mne, chans))
213+
print(f"{mne}.channels.read_attrs = {chans}")
210214

211215
mne_list = []
212216
for mne, motor in sorted(spec_config.motors.items()):
213217
if motor.pvname is not None:
214218
mne = mne.replace(".", "_")
215219
mne_list.append(mne)
216-
print("{} = {}('{}', name='{}') # {}".format(
217-
mne, "EpicsMotor", motor.pvname, mne, motor.name))
220+
msg = f"{mne} = EpicsMotor('{motor.pvname}', name='{mne}')"
221+
comments = []
222+
if motor.mne != motor.name:
223+
comments.append(f"{motor.name}")
224+
if len(motor.motpar) > 0:
225+
comments.append(f" TODO: {', '.join(motor.motpar)}")
226+
if len(comments) > 0:
227+
msg += f" # {(' '.join(comments)).strip()}"
228+
print(msg)
218229

219230

220231

0 commit comments

Comments
 (0)