Exemple #1
0
    def registerDevice(self, device):
        """
        Register or update the specified device. Devices are stored into the file devices.ini
        from the config folder.
        """
        if not config.workspaceIsSet():
            print "Cannot register a device when the workspace is not set."
            return False

        if not isinstance(device, Device):
            error = "The specified device argument must inherit from the type devices.Device."
            logging.info(error)
            raise TypeError(error)

        filesRead = self.parser.read(config.getFullFileName("devices.ini"))
        if len(filesRead) == 0:
            print "The DeviceManager is creating the registry..."
            if not self.createRegistry():
                print "The DeviceManager could not create the registry."
                return False

        currentDevices = self.getDevices()
        if not currentDevices == None and device in currentDevices:
            self.updateDeviceLastSeenTime(device)
            return True

        sectionName = device.visibleName
        self.parser.add_section(sectionName)
        self.parser.set(sectionName, 'visibleName', device.visibleName)
        self.parser.set(sectionName, 'url', device.url)
        self.parser.set(sectionName, 'type', device.type)
        self.parser.set(sectionName, 'lastSeen', str(device.lastSeen))
        with open(config.getFullFileName("devices.ini"),'w') as f:
            self.parser.write(f)
        print "Added device to the registry: {0} {1}".format(device.visibleName, device.url)
        return True
Exemple #2
0
    def show_and_raise(self):
        self.showMaximized()
        self.raise_()

        if not config.workspaceIsSet():
            self.showConfigPanel()