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

1from typing import Any 

2 

3from lanraragi_api.api.base import BaseAPICall 

4from lanraragi_api.entity.base import OperationResponse 

5 

6 

7class ShinobuAPI(BaseAPICall): 

8 """Shinobu Filewatcher APIs. 

9 

10 Shared request and error behavior is documented on ``BaseAPICall``. 

11 """ 

12 

13 def get_shinobu_status(self) -> dict[str, Any]: 

14 """Get the current status of the filewatcher. 

15 

16 Returns: 

17 dict: Decoded status payload, holding the ``is_alive`` flag and the 

18 ``pid`` of the watcher process. 

19 

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") 

25 

26 def stop_shinobu(self) -> OperationResponse: 

27 """Stop the filewatcher. 

28 

29 Use ``/api/shinobu/restart`` to start it again. 

30 

31 Returns: 

32 OperationResponse: Result of the operation. 

33 

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") 

40 

41 def restart_shinobu(self) -> OperationResponse: 

42 """Restart the Shinobu filewatcher. 

43 

44 This also starts the filewatcher again when it was stopped. 

45 

46 Returns: 

47 OperationResponse: Result of the operation, with the new process 

48 PID as an extra field. 

49 

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") 

56 

57 def rescan_shinobu(self) -> OperationResponse: 

58 """Rescan the filemap and restart Shinobu. 

59 

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. 

63 

64 Returns: 

65 OperationResponse: Result of the operation, with the new process 

66 PID as an extra field. 

67 

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")