more of @element

This commit is contained in:
Erik Frojdh 2020-09-24 08:39:12 +02:00
parent d3fbfebeb7
commit 97fea10ee2
3 changed files with 37 additions and 22 deletions

View File

@ -1125,13 +1125,11 @@ class Detector(CppDetectorApi):
@udp_srcmac.setter @udp_srcmac.setter
def udp_srcmac(self, mac): def udp_srcmac(self, mac):
if isinstance(mac, (list, tuple)): mac = ut.make_mac(mac)
for i, m in enumerate(mac): ut.set_using_dict(self.setSourceUDPMAC, mac)
self.setSourceUDPMAC(MacAddr(m), [i])
else:
self.setSourceUDPMAC(MacAddr(mac))
@property @property
@element
def udp_srcmac2(self): def udp_srcmac2(self):
""" """
[Jungfrau][Gotthard2] Mac address of the receiver (source) udp interface 2. [Jungfrau][Gotthard2] Mac address of the receiver (source) udp interface 2.
@ -1146,17 +1144,15 @@ class Detector(CppDetectorApi):
d.udp_srcmac2 d.udp_srcmac2
00:1b:31:01:8a:de 00:1b:31:01:8a:de
""" """
return element_if_equal(self.getSourceUDPMAC2()) return self.getSourceUDPMAC2()
@udp_srcmac2.setter @udp_srcmac2.setter
def udp_srcmac2(self, mac): def udp_srcmac2(self, mac):
if isinstance(mac, (list, tuple)): mac = ut.make_mac(mac)
for i, m in enumerate(mac): ut.set_using_dict(self.setSourceUDPMAC2, mac)
self.setSourceUDPMAC2(MacAddr(m), [i])
else:
self.setSourceUDPMAC2(MacAddr(mac))
@property @property
@element
def udp_srcip(self): def udp_srcip(self):
""" """
Ip address of the detector (source) udp interface. Ip address of the detector (source) udp interface.
@ -1171,13 +1167,15 @@ class Detector(CppDetectorApi):
>>> d.udp_srcip >>> d.udp_srcip
192.168.1.127 192.168.1.127
""" """
return element_if_equal(self.getSourceUDPIP()) return self.getSourceUDPIP()
@udp_srcip.setter @udp_srcip.setter
def udp_srcip(self, ip): def udp_srcip(self, ip):
self.setSourceUDPIP(IpAddr(ip)) ip = ut.make_ip(ip)
ut.set_using_dict(self.setSourceUDPIP, ip)
@property @property
@element
def udp_srcip2(self): def udp_srcip2(self):
""" """
[Jungfrau][Gotthard2] Ip address of the detector (source) udp interface 2. [Jungfrau][Gotthard2] Ip address of the detector (source) udp interface 2.
@ -1193,13 +1191,15 @@ class Detector(CppDetectorApi):
>>> d.udp_srcip2 >>> d.udp_srcip2
192.168.1.127 192.168.1.127
""" """
return element_if_equal(self.getSourceUDPIP2()) return self.getSourceUDPIP2()
@udp_srcip2.setter @udp_srcip2.setter
def udp_srcip2(self, ip): def udp_srcip2(self, ip):
self.setSourceUDPIP2(IpAddr(ip)) ip = ut.make_ip(ip)
ut.set_using_dict(self.setSourceUDPIP2, ip)
@property @property
@element
def udp_dstport(self): def udp_dstport(self):
""" """
Port number of the receiver (destination) udp interface. Port number of the receiver (destination) udp interface.
@ -1209,13 +1209,14 @@ class Detector(CppDetectorApi):
Ports for each module is calculated (incremented by 1 if no 2nd interface) \n Ports for each module is calculated (incremented by 1 if no 2nd interface) \n
To set ports for individual modules, use setDestinationUDPPort. To set ports for individual modules, use setDestinationUDPPort.
""" """
return element_if_equal(self.getDestinationUDPPort()) return self.getDestinationUDPPort()
@udp_dstport.setter @udp_dstport.setter
def udp_dstport(self, port): def udp_dstport(self, port):
self.setDestinationUDPPort(port) ut.set_using_dict(self.setDestinationUDPPort, port)
@property @property
@element
def udp_dstport2(self): def udp_dstport2(self):
""" """
Port number of the receiver (destination) udp interface. Port number of the receiver (destination) udp interface.
@ -1228,13 +1229,14 @@ class Detector(CppDetectorApi):
Ports for each module is calculated (incremented by 2) \n Ports for each module is calculated (incremented by 2) \n
To set ports for individual modules, use setDestinationUDPPort2. To set ports for individual modules, use setDestinationUDPPort2.
""" """
return element_if_equal(self.getDestinationUDPPort2()) return self.getDestinationUDPPort2()
@udp_dstport2.setter @udp_dstport2.setter
def udp_dstport2(self, port): def udp_dstport2(self, port):
self.setDestinationUDPPort2(port) ut.set_using_dict(self.setDestinationUDPPort2, port)
@property @property
@element
def highvoltage(self): def highvoltage(self):
"""High voltage to the sensor in Voltage. """High voltage to the sensor in Voltage.
@ -1244,11 +1246,11 @@ class Detector(CppDetectorApi):
[Eiger][Mythen3][Gotthard2] 0 - 200 \n [Eiger][Mythen3][Gotthard2] 0 - 200 \n
[Jungfrau][Ctb][Moench] 0, 60 - 200 [Jungfrau][Ctb][Moench] 0, 60 - 200
""" """
return element_if_equal(self.getHighVoltage()) return self.getHighVoltage()
@highvoltage.setter @highvoltage.setter
def highvoltage(self, v): def highvoltage(self, v):
self.setHighVoltage(v) ut.set_using_dict(self.setHighVoltage, v)
@property @property
def user(self): def user(self):
@ -1258,9 +1260,10 @@ class Detector(CppDetectorApi):
return self.getUserDetails() return self.getUserDetails()
@property @property
@element
def settingspath(self): def settingspath(self):
"""[Eiger] Directory where settings files are loaded from/to.""" """[Eiger] Directory where settings files are loaded from/to."""
return element_if_equal(self.getSettingsPath()) return ut.make_path(self.getSettingsPath())
@settingspath.setter @settingspath.setter
def settingspath(self, path): def settingspath(self, path):

View File

@ -122,6 +122,9 @@ def make_ip(arg):
def make_mac(arg): def make_mac(arg):
return _make(arg, _slsdet.MacAddr) return _make(arg, _slsdet.MacAddr)
def make_path(arg):
return _make(arg, Path)
def _make(arg, transform): def _make(arg, transform):
"""Helper function for make_mac and make_ip special cases for """Helper function for make_mac and make_ip special cases for
dict, list and tuple. Otherwise just calls transform""" dict, list and tuple. Otherwise just calls transform"""

View File

@ -9,6 +9,7 @@ from slsdet.utils import *
from slsdet import IpAddr, MacAddr from slsdet import IpAddr, MacAddr
import datetime as dt import datetime as dt
import pathlib import pathlib
from pathlib import Path
def test_iterable(): def test_iterable():
@ -196,3 +197,11 @@ def test_make_mac_from_tuple():
arg = ("84:a9:aa:24:32:88", "84:a9:3e:24:32:aa") arg = ("84:a9:aa:24:32:88", "84:a9:3e:24:32:aa")
assert make_mac(arg) == (MacAddr("84:a9:aa:24:32:88"), assert make_mac(arg) == (MacAddr("84:a9:aa:24:32:88"),
MacAddr("84:a9:3e:24:32:aa")) MacAddr("84:a9:3e:24:32:aa"))
def test_make_path_from_str():
assert make_path("/") == Path("/")
assert make_path("/home") == Path("/home")
def test_make_path_from_list():
arg = ["/", "/home", "/another/path"]
assert make_path(arg) == [Path(p) for p in arg]