otg msd and big refactoring

This commit is contained in:
Devaev Maxim
2019-10-29 02:16:12 +03:00
parent f6214191af
commit 10f8c2b335
15 changed files with 1300 additions and 356 deletions

View File

@@ -21,11 +21,11 @@
import asyncio
import types
import contextlib
from typing import Dict
from typing import Type
from typing import AsyncGenerator
from typing import Optional
from . import MsdOperationError
from . import BaseMsd
@@ -39,23 +39,22 @@ class MsdDisabledError(MsdOperationError):
# =====
class Plugin(BaseMsd):
def get_state(self) -> Dict:
async def get_state(self) -> Dict:
return {
"enabled": False,
"multi": False,
"online": False,
"busy": False,
"uploading": False,
"written": 0,
"current": None,
"storage": None,
"cdrom": None,
"connected": False,
"drive": None,
"features": {
"multi": False,
"cdrom": False,
},
}
async def poll_state(self) -> AsyncGenerator[Dict, None]:
while True:
yield self.get_state()
yield (await self.get_state())
await asyncio.sleep(60)
async def reset(self) -> None:
@@ -63,32 +62,24 @@ class Plugin(BaseMsd):
# =====
async def connect(self) -> Dict:
async def set_params(self, name: Optional[str]=None, cdrom: Optional[bool]=None) -> None:
raise MsdDisabledError()
async def disconnect(self) -> Dict:
async def connect(self) -> None:
raise MsdDisabledError()
async def select(self, name: str, cdrom: bool) -> Dict:
async def disconnect(self) -> None:
raise MsdDisabledError()
async def remove(self, name: str) -> Dict:
raise MsdDisabledError()
async def __aenter__(self) -> BaseMsd:
raise MsdDisabledError()
async def write_image_info(self, name: str, complete: bool) -> None:
raise MsdDisabledError()
@contextlib.asynccontextmanager
async def write_image(self, name: str) -> AsyncGenerator[None, None]:
if True: # pylint: disable=using-constant-test
# XXX: Vulture hack
raise MsdDisabledError()
yield
async def write_image_chunk(self, chunk: bytes) -> int:
raise MsdDisabledError()
async def __aexit__(
self,
_exc_type: Type[BaseException],
_exc: BaseException,
_tb: types.TracebackType,
) -> None:
async def remove(self, name: str) -> None:
raise MsdDisabledError()