22
33"""
44read SPEC config file and convert to ophyd setup commands
5+
6+ output of ophyd configuration to stdout
57"""
68
79
810from collections import OrderedDict
911import re
1012
1113
12- CONFIG_FILE = 'config'
14+ CONFIG_FILE = 'config-8idi '
1315KNOWN_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