示例#1
0
 async def once() -> typing.Union[int, bytes]:
     res = await self._call(
         Read, Read.Request(offset=offset, path=Path(path)))
     assert isinstance(res, Read.Response)
     if res.error.value != 0:
         return int(res.error.value)
     return bytes(res.data.value.tobytes())
示例#2
0
 async def get_info(self, path: str) -> GetInfo.Response:
     """
     Proxy for ``uavcan.file.GetInfo``. Be sure to check the error code in the returned object.
     """
     res = await self._call(GetInfo, GetInfo.Request(Path(path)))
     assert isinstance(res, GetInfo.Response)
     return res
示例#3
0
 async def once(d: typing.Union[memoryview, bytes]) -> int:
     res = await self._call(
         Write,
         Write.Request(offset,
                       path=Path(path),
                       data=Unstructured(np.frombuffer(d, np.uint8))))
     assert isinstance(res, Write.Response)
     return res.error.value
示例#4
0
    async def move(self, src: str, dst: str, overwrite: bool = False) -> int:
        """
        Proxy for ``uavcan.file.Modify``.

        :returns: See ``uavcan.file.Error``
        """
        res = await self._call(
            Modify,
            Modify.Request(
                preserve_source=False,
                overwrite_destination=overwrite,
                source=Path(src),
                destination=Path(dst),
            ),
        )
        assert isinstance(res, Modify.Response)
        return int(res.error.value)
示例#5
0
    async def touch(self, path: str) -> int:
        """
        Proxy for ``uavcan.file.Modify``.

        :returns: See ``uavcan.file.Error``
        """
        res = await self._call(Modify, Modify.Request(destination=Path(path)))
        assert isinstance(res, Modify.Response)
        return int(res.error.value)
示例#6
0
 async def list(self, path: str) -> typing.AsyncIterable[str]:
     """
     Proxy for ``uavcan.file.List``. Invokes requests in series until all elements are listed.
     """
     for index in itertools.count():
         res = await self._call(
             List, List.Request(entry_index=index,
                                directory_path=Path(path)))
         assert isinstance(res, List.Response)
         p = res.entry_base_name.path.tobytes().decode(errors="ignore")
         if p:
             yield str(p)
         else:
             break
示例#7
0
 async def _serve_ls(
         self, request: List.Request,
         meta: pyuavcan.presentation.ServiceRequestMetadata
 ) -> List.Response:
     _logger.info("%r: Request from %r: %r", self, meta.client_node_id,
                  request)
     try:
         d = pathlib.Path(*self.locate(request.directory_path))
         for i, e in enumerate(sorted(d.iterdir())):
             if i == request.entry_index:
                 rel = e.absolute().relative_to(d.absolute())
                 return List.Response(Path(str(rel)))
     except FileNotFoundError:
         pass
     except Exception as ex:
         _logger.exception("%r: Directory list error: %s", self, ex)
     return List.Response()