Ejemplo n.º 1
0
    def load(self, yamlfp: BinaryIO) -> None:
        """Load a YaML configuration stream.

           :param yamlfp: YaML stream to be parsed
        """
        backend = get_backend()
        with yamlfp:
            try:
                for ydef in YAML().load_all(yamlfp):
                    self._build_root(backend, ydef)
            except Exception as exc:
                raise ValueError(f'Invalid configuration: {exc}') from exc
        self._validate()
        UsbTools.release_all_devices(VirtDevice)
        UsbTools.flush_cache()
Ejemplo n.º 2
0
    def unload(self) -> None:
        """Unload current USB topology, release all allocated devices, and
           flush UsbTools cache.

           Note that the application should also flush UsbTools cache,
           or reference to 'disconnected' devices may persist.
        """
        backend = get_backend()
        backend.flush_devices()
        count = UsbTools.release_all_devices(VirtDevice)
        UsbTools.flush_cache()
        return count