Coverage for src/lanraragi_api/api/shinobu.py: 67%
12 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-22 23:19 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-22 23:19 +0000
1from typing import Any
3from lanraragi_api.api.base import BaseAPICall
4from lanraragi_api.entity.base import OperationResponse
7class ShinobuAPI(BaseAPICall):
8 """Shinobu Filewatcher APIs.
10 Shared request and error behavior is documented on ``BaseAPICall``.
11 """
13 def get_shinobu_status(self) -> dict[str, Any]:
14 """Get the current status of the filewatcher.
16 Returns:
17 dict: Decoded status payload, holding the ``is_alive`` flag and the
18 ``pid`` of the watcher process.
20 Raises:
21 APIHttpError: Any status code other than 200.
22 APIResponseDecodeError: If the body is not valid JSON.
23 """
24 return self.request_json("GET", "/api/shinobu")
26 def stop_shinobu(self) -> OperationResponse:
27 """Stop the filewatcher.
29 Use ``/api/shinobu/restart`` to start it again.
31 Returns:
32 OperationResponse: Result of the operation.
34 Raises:
35 APIResponseDecodeError: If the body is not valid JSON, or does not
36 match ``OperationResponse``.
37 APIOperationError: If the operation failed and raising is enabled.
38 """
39 return self.request_operation("POST", "/api/shinobu/stop")
41 def restart_shinobu(self) -> OperationResponse:
42 """Restart the Shinobu filewatcher.
44 This also starts the filewatcher again when it was stopped.
46 Returns:
47 OperationResponse: Result of the operation, with the new process
48 PID as an extra field.
50 Raises:
51 APIResponseDecodeError: If the body is not valid JSON, or does not
52 match ``OperationResponse``.
53 APIOperationError: If the operation failed and raising is enabled.
54 """
55 return self.request_operation("POST", "/api/shinobu/restart")
57 def rescan_shinobu(self) -> OperationResponse:
58 """Rescan the filemap and restart Shinobu.
60 This deletes the internal map of scanned files on your system (the
61 "filemap") and restarts Shinobu, effectively prompting a full rescan
62 of your FS.
64 Returns:
65 OperationResponse: Result of the operation, with the new process
66 PID as an extra field.
68 Raises:
69 APIResponseDecodeError: If the body is not valid JSON, or does not
70 match ``OperationResponse``.
71 APIOperationError: If the operation failed and raising is enabled.
72 """
73 return self.request_operation("POST", "/api/shinobu/rescan")