41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
####################################
|
||
|
# Directory-Getter implementations #
|
||
|
####################################
|
||
|
|
||
|
# Imports
|
||
|
from tubot.dirgetter.types import GetterTypes
|
||
|
from tubot.dirgetter.abc import DirGetter
|
||
|
from aiofiles.os import listdir
|
||
|
from aiofiles.ospath import isdir
|
||
|
|
||
|
|
||
|
class OSGetter(DirGetter):
|
||
|
"""
|
||
|
Python.os module implementation of DirectoryGetter
|
||
|
"""
|
||
|
_gtype = GetterTypes.OS
|
||
|
base_dir: str
|
||
|
|
||
|
def __init__(self, base_dir: str) -> None:
|
||
|
"""
|
||
|
:param base_dir: Path to parent directory
|
||
|
"""
|
||
|
super().__init__()
|
||
|
self.base_dir = base_dir
|
||
|
|
||
|
@property
|
||
|
async def folders(self) -> dict:
|
||
|
dirs = {}
|
||
|
ls = await listdir(self.base_dir)
|
||
|
if len(ls) == 0:
|
||
|
raise ValueError("No dirs found")
|
||
|
for item in ls:
|
||
|
if await isdir(f"{self.base_dir}/{item}"):
|
||
|
dirs[item] = f"{self.base_dir}/{item}"
|
||
|
return dirs
|
||
|
|
||
|
async def __validate__(self) -> bool:
|
||
|
return await isdir(self.base_dir)
|