Commit 18760bc3 authored by Claudio Scafuri's avatar Claudio Scafuri 💬
Browse files

ported to python3 with 2to3

parent c0f6a211
......@@ -6,7 +6,7 @@ PY_FILES += $(wildcard src/*.py)
default: bin ${PY_FILES}
@cp ${PY_FILES} bin/${DIRNAME}
@echo "#!/usr/bin/env python\nimport sys\nsys.path.append(sys.path[0]+'/${DIRNAME}')\nfrom ${MODNAME} import main\nif __name__ == '__main__':\n main()\n" > bin/${NAME}
@echo "#!/usr/bin/env python3\nimport sys\nsys.path.append(sys.path[0]+'/${DIRNAME}')\nfrom ${MODNAME} import main\nif __name__ == '__main__':\n main()\n" > bin/${NAME}
@chmod +x bin/${NAME} bin/${DIRNAME}/${MAIN}
bin:
......
#!/usr/bin/env python
#!/usr/bin/env python3
# test program for restoring fel1 paramters
# $Author : claudio.scafuri$
#
......@@ -15,14 +15,14 @@
import csv
import sys
import tango as PyTango
import tango
if len(sys.argv) != 3:
print "usage: restore.py device_name filename"
print("usage: restore.py device_name filename")
sys.exit(1)
master = PyTango.DeviceProxy(sys.argv[1])
master = tango.DeviceProxy(sys.argv[1])
f = open(sys.argv[2], 'rb') # opens the csv file
dialect = csv.Sniffer().sniff(f.read(1024))
......@@ -36,9 +36,9 @@ count=0
for row in reader:
saverestore.append(float(row[0]))
print count, row[0]
print(count, row[0])
count += 1
print saverestore
print(saverestore)
master.restorablestatevector=saverestore
#!/usr/bin/env python
#!/usr/bin/env python3
#test program for saving fel1 paramters
# $Author : claudio.scafuri$
#
......@@ -29,5 +29,5 @@ w_val = atval.w_value
for val in w_val:
row = '%s\n' % val
f.write(row)
print row
print(row)
f.close()
#!/usr/bin/env python
#!/usr/bin/env python3
# test program for saving fel1 parameters
# $Author : claudio.scafuri$
#
......@@ -13,18 +13,18 @@
#
import PyTango
import tango
import sys
f = open(sys.argv[1], 'wb')
fm_name = 'fel02/master_s01/master_s01_fel02.01'
fm_dev = PyTango.DeviceProxy(fm_name)
fm_dev = tango.DeviceProxy(fm_name)
atval = fm_dev.read_attribute('RestorableStateVector')
w_val = atval.w_value
for val in w_val:
row = '%s\n' % val
f.write(row)
print row
print(row)
f.close()
#!/usr/bin/env python
#!/usr/bin/env python3
#test program for saving fel1 paramters
# $Author : claudio.scafuri$
#
......@@ -13,7 +13,7 @@
#
import PyTango
import tango
import sys
f = open(sys.argv[1], 'wb') # opens the csv file
......@@ -21,11 +21,11 @@ f = open(sys.argv[1], 'wb') # opens the csv file
fm_name = 'fel02/master_s02/master_s02_fel02.01'
fm_dev = PyTango.DeviceProxy(fm_name)
fm_dev = tango.DeviceProxy(fm_name)
atval = fm_dev.read_attribute('RestorableStateVector')
w_val = atval.w_value
for val in w_val:
row = '%s\n' % (val)
f.write(row)
print row
print(row)
f.close()
This diff is collapsed.
<?xml version="1.0" encoding="ASCII"?>
<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl">
<classes name="FelMaster" pogoRevision="9.6">
<description description="FelMaster handles global settings for FEMI fel opaerations" title="fel master" sourcePath="/home/claudio/devel/fermi/servers/supergap/FelMaster" language="Python" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<description description="FelMaster handles global settings for FEMI fel opaerations" title="fel master" sourcePath="/home/claudio/src/gitlab/cs/ds/felmaster/src" language="Python" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_4Impl" sourcePath=""/>
<identification contact="at elettra.eu - claudio.scafuri" author="claudio.scafuri" emailDomain="elettra.eu" classFamily="OtherInstruments" siteSpecific="" platform="Unix Like" bus="Not Applicable" manufacturer="" reference="">
<keyWords>FEL</keyWords>
......
......@@ -45,7 +45,7 @@ class applyvaluesthread(threading.Thread):
try:
pre_state = self.master.pre_sequencer_3Hc.state()
self.master.info_stream('step 1: check pre sequencer 3Hc termination.')
except tango.DevFailed, e:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.set_status('failed reading pre sequencer state')
self.master.attr_LastSetMsg += 'failed reading pre sequencer state\n'
......@@ -76,7 +76,7 @@ class applyvaluesthread(threading.Thread):
self.master.push_change_event('UndulatorState', tango.DevState.MOVING)
self.master.set_status('step 2: set undulators and shifters.')
self.master.info_stream('step 2: set undulators and shifters.')
except tango.DevFailed, e:
except tango.DevFailed as e:
self.master.error_stream('Tango exception excuting ApplyGap on at least one sub device')
tango.Except.print_exception(e)
tango.Except.re_throw_exception(e, 'command_inout failed',
......@@ -84,7 +84,7 @@ class applyvaluesthread(threading.Thread):
'command_inout failed on at least one sub device')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg = "DevFailed excuting ApplyGap on a device"
except tango.DevError, e:
except tango.DevError as e:
self.master.error_stream('Tango.DevError excuting ApplyGap on at least one sub device')
tango.Except.print_exception(e)
tango.Except.re_throw_exception(e, 'command_inout failed',
......@@ -92,7 +92,7 @@ class applyvaluesthread(threading.Thread):
'command_inout failed on at least one sub device')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg = "DevFailed excuting ApplyGap on a device"
except Exception, e:
except Exception as e:
self.master.error_stream('Unforessen exception excuting ApplyGap on at least one sub device')
# tango.Except.print_exception(e)
tango.Except.throw_exception('command_inout failed',
......@@ -105,17 +105,17 @@ class applyvaluesthread(threading.Thread):
self.master.attr_global_polarization.write(self.master.attr_Polarization_read)
# self.master.attr_global_modulator_polarization.write(self.master.attr_ModulatorPolarization_read)
self.master.attr_global_fel_wavelength.write(self.master.attr_LambdaFEL_read)
except tango.DevError, e:
except tango.DevError as e:
self.master.error_stream('Tango.DevError exception while updating global FEL status')
tango.Except.print_exception(e)
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg = "exception updating global FEL status"
except tango.DevFailed, e:
except tango.DevFailed as e:
self.master.error_stream('Tango.DevFailed exception while updating global FEL status')
tango.Except.print_exception(e)
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg = "exception updating global FEL status"
except Exception, e:
except Exception as e:
self.master.error_stream('Unoforeseen exception while updating global FEL status')
tango.Except.throw_exception('write_attribute failed',
'ApplyGap partially failed',
......@@ -165,7 +165,7 @@ class applyvaluesthread(threading.Thread):
try:
post_state = self.master.post_sequencer_opa.state()
self.master.info_stream('step 3: check post sequencer 3Hc termination.')
except tango.DevFailed, e:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.set_status('failed reading post sequencer state')
self.master.attr_LastSetMsg += 'failed reading post sequencer state\n'
......
......@@ -39,7 +39,7 @@ class opathread(threading.Thread):
compressor_position = float('Nan')
try:
lmb0 = self.master.opa.read_attribute('WavelengthSP').value
except tango.DevFailed, e:
except tango.DevFailed as e:
self.master.set_status('step 1: failed reading l0')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 1: failed reading l0\n'
......@@ -107,7 +107,7 @@ class opathread(threading.Thread):
try:
pre_state = self.master.pre_sequencer_opa.state()
self.master.info_stream('step 1: check pre sequencer OPA termination.')
except tango.DevFailed, e:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.set_status('failed reading pre sequencer state')
self.master.attr_LastSetMsg += 'failed reading pre sequencer state\n'
......@@ -154,14 +154,14 @@ class opathread(threading.Thread):
self.master.compressor.write_attribute('Position', compressor_position)
self.master.info_stream('step 2 compressor: %f' % compressor_position)
self.master.set_status('step 2: compressor setting done')
except tango.DevFailed, e:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.set_status('step 2: failed setting compressor')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 2: failed setting compressor\n'
self.master.error_stream('step 2: failed setting compressor')
except Exception:
print 'line 731 -print_exc() postion=', compressor_position
print('line 731 -print_exc() postion=', compressor_position)
self.master.set_status('step 2: exception setting compressor')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 2: exception setting compressro.\n'
......@@ -170,7 +170,7 @@ class opathread(threading.Thread):
self.master.set_status('step 5: set OPA wavelength')
try:
self.master.opa.write_attribute('Wavelength', self.lmb)
except tango.DevFailed, e:
except tango.DevFailed as e:
self.master.set_status('step 3: failed to set OPA wavelength')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 3: failed to set OPA wavelength. Operation stopped!'
......@@ -196,7 +196,7 @@ class opathread(threading.Thread):
# self.master.opa.write_attribute('EnableCorrection', False)
else:
count += 1
except tango.DevFailed, e:
except tango.DevFailed as e:
tango.Except.print_exception(e)
errcount += 1
self.master.error_stream('failed to read OPA state')
......@@ -216,7 +216,7 @@ class opathread(threading.Thread):
opaauto_on = self.master.emecalib.read_attribute('OPAAuto').value
if (not opaauto_on) and (not math.isnan(self.lmb)):
self.master.emecalib.write_attribute('Wavelength', self.lmb)
except tango.DevFailed, e:
except tango.DevFailed as e:
self.master.set_status('step 4: failed to set new lambda on energy meter')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 4: DevFailed setting new lambda on energy meter\n'
......@@ -262,7 +262,7 @@ class opathread(threading.Thread):
self.master.delay_line2.write_attribute('Position', newdelay2)
self.master.info_stream('step 5 (684): newdelay2: %f' % (newdelay2))
self.master.set_status('step 5:delay line settings done')
except tango.DevFailed, e:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.set_status('step 5: failed setting delay line')
self.master.attr_LastSetOk = False
......@@ -352,7 +352,7 @@ class opathread(threading.Thread):
try:
post_state = self.master.post_sequencer_opa.state()
self.master.info_stream('step 9: check post sequencer OPA termination.')
except tango.DevFailed, e:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.set_status('failed reading post sequencer state')
self.master.attr_LastSetMsg += 'failed reading post sequencer state\n'
......
......@@ -48,7 +48,7 @@ try:
fbenergy_dev = PyTango.DeviceProxy(fbenergy_name)
seed_pow_value_v = fbenergy_dev.GetSensorValues((0,5))
seed_pow_value = seed_pow_value_v.mean()
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continu
......@@ -67,7 +67,7 @@ try:
sldelay_dev.off()
corrmin_12_H_dev.off()
corrmin_12_H_dev.off()
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery
......@@ -85,7 +85,7 @@ except PyTango.DevFailed, e:
time.sleep(0.5)
try:
fel2_second_dev = PyTango.DeviceProxy(fel2_second_stage)
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery
......@@ -93,7 +93,7 @@ except PyTango.DevFailed, e:
try:
fel2_second_dev.Import_lambdaseed_from_infosys()
fel2_second_dev.ApplyCalculatedValues(0)
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery
......@@ -108,7 +108,7 @@ while wait_loops < max_wait_loops:
st = fel2_second_dev.state()
if st == PyTango.DevState.ON:
break
print 'moving'
print('moving')
time.sleep(1)
# leggere la posizione della slitta 4 e 8 per un eventuale rollback - property Delayline2_device_name
......@@ -117,7 +117,7 @@ try:
trls4_ref_pos = trls4_dev.position[0]
trls8_dev = PyTango.DeviceProxy(trls8_name)
trls8_ref_pos = trls8_dev.position[0]
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery
......@@ -137,14 +137,14 @@ try:
seed_power_error = seed_power_error_v.mean()
if seed_power_error > max_seed_power_error:
sezione_disp = True
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery
try:
iom2_1_v = iom_dev.GetIa(0,10)
iom2_1 = iom2_1_v.mean()
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery
......@@ -154,7 +154,7 @@ except PyTango.DevFailed, e:
try:
sldelay_dev.StartScan(0)
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery
......@@ -165,7 +165,7 @@ while wait_loops < max_wait_loops:
st = sldelay_dev.state()
if st != PyTango.DevState.RUNNING:
break
print 'sl delay scan moving'
print('sl delay scan moving')
time.sleep(1)
# il delta rispetto il valore iniziale (trls4_nuovo - trls4_vecchio) va
......@@ -176,20 +176,20 @@ while wait_loops < max_wait_loops:
try:
iom2_2_v = iom_dev.GetIa(0,10)
iom2_2 = iom2_2_v.mean()
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery
try:
if (iom2_2 * 1.1) < iom2_1:
print 'SLdelay optimization failed - restore orignal delay'
print('SLdelay optimization failed - restore orignal delay')
trls4_dev.position = trls4_ref_pos
else: #succesfull optimzation, compnsate trls8
trls4_nuovo = trls4_dev.position
delta_trls4 = trls4_nuovo - trls4_ref_pos
trls8_new_pos = trls8_ref_pos - delta_trls4
trls8_dev.position = trls8_new_pos
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery
......@@ -198,7 +198,7 @@ except PyTango.DevFailed, e:
try:
if sldelay_state == PyTango.DevState.ON:
sldelay_dev.On(0)
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery
......@@ -213,14 +213,14 @@ try:
wait_loops += 1
st = rtltf_dev.optimizestate
if st != PyTango.DevState.ON:
print 'Pointing optimization done'
print('Pointing optimization done')
break
else:
print 'Waiting pointing optimization'
print('Waiting pointing optimization')
time.sleep(1)
if wait_loops == max_wait_loops:
print 'Pointing optimization not done after timeout'
except PyTango.DevFailed, e:
print('Pointing optimization not done after timeout')
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery print 'Pointing optimizatio timed out'
......@@ -233,7 +233,7 @@ if sezione_disp:
disp_sect_dev = PyTango.DeviceProxy(disp_sect_name)
# read dispersive section current for rollback purposes
disp_section = disp_sect_dev.Current
print 'Dispersive section optimization on'
print('Dispersive section optimization on')
fbiom_dev = PyTango.DeviceProxy(fbiom_name)
fbiom_dev.On()
time.sleep(3)
......@@ -243,20 +243,20 @@ if sezione_disp:
wait_loops += 1
fbiom_state = fbiom_dev.state()
if fbiom_state != PyTango.DevState.ON:
print 'Dispersive section optimization done'
print('Dispersive section optimization done')
break
else:
print 'Waiting Dispersive section optimization'
print('Waiting Dispersive section optimization')
time.sleep(1)
if wait_loops == max_wait_loops:
print 'Pointing optimization not done after timeout'
print('Pointing optimization not done after timeout')
# si legge iom2_4, se minore di iom2_3 si ripristina il valore della prima sezione dispersiva
iom2_4_v = iom_dev.GetIa((0,10))
iom2_4 = iom2_4_v.mean()
if ( iom2_4 *1.1 ) < iom2_3:
print 'rollaback dispersive section'
print('rollaback dispersive section')
disp_sect_dev.current = disp_section
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery print 'Pointing optimizatio timed out'
......@@ -266,6 +266,6 @@ try:
corrmin_12_H_dev.On(0)
if corrmin_12_V_state == PyTango.DevState.ON:
corrmin_12_V_dev.On(0)
except PyTango.DevFailed, e:
except PyTango.DevFailed as e:
PyTango.Except.print_exception(e)
exit #stop not possible to continue ??? try recovery print 'Pointing optimizatio timed out'
from __future__ import print_function
import harmoncalc
import pylab
......@@ -12,12 +12,12 @@ L = pylab.arange(start,stop+step,step)
for l in L:
res = opa.calculate(l)
print (l,'\t', end='')
print (l,'\t')
for i in range (len(res[0])):
n=str(res[0][i])
l=str(res[1][i])
msg=n+'|'+l
print( msg,end='\t')
print( msg,'\t')
print('')
......@@ -22,17 +22,17 @@ class Test(unittest.TestCase):
def test_value(self):
l1 = 342
l2 = 310.0
print 'position :',l1, self.opa.get_position(l1)
print 'position :',l2, self.opa.get_position(l2)
print('position :',l1, self.opa.get_position(l1))
print('position :',l2, self.opa.get_position(l2))
def testTable(self):
l = self.opa.get_min_lambda()
lmax = self.opa.get_max_lambda()
print l, lmax
print(l, lmax)
while l <= lmax:
dl = self.opa.get_position(l)
print l, ' ', dl
print(l, ' ', dl)
l += 0.5
if __name__ == "__main__":
......
......@@ -21,22 +21,22 @@ class Test(unittest.TestCase):
def test_value(self):
l1 = 310
l2 = 350
print 'delta ps:', self.opa.get_compensation_delay(l1, l2)
print 'delta ps:', self.opa.get_compensation_delay(l2, l1)
print('delta ps:', self.opa.get_compensation_delay(l1, l2))
print('delta ps:', self.opa.get_compensation_delay(l2, l1))
def testFwl(self):
l1 = 300.1
l2 = 310.0
print 'Fwl delta ps:', self.opa.get_compensation_delay(l1, l2)
print 'Fwl delta ps:', self.opa.get_compensation_delay(l2, l1)
print('Fwl delta ps:', self.opa.get_compensation_delay(l1, l2))
print('Fwl delta ps:', self.opa.get_compensation_delay(l2, l1))
def testTable(self):
l = self.opa.get_min_lambda()
lmax = self.opa.get_max_lambda()
print l, lmax
print(l, lmax)
while l <= lmax:
dl = self.opa.get_abs_delay(l)
print l, ' ', dl
print(l, ' ', dl)
l += 0.5
def testDelta(self):
......@@ -48,7 +48,7 @@ class Test(unittest.TestCase):
l3 = l - dle
dplus = self.opa.get_compensation_delay(l, l2) *1000.0
dminus = self.opa.get_compensation_delay(l, l3) *1000.0
print l, ',', dplus, ',', dminus
print(l, ',', dplus, ',', dminus)
l += 0.5
if __name__ == "__main__":
......
......@@ -33,46 +33,46 @@ class Test(unittest.TestCase):
pass
def testbase(self):
print
print '----------------------------------------'
print 'lambda fel min:', self.opa.get_fel_min()
print 'lambda fel max:', self.opa.get_fel_max()
print '----------------------------------------'
print
print()
print('----------------------------------------')
print('lambda fel min:', self.opa.get_fel_min())
print('lambda fel max:', self.opa.get_fel_max())
print('----------------------------------------')
print()
def testcalc(self):
print
print '.........................................'
print()
print('.........................................')
ll = [100.0, 65.25, 32.5, 34.0, 52.5, 20.0, 9.1, 8.0]
for lf in ll:
try:
res = self.opa.calculate(lf)
print 'testcalc ', lf, ' ', res[0], ' ', res[1]
print('testcalc ', lf, ' ', res[0], ' ', res[1])
except:
print 'testcalc ', lf, ' no solution'
print '.........................................'
print
print('testcalc ', lf, ' no solution')
print('.........................................')
print()
def test_normal(self):
print
print '******************************************'
print()
print('******************************************')
for lf in self.l_normal:
try:
res = self.opa.calculate(lf)
print 'test_normal ', lf, ' ', res[0], ' ', res[1]
print('test_normal ', lf, ' ', res[0], ' ', res[1])
except:
print 'test_normal ', lf, ' no solution'
print '******************************************'
print
print('test_normal ', lf, ' no solution')
print('******************************************')
print()
def test_change_limit(self):
self.opa.set_limits(2, 40, 380.0, 281.0)
print '======================================='
print self.opa.get_limits()
print '======================================='
print 'lambda fel min:', self.opa.get_fel_min()
print 'lambda fel max:', self.opa.get_fel_max()
print '======================================='
print('=======================================')
print(self.opa.get_limits())
print('=======================================')
print('lambda fel min:', self.opa.get_fel_min())
print('lambda fel max:', self.opa.get_fel_max())
print('=======================================')
pass
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment