Example #1
0
 def _accept(self):
     '''
     Accepts provided device data.
     '''
     log.debug("Accepting device data")
     # Test provided name
     name = self._name.text()
     if not name:
         dialogs.runError("'name' field is required")
         return
     # Test provided address
     address = self._address.currentText()
     if not address:
         dialogs.runError("'address' field is required")
         return
     if ((not self._device or self._device.name != name)
         and devices.get(name) is not None):
         dialogs.runError("'%s' name already in use" % name)
         return
     self.params = {
         "name": name,
         "description": self._desc.text() or '',
         "address": address,
         "port": self._port.value(),
         "connect": self._connect.isChecked(),
         "autoconnect": self._autoconnect.isChecked()
     }
     self._lastAddresses.add(address)
     self.dialog.accept()
Example #2
0
def getDevices(deviceArgs):
    '''
    Converts command-line arguments representing devices.

    :param deviceArgs: Devices identifiers
    :type deviceArgs: list [string]
    :return: List of devices
    :rtype: list [tadek.connection.device.Device]
    '''
    log.debug("Get devices from command-line arguments: %s" % deviceArgs)
    deviceList = []
    if deviceArgs is None or deviceArgs == [None]:
        log.info("Using default device %s:%d" %
                 (devices.DEFAULT_IP, devices.DEFAULT_PORT))
        deviceList.append(
            Device('localhost', devices.DEFAULT_IP, devices.DEFAULT_PORT))
    else:
        for arg in deviceArgs:
            device = devices.get(arg)
            if device is None:
                address = arg.split(':')
                if len(address) == 2:
                    address, port = address
                    port = int(port)
                elif len(address) == 1:
                    address, port = address[0], devices.DEFAULT_PORT
                else:
                    exitWithError("Invalid format of a device: %s" % arg)
                device = Device(address + ':' + str(port), address, port)
            log.info("Adding a device: %s=%s:%d" %
                     (device.name, device.address[0], device.address[1]))
            deviceList.append(device)
    return deviceList
Example #3
0
 def _editDevice(self):
     '''
     Runs the 'Edit device' dialog for currently selected device.
     '''
     items = self._deviceList.selectedItems()
     if not items:
         return
     dev = devices.get(items[0].text(0))
     log.debug("Editing device: %s" % dev)
     dialog = DeviceConfigDialog(dev)
     if not dialog.run():
         return
     connect = dialog.params.pop("connect", False)
     if dev.name != dialog.params["name"]:
         self._updateConnectionState(False, dev)
         devices.remove(dev.name)
         index = self._deviceList.indexOfTopLevelItem(items[0])
         self._deviceList.takeTopLevelItem(index)
         dev = devices.add(type=Device, **dialog.params)
         self._addDeviceItem(dev)
     else:
         address = dialog.params["address"]
         port = dialog.params["port"]
         if dev.address != (address, port):
             self._updateConnectionState(False, dev)
         devices.update(**dialog.params)
         self._deviceItems[dev].updateDevice()
     log.info("Device edited: %s" % dev)
     if connect:
         self._updateConnectionState(True, dev)
Example #4
0
 def _accept(self):
     '''
     Accepts provided device data.
     '''
     log.debug("Accepting device data")
     # Test provided name
     name = self._name.text()
     if not name:
         dialogs.runError("'name' field is required")
         return
     # Test provided address
     address = self._address.currentText()
     if not address:
         dialogs.runError("'address' field is required")
         return
     if ((not self._device or self._device.name != name)
             and devices.get(name) is not None):
         dialogs.runError("'%s' name already in use" % name)
         return
     self.params = {
         "name": name,
         "description": self._desc.text() or '',
         "address": address,
         "port": self._port.value(),
         "connect": self._connect.isChecked(),
         "autoconnect": self._autoconnect.isChecked()
     }
     self._lastAddresses.add(address)
     self.dialog.accept()
Example #5
0
 def _editDevice(self):
     '''
     Runs the 'Edit device' dialog for currently selected device.
     '''
     items = self._deviceList.selectedItems()
     if not items:
         return
     dev = devices.get(items[0].text(0))
     log.debug("Editing device: %s" % dev)
     dialog = DeviceConfigDialog(dev)
     if not dialog.run():
         return
     connect = dialog.params.pop("connect", False)
     if dev.name != dialog.params["name"]:
         self._updateConnectionState(False, dev)
         devices.remove(dev.name)
         index = self._deviceList.indexOfTopLevelItem(items[0])
         self._deviceList.takeTopLevelItem(index)
         dev = devices.add(type=Device, **dialog.params)
         self._addDeviceItem(dev)
     else:
         address = dialog.params["address"]
         port = dialog.params["port"]
         if dev.address != (address, port):
             self._updateConnectionState(False, dev)
         devices.update(**dialog.params)
         self._deviceItems[dev].updateDevice()
     log.info("Device edited: %s" % dev)
     if connect:
         self._updateConnectionState(True, dev)
Example #6
0
def getDevices(deviceArgs):
    '''
    Converts command-line arguments representing devices.

    :param deviceArgs: Devices identifiers
    :type deviceArgs: list [string]
    :return: List of devices
    :rtype: list [tadek.connection.device.Device]
    '''
    log.debug("Get devices from command-line arguments: %s" % deviceArgs)
    deviceList = []
    if deviceArgs is None or deviceArgs == [None]:
        log.info("Using default device %s:%d"
                 % (devices.DEFAULT_IP, devices.DEFAULT_PORT) )
        deviceList.append(Device('localhost', devices.DEFAULT_IP,
                                 devices.DEFAULT_PORT))
    else:
        for arg in deviceArgs:
            device = devices.get(arg)
            if device is None:
                address = arg.split(':')
                if len(address) == 2:
                    address, port = address
                    port = int(port)
                elif len(address) == 1:
                    address, port = address[0], devices.DEFAULT_PORT
                else:
                    exitWithError("Invalid format of a device: %s" % arg)
                device = Device(address + ':' + str(port), address, port)
            log.info("Adding a device: %s=%s:%d"
                      % (device.name, device.address[0], device.address[1]))
            deviceList.append(device)
    return deviceList
Example #7
0
 def _refresh(self):
     '''
     Refreshes the list of devices.
     '''
     log.debug("Refreshing device list")
     devices.load(type=Device)
     for dev in self._deviceItems.keys()[:]:
         if devices.get(dev.name) is None and not dev.isConnected():
             self._removeDeviceItem(dev)
     for dev in devices.all():
         if dev not in self._deviceItems:
             self._addDeviceItem(dev)
     self._updateDialogButtons()
Example #8
0
 def _refresh(self):
     '''
     Refreshes the list of devices.
     '''
     log.debug("Refreshing device list")
     devices.load(type=Device)
     for dev in self._deviceItems.keys()[:]:
         if devices.get(dev.name) is None and not dev.isConnected():
             self._removeDeviceItem(dev)
     for dev in devices.all():
         if dev not in self._deviceItems:
             self._addDeviceItem(dev)
     self._updateDialogButtons()
Example #9
0
 def _removeDevice(self):
     '''
     Removes the currently selected device.
     '''
     items = self._deviceList.selectedItems()
     if not items:
         return
     dev = devices.get(items[0].text(0))
     if not dialogs.runQuestion("Do you want to remove "
                                "'%s' device permanently?" % dev.name):
         return
     log.debug("Removing device: %s" % dev)
     self._updateConnectionState(False, dev)
     devices.remove(dev.name)
     self._removeDeviceItem(dev)
     log.info("Device removed: %s" % dev)
Example #10
0
 def _removeDevice(self):
     '''
     Removes the currently selected device.
     '''
     items = self._deviceList.selectedItems()
     if not items:
         return
     dev = devices.get(items[0].text(0))
     if not dialogs.runQuestion("Do you want to remove "
                                "'%s' device permanently?" % dev.name):
         return
     log.debug("Removing device: %s" % dev)
     self._updateConnectionState(False, dev)
     devices.remove(dev.name)
     self._removeDeviceItem(dev)
     log.info("Device removed: %s" % dev)
Example #11
0
 def testRemove(self):
     devices.remove(_DEVICE_NAME)
     self.failIf(devices.get(_DEVICE_NAME))
Example #12
0
 def testLoad(self):
     device = devices.get(_DEVICE_NAME)
     self.failUnless(device)
     devices.load()
     self.failUnlessEqual(device, devices.get(_DEVICE_NAME))
Example #13
0
 def testLoadInvalid(self):
     devices.load()
     self.failIf(devices.get(_DEVICE_NAME))
Example #14
0
 def testLoad(self):
     device = devices.get(_DEVICE_NAME)
     self.failUnless(device)
     devices.load()
     self.failUnlessEqual(device, devices.get(_DEVICE_NAME))
Example #15
0
 def testAdd(self):
     device = devices.add(_DEVICE_NAME, **_DEVICE_PARAS)
     self.failUnless(device)
     self.failUnlessEqual(device, devices.get(_DEVICE_NAME))
Example #16
0
 def testUpdate(self):
     devices.update(_DEVICE_NAME, boolean=True)
     device = devices.get(_DEVICE_NAME)
     self.failUnless(device)
     self.failUnless("boolean" in device.params)
     self.failUnlessEqual(device.params["boolean"].getBool(), True)
Example #17
0
 def testRemove(self):
     devices.remove(_DEVICE_NAME)
     self.failIf(devices.get(_DEVICE_NAME))
Example #18
0
 def testUpdate(self):
     devices.update(_DEVICE_NAME, boolean=True)
     device = devices.get(_DEVICE_NAME)
     self.failUnless(device)
     self.failUnless("boolean" in device.params)
     self.failUnlessEqual(device.params["boolean"].getBool(), True)
Example #19
0
 def testAdd(self):
     device = devices.add(_DEVICE_NAME, **_DEVICE_PARAS)
     self.failUnless(device)
     self.failUnlessEqual(device, devices.get(_DEVICE_NAME))
Example #20
0
 def testLoadInvalid(self):
     devices.load()
     self.failIf(devices.get(_DEVICE_NAME))