pyepics / newportxps

python support code for NewportXPS drivers
BSD 2-Clause "Simplified" License
20 stars 17 forks source link

system.ini parser problem #9

Open jurajjasik opened 3 years ago

jurajjasik commented 3 years ago

Hello, I found an issue with parsing factory provided system.ini file from XPS-C:

[GENERAL]
BootScriptFileName = 
BootScriptArguments = 

[GROUPS]
SingleAxisInUse =  THETA, X, Y, Z
SpindleInUse = 
XYInUse = 
XYZInUse = 
MultipleAxesInUse = 

 [THETA]
PositionerInUse = RVS80

 [THETA.RVS80]
PlugNumber = 1
StageName = RVS80PPV6
;--- Time flasher
TimeFlasherBaseFrequency = 40e6 ; Hz

 [X]
PositionerInUse = LTA-X

 [X.LTA-X]
PlugNumber = 2
StageName = LTAHLPPV6-X
;--- Time flasher
TimeFlasherBaseFrequency = 40e6 ; Hz

 [Y]
PositionerInUse = LTA-Y

 [Y.LTA-Y]
PlugNumber = 3
StageName = LTAHLPPV6-Y
;--- Time flasher
TimeFlasherBaseFrequency = 40e6 ; Hz

 [Z]
PositionerInUse = LTA-Z

 [Z.LTA-Z]
PlugNumber = 4
StageName = LTAHLPPV6-Z
;--- Time flasher
TimeFlasherBaseFrequency = 40e6 ; Hz

After debugging, I found that problem is in leading white character in [section] header line. Such line is not processed correctly with ConfigParser. To be honest, I am not sure if white characters before section are allowed in standart .ini files but possible workaround is to remove white characters from lines before parsing using strip() function. Thus replace code: https://github.com/pyepics/newportxps/blob/4713dcc693bd7dc5bd91ff4f456f3f0c8cd1306a/newportxps/newportxps.py#L173 with:

sconf.readfp(StringIO('\n'.join([line.strip() for line in lines])))

Best, Juraj

newville commented 3 years ago

@jurajjasik That's interesting. Yeah, I guess I just assumed that the ini files would comply with ConfigParser, and they have for me and our group for multiple (10+) XPSes for many (10+) years.

But I guess that isn't necessarily going to always work. I'll add your suggested fix, and hope that will be enough. Thanks!