コード例 #1
0
    def _mount(self):
        if self._children:
            self._mode |= MODE_VIRT

        if self._mode & MODE_VIRT or self._index == None:
            mode = None
            freq = None
            prof = None
        else:
            mode = self._mode
            freq = self._freq
            prof = self.d_profile
            path = get_mnt_path(self._uid, self._name)
            if os.path.exists(path):
                loader = Loader(self._uid)
                curr_prof = loader.get_profile(self._name)
                if curr_prof['type'] == prof['type']:
                    curr_mode = loader.get_attr(self._name, ATTR_MODE, int)
                    if ((curr_mode | MODE_SYNC) == (mode | MODE_SYNC)
                        ) and curr_prof.get('spec') == prof.get('spec'):
                        mode = None
                        freq = None
                        prof = None
                    else:
                        if not (curr_mode & MODE_SYNC):
                            mode &= ~MODE_SYNC
                        else:
                            mode |= MODE_SYNC
                        freq = loader.get_attr(self._name, ATTR_FREQ, float)
コード例 #2
0
class Lo(UDI):
    def get_name(self, device, child=None):
        return _get_name(device)

    def get_mode(self, device):
        return _get_mode(device)

    def setup(self):
        self._active = False
        self._loader = Loader(self.get_uid())
        Thread(target=create_server, args=(LO_ADDR, LO_PORT, LoServer)).start()

    def _get_device(self, name):
        mode = self._core.get_mode(name)
        prof = self._loader.get_profile(name)
        if prof:
            return device_name(prof['type'], name, mode)

    def scan(self):
        device_list = []
        if not self._active:
            self._active = True
            names = get_devices(self._uid, sort=True)
            if names:
                for name in names:
                    device = self._get_device(name)
                    if device and device not in _devices:
                        device_list.append(device)
        return device_list

    def connect(self, device):
        return (connect(device), True)

    @property
    def compute_unit(self):
        if not _devices:
            return
        keys = _devices.keys()
        length = len(keys)
        i = randint(0, length - 1)
        for _ in range(length):
            device = _devices[keys[i]]
            if device.get_mode() & MODE_CTRL:
                return device
            i += 1
            if i == length:
                i = 0