Commit 11cf383f authored by Vincent Michel's avatar Vincent Michel Committed by Sebastien Petitdemange
Browse files

Run 2to3 script

$ 2to3 -w .
$ 2to3 -w bin/*
$ black bin/*
parent 365d4fb5
......@@ -26,8 +26,8 @@ except gevent.Timeout:
if replied_host:
max_host_len = max([len(host) for host, port in replied_host])
format = "{0: <%d} {1}" % max_host_len
print(format.format("HOST", "PORT"))
print((format.format("HOST", "PORT")))
for host, port in sorted(replied_host):
print(format.format(host, port))
print((format.format(host, port)))
else:
print("No response!!!")
......@@ -25,7 +25,7 @@ try:
arguments = docopt.docopt(__doc__)
port = int(arguments["--port"])
except docopt.DocoptExit as e:
print e.message
print(e.message)
else:
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
......
......@@ -71,7 +71,7 @@ def copy_data(zerod, zerod_index, session_name, max_nb_counter, max_nb_points):
sps.putdata(session_name, ARRAY_NAME, sps_data)
min_index = nb_points
for channel_name, channel_info in zerod_index.iteritems():
for channel_name, channel_info in zerod_index.items():
point_nb = channel_info.get("from")
if point_nb < min_index:
min_index = point_nb
......@@ -120,10 +120,10 @@ def watch_data(scan_node, session_name):
"scanno": new_scanno(),
"datafile": "bliss",
"spec": session_name,
"columnnames": zerod_index.keys()
+ [""] * (nbcounters - len(zerod_index.keys())),
"columns": len(zerod_index.keys()),
"selectedcounters": ";".join(zerod_index.keys()),
"columnnames": list(zerod_index.keys())
+ [""] * (nbcounters - len(list(zerod_index.keys()))),
"columns": len(list(zerod_index.keys())),
"selectedcounters": ";".join(list(zerod_index.keys())),
},
{},
)
......@@ -177,7 +177,7 @@ def main():
arguments = docopt.docopt(__doc__)
sessions_name = arguments["<name>"]
except docopt.DocoptExit as e:
print e.message
print(e.message)
else:
tasks = list()
for session in sessions_name:
......
......@@ -65,7 +65,7 @@ def main(host=None, user=None, passwd=None):
else:
properties[name] = [values, value]
for node in server2nodes.values():
for node in list(server2nodes.values()):
node.save()
......
......@@ -112,10 +112,10 @@ class Exporter(ExporterClient.ExporterClient):
if "\x1f" in value:
value = self.parseArray(value)
try:
value = map(int, value)
value = list(map(int, value))
except:
try:
value = map(float, value)
value = list(map(float, value))
except:
pass
else:
......@@ -163,7 +163,7 @@ class ExporterChannel:
def update(self, value=None):
if value is None:
value = self.getValue()
if isinstance(value, tuple):
if type(value) == tuple:
value = list(value)
self.value = value
......
......@@ -7,9 +7,8 @@
Copyright 2009 by European Molecular Biology Laboratory - Grenoble
"""
from __future__ import absolute_import
from warnings import warn
from StandardClient import *
from .StandardClient import *
CMD_SYNC_CALL = "EXEC"
CMD_ASNC_CALL = "ASNC"
......@@ -34,7 +33,7 @@ class ExporterClient(StandardClient):
try:
evtstr = msg[4:]
tokens = evtstr.split(PARAMETER_SEPARATOR)
self.onEvent(tokens[0], tokens[1], long(tokens[2]))
self.onEvent(tokens[0], tokens[1], int(tokens[2]))
except:
# print("Error processing event: " + str(sys.exc_info()[1]))
pass
......
......@@ -9,7 +9,7 @@ import sys
import time
import string
import threading
from ExporterClient import *
from .ExporterClient import *
SERVER_ADDRESS = "localhost"
SERVER_PORT = 9001
......@@ -516,7 +516,7 @@ class MDClient(ExporterClient):
def createStringFromDict(self, motor_position_dict):
ret = ""
for motor in motor_position_dict.keys():
for motor in list(motor_position_dict.keys()):
ret += motor + "=" + str(motor_position_dict[motor]) + ","
return ret
......@@ -541,7 +541,7 @@ class MDClient(ExporterClient):
def getMotorPositions(self):
array = self.readPropertyAsStringArray(self.PROPERTY_MOTOR_POSITIONS)
dict = self.createDictFromStringList(array)
for key in dict.keys():
for key in list(dict.keys()):
dict[key] = float(dict[key])
return dict
......@@ -708,10 +708,10 @@ if __name__ == "__main__":
task_finished = False
def onConnected(self):
print " ****** CONNECTED *******"
print(" ****** CONNECTED *******")
def onDisconnected(self):
print " ****** DISCONNECTED ******"
print(" ****** DISCONNECTED ******")
def onEvent(self, name, value, timestamp):
if name == self.STATE_EVENT:
......@@ -722,22 +722,22 @@ if __name__ == "__main__":
elif name == self.MOTOR_STATES_EVENT:
array = self.parseArray(value)
value = self.createDictFromStringList(array)
print " Event: " + name + " = " + str(value)
print(" Event: " + name + " = " + str(value))
md = Microdiff(SERVER_ADDRESS, SERVER_PORT, PROTOCOL.STREAM, TIMEOUT, RETRIES)
methods = md.getMethodList()
print "-------------- Listing methods ------------------"
print "Methods:"
print("-------------- Listing methods ------------------")
print("Methods:")
for method in methods:
print method
print(method)
print "-------------- Listing properties ------------------"
print("-------------- Listing properties ------------------")
properties = md.getPropertyList()
print "Properties:"
print("Properties:")
for property in properties:
print property
print property
print(property)
print(property)
# Example recovering conection after a MD restart
# It is not needed to call connect explicitly. Connectiong is set with any command/attributr access.
......@@ -749,7 +749,7 @@ if __name__ == "__main__":
# while True:
# time.sleep(md.MONITORING_INTERVAL)
print "-------------- Calling a async task ------------------"
print("-------------- Calling a async task ------------------")
# Setting transfer phase synchronously (blocking)
# md.setTransferPhase(sync=True)
......@@ -770,29 +770,29 @@ if __name__ == "__main__":
task_result_code = md.getLastTaskResultCode()
if task_result_code == None:
print "Task still running"
print("Task still running")
elif task_result_code > 0:
print "Task succeeded"
print("Task succeeded")
elif task_result_code < 0:
print "Task failed" + md.getLastTaskException()
print("Task failed" + md.getLastTaskException())
elif task_result_code == 0:
print "Task aborted"
print("Task aborted")
print "-------------- Executing a scan --------------------"
print("-------------- Executing a scan --------------------")
scan_time = 3.0
md.setScanParameters(0.0, 1.0, 3.0, 1)
md.scan(sync=True, timeout=(scan_time + md.DEFAULT_TASK_TIMEOUT))
md.waitReady()
task_result_code = md.getLastTaskResultCode()
if task_result_code == None:
print "Scan still running"
print("Scan still running")
elif task_result_code > 0:
print "Scan succeeded"
print("Scan succeeded")
elif task_result_code < 0:
print "Scan failed" + md.getLastTaskException()
print("Scan failed" + md.getLastTaskException())
elif task_result_code == 0:
print "Scan aborted"
print "-------------- Directly accessing motors --------------------"
print("Scan aborted")
print("-------------- Directly accessing motors --------------------")
md.setMotorPosition(md.MOTOR_OMEGA, 10.0)
md.setMotorPosition(md.MOTOR_PHI, 5.0)
md.waitMotorReady(md.MOTOR_OMEGA)
......@@ -800,7 +800,7 @@ if __name__ == "__main__":
motor_position_dict = {md.MOTOR_OMEGA: 0.0, md.MOTOR_PHI: 0.0}
md.simultaneousMoveMotors(motor_position_dict, sync=True)
print "-------------- Reading all properties --------------------"
print("-------------- Reading all properties --------------------")
# Reading all properties
for property in properties:
property_info = property.split(" ")
......@@ -816,128 +816,130 @@ if __name__ == "__main__":
value = md.readProperty(property_name)
if property_type.endswith("[]"):
value = md.parseArray(value)
print property_name + " = " + str(value)
print(property_name + " = " + str(value))
except:
print "Error reading " + property_name + ": " + str(sys.exc_info()[1])
print "-------------- Reading/Writing all properties by their get/set methods --------------------"
print "State: " + md.getState()
print "State: " + md.getStatus()
print "Alarms"
print md.getAlarmList()
print "Motor states:"
print md.getMotorStates()
print "Motor positions:"
print md.getMotorPositions()
print "Version: " + md.getVersion()
print "Uptime: " + md.getUptime()
print "ScanSpeed: " + str(md.getScanSpeed())
print "ScanPassDuration: " + str(md.getScanPassDuration())
print "SampleLoaded: " + str(md.isSampleLoaded())
print "isSampleCentred: " + str(md.isSampleCentred())
print "isSampleChangerUsed: " + str(md.isSampleChangerUsed())
print "Scale X: " + str(md.getScaleX())
print "Scale Y: " + str(md.getScaleY())
print("Error reading " + property_name + ": " + str(sys.exc_info()[1]))
print(
"-------------- Reading/Writing all properties by their get/set methods --------------------"
)
print("State: " + md.getState())
print("State: " + md.getStatus())
print("Alarms")
print(md.getAlarmList())
print("Motor states:")
print(md.getMotorStates())
print("Motor positions:")
print(md.getMotorPositions())
print("Version: " + md.getVersion())
print("Uptime: " + md.getUptime())
print("ScanSpeed: " + str(md.getScanSpeed()))
print("ScanPassDuration: " + str(md.getScanPassDuration()))
print("SampleLoaded: " + str(md.isSampleLoaded()))
print("isSampleCentred: " + str(md.isSampleCentred()))
print("isSampleChangerUsed: " + str(md.isSampleChangerUsed()))
print("Scale X: " + str(md.getScaleX()))
print("Scale Y: " + str(md.getScaleY()))
val = md.isGUILocked()
print "GUI locked: " + str(val)
print("GUI locked: " + str(val))
md.setGUILocked(val)
val = md.isKappaEnabled()
print "Kappa Enabled: " + str(val)
print("Kappa Enabled: " + str(val))
md.setKappaEnabled(val)
val = md.isFastShutterOpen()
print "Fast Shutter Open: " + str(val)
print("Fast Shutter Open: " + str(val))
md.setFastShutterOpen(val)
val = md.isFluoDetectorBack()
print "Fluo Detector Back: " + str(val)
print("Fluo Detector Back: " + str(val))
md.setFluoDetectorBack(val)
val = md.isCryoBack()
print "Cryo Back: " + str(val)
print("Cryo Back: " + str(val))
md.setCryoBack(val)
val = md.isInterlockEnabled()
print "Interlock Enabled: " + str(val)
print("Interlock Enabled: " + str(val))
md.setInterlockEnabled(val)
val = md.getScanNumberOfPasses()
print "Scan Number Of Passes: " + str(val)
print("Scan Number Of Passes: " + str(val))
md.setScanNumberOfPasses(val)
val = md.getScanFrameNumber()
print "Scan Frame Number: " + str(val)
print("Scan Frame Number: " + str(val))
md.setScanFrameNumber(val)
val = md.getScanStartAngle()
print "Scan Start Angle: " + str(val)
print("Scan Start Angle: " + str(val))
md.setScanStartAngle(val)
val = md.getScanExposureTime()
print "Scan Exposure Time: " + str(val)
print("Scan Exposure Time: " + str(val))
md.setScanExposureTime(val)
val = md.getScanRange()
print "Scan Range: " + str(val)
print("Scan Range: " + str(val))
md.setScanRange(val)
val = md.getBeamSizeHorizontal()
print "Beam Size Horizontal: " + str(val)
print("Beam Size Horizontal: " + str(val))
md.setBeamSizeHorizontal(val)
val = md.getBeamSizeVertical()
print "Beam Size Vertical: " + str(val)
print("Beam Size Vertical: " + str(val))
md.setBeamSizeVertical(val)
val = md.getFrontLightLevel()
print "Front Light Level: " + str(val)
print("Front Light Level: " + str(val))
md.setFrontLightLevel(val)
val = md.getBackLightLevel()
print "Back Light Level: " + str(val)
print("Back Light Level: " + str(val))
md.setBackLightLevel(val)
val = md.getBackLightLevel()
print "Back Light Level: " + str(val)
print("Back Light Level: " + str(val))
md.setBackLightLevel(val)
val = md.getSampleLoopSize()
print "Sample Loop Size: " + str(val)
print("Sample Loop Size: " + str(val))
md.setSampleLoopSize(val)
val = md.getSampleHolderLength()
print "Sample Holder Length: " + str(val)
print("Sample Holder Length: " + str(val))
md.setSampleHolderLength(val)
val = md.getSampleUID()
print "Sample UID: " + val
print("Sample UID: " + val)
md.setSampleUID(val)
val = md.getSampleLoopType()
print "Sample Loop Type: " + val
print("Sample Loop Type: " + val)
md.setSampleLoopType(val)
val = md.getSampleImageName()
print "Sample Image Name: " + val
print("Sample Image Name: " + val)
md.setSampleImageName(val)
snapshot = md.getImageJPG()
# Calling sync methods
print "Pmac State: " + md.getDeviceState(md.DEVICE_PMAC)
print "Omega State: " + md.getMotorState(md.MOTOR_OMEGA)
print "Omega Position: " + str(md.getMotorPosition(md.MOTOR_OMEGA))
print "Organ Positions: " + str(md.getOrganDevicesPositions())
print("Pmac State: " + md.getDeviceState(md.DEVICE_PMAC))
print("Omega State: " + md.getMotorState(md.MOTOR_OMEGA))
print("Omega Position: " + str(md.getMotorPosition(md.MOTOR_OMEGA)))
print("Organ Positions: " + str(md.getOrganDevicesPositions()))
md.checkSyncMoveSafety({md.MOTOR_OMEGA: 180.0, md.MOTOR_KAPPA: 180.0})
md.checkPositionSafety({md.MOTOR_OMEGA: 180.0, md.MOTOR_KAPPA: 180.0})
md.setStartScan4D()
md.setStopScan4D()
md.setMotorPosition(md.MOTOR_PHI, 0.0, sync=False)
print "Motor Y limits: " + str(md.getMotorLimits(md.MOTOR_Y))
print "Motor Y dynamic limits: " + str(md.getMotorDynamicLimits(md.MOTOR_Y))
print "Photodiode 0: " + str(md.readPhotodiodeSignal(0))
print "Photodiode 1: " + str(md.readPhotodiodeSignal(1))
print("Motor Y limits: " + str(md.getMotorLimits(md.MOTOR_Y)))
print("Motor Y dynamic limits: " + str(md.getMotorDynamicLimits(md.MOTOR_Y)))
print("Photodiode 0: " + str(md.readPhotodiodeSignal(0)))
print("Photodiode 1: " + str(md.readPhotodiodeSignal(1)))
md.disconnect()
......@@ -9,7 +9,7 @@ import sys
import time
import string
import threading
from ExporterClient import *
from .ExporterClient import *
SERVER_ADDRESS = "localhost"
SERVER_PORT = 9001
......@@ -243,7 +243,7 @@ if __name__ == "__main__":
class Microdiff(MDEvents):
def onReceivedEvent(self, name, value, timestamp):
print " Event: " + name + " = " + str(value)
print(" Event: " + name + " = " + str(value))
md = Microdiff(SERVER_ADDRESS, SERVER_PORT, PROTOCOL.STREAM, TIMEOUT, RETRIES)
md.start()
......@@ -251,6 +251,6 @@ if __name__ == "__main__":
while True:
time.sleep(1.0)
if not md.isConnected():
print "Not Connected"
print("Not Connected")
md.stop()
......@@ -108,15 +108,15 @@ class StandardClient:
try:
self.__sock__.sendto(msg, (self.server_ip, self.server_port))
except:
raise SocketError, "Socket error:" + str(sys.exc_info()[1])
raise SocketError("Socket error:" + str(sys.exc_info()[1]))
received = False
while received == False:
try:
ret = self.__sock__.recv(4096)
except socket.timeout:
raise TimeoutError, "Timeout error:" + str(sys.exc_info()[1])
raise TimeoutError("Timeout error:" + str(sys.exc_info()[1]))
except:
raise SocketError, "Socket error:" + str(sys.exc_info()[1])
raise SocketError("Socket error:" + str(sys.exc_info()[1]))
if ret[0:5] == msg_number:
received = True
ret = ret[5:]
......@@ -230,7 +230,7 @@ class StandardClient:
with gevent.Timeout(self.timeout, TimeoutError):
while self.received_msg is None:
if not self.error is None:
raise SocketError, "Socket error:" + str(self.error)
raise SocketError("Socket error:" + str(self.error))
self.msg_received_event.wait()
return self.received_msg
......@@ -254,7 +254,9 @@ class StandardClient:
@protect_from_kill
def send(self, cmd):
if self.protocol == PROTOCOL.DATAGRAM:
raise ProtocolError, "Protocol error: send command not support in datagram clients"
raise ProtocolError(
"Protocol error: send command not support in datagram clients"
)
else:
return self.__sendStream__(cmd)
......
......@@ -9,4 +9,4 @@
interface specific classes)
"""
from _gpib import *
from ._gpib import *
......@@ -347,7 +347,7 @@ class Gpib:
interface = Gpib(url="enet://gpibid00a.esrf.fr", pad=15)
"""
ENET, TANGO, TANGO_DEVICE_SERVER, PROLOGIX, LOCAL = range(5)
ENET, TANGO, TANGO_DEVICE_SERVER, PROLOGIX, LOCAL = list(range(5))
READ_BLOCK_SIZE = 64 * 1024
def __init__(self, url=None, pad=0, sad=0, timeout=1., tmo=13, eot=1, eos="\n"):
......
......@@ -45,9 +45,9 @@ def _dbg(f, name=None):
name = f.__name__
def wrap(self, *a, **k):
print "DBG: %s: enter: %s %s" % (name, ` a `, ` k `),
print("DBG: %s: enter: %s %s" % (name, repr(a), repr(k)), end=" ")
r = f(self, *a, **k)
print "exit: %s" % ` r `
print("exit: %s" % repr(r))
return r
wrap._dummy = True
......@@ -59,7 +59,7 @@ def _not_impl(name):
if "ignore_not_impl" in debug:
return None
else:
raise NotImplementedError, "%s not implemented", name
raise NotImplementedError("%s not implemented").with_traceback(name)
return _dbg(wrap, name)
......@@ -99,8 +99,8 @@ class EnetSocket(object):
if "dummy_io" in debug:
_open = lambda self: None
_send = lambda self, s: sys.stderr.write("DBG: > %s" % (` s `))
_recv = lambda self, len: raw_input("DBG: < #%s:" % (len))[:len]
_send = lambda self, s: sys.stderr.write("DBG: > %s" % (repr(s)))
_recv = lambda self, len: input("DBG: < #%s:" % (len))[:len]
_close = lambda self: None
if "io" in debug:
......@@ -395,7 +395,7 @@ class EnetLib(object):
if name[:3] == "dev":
pad = int(name[3:])
else:
raise ValueError, "configuration not yet implemented. use devX"
raise ValueError("configuration not yet implemented. use devX")
return self.ibdev(pad)
def ibdev(self, *a, **ka):
......@@ -430,16 +430,16 @@ if __name__ == "__main__":
nienet_host = "qo-hpf-gpib1.ethz.ch"
l = EnetLib(nienet_host)
ud = l.ibdev(pad=13)
print "ibrsp", l.ibrsp(ud)
print "iblines", l.iblines(ud)
print "ibtrg", l.ibtrg(ud)
print "ibask", l.ibask(ud, 1)
print "ibln 13", l.ibln(ud, 13)
print "ibln 11", l.ibln(ud, 11)
print "ibwrt", l.ibwrt(ud, "ID?;")
print "ibrd", l.ibrd(ud, 10)
print "ibwrt", l.ibwrt(ud, "SET?;")
print "ibrd", ` l.ibrd(ud, 640) `
print "ibwrt", l.ibwrt(ud, "DSTB;")
print "ibrd", ` l.ibrd(ud, 4096) `
print "ibbna", l.ibbna(ud)
print("ibrsp", l.ibrsp(ud))
print("iblines", l.iblines(ud))
print("ibtrg", l.ibtrg(ud))
print("ibask", l.ibask(ud, 1))
print("ibln 13", l.ibln(ud, 13))
print("ibln 11", l.ibln(ud, 11))
print("ibwrt", l.ibwrt(ud, "ID?;"))
print("ibrd", l.ibrd(ud, 10))
print("ibwrt", l.ibwrt(ud, "SET?;"))
print("ibrd", repr(l.ibrd(ud, 640)))
print("ibwrt", l.ibwrt(ud, "DSTB;"))
print("ibrd", repr(l.ibrd(ud, 4096)))
print("ibbna", l.ibbna(ud))
......@@ -561,7 +561,7 @@ class ModbusTcp:
modbus._connected = False
modbus._fd = None
# inform all pending requests that the socket closed
for trans in modbus._transaction.values():
for trans in list(modbus._transaction.values()):
trans.put(socket.error(errno.EPIPE, "Broken pipe"))
except ReferenceError:
pass
......@@ -158,7 +158,7 @@ class _ServerObject(object):
def __dir__(self):
result = ["zerorpc_call__"]
for name, info in self._metadata["members"].items():
for name, info in list(self._metadata["members"].items()):
if "method" in info["type"]:
result.append(name)
return result
......@@ -332,7 +332,7 @@ def Client(address, **kwargs):
stream = metadata.get("stream", False)
members = dict(_client=client)
for name, info in metadata["members"].items():
for name, info in list(metadata["members"].items()):
if name.startswith("__") and name[2:-2] in SPECIAL_METHODS:
continue
name, mtype, doc = info["name"], info["type"], info["doc"]
......
......@@ -33,7 +33,6 @@ Example::