diff --git a/proxy_scraper_checker/fs.py b/proxy_scraper_checker/fs.py index 80618cb..e1730b6 100644 --- a/proxy_scraper_checker/fs.py +++ b/proxy_scraper_checker/fs.py @@ -5,6 +5,8 @@ from pathlib import Path import platformdirs +from .utils import asyncify + logger = logging.getLogger(__name__) CACHE_PATH = platformdirs.user_cache_path("proxy_scraper_checker") @@ -28,6 +30,9 @@ def add_permission( raise +async_add_permission = asyncify(add_permission) + + def create_or_fix_dir(path: Path, /, *, permissions: int) -> None: try: path.mkdir(parents=True) @@ -36,3 +41,6 @@ def create_or_fix_dir(path: Path, /, *, permissions: int) -> None: msg = f"{path} is not a directory" raise ValueError(msg) from None add_permission(path, permissions) + + +async_create_or_fix_dir = asyncify(create_or_fix_dir) diff --git a/proxy_scraper_checker/geodb.py b/proxy_scraper_checker/geodb.py index 0c7e1b1..ca3864d 100644 --- a/proxy_scraper_checker/geodb.py +++ b/proxy_scraper_checker/geodb.py @@ -20,7 +20,7 @@ GEODB_ETAG_PATH = GEODB_PATH.with_suffix(".mmdb.etag") async def _read_etag() -> Optional[str]: try: - await asyncify(fs.add_permission)(GEODB_ETAG_PATH, stat.S_IRUSR) + await fs.async_add_permission(GEODB_ETAG_PATH, stat.S_IRUSR) async with aiofiles.open(GEODB_ETAG_PATH, "rb") as etag_file: content = await etag_file.read() except FileNotFoundError: @@ -29,7 +29,7 @@ async def _read_etag() -> Optional[str]: async def _save_etag(etag: str, /) -> None: - await asyncify(fs.add_permission)( + await fs.async_add_permission( GEODB_ETAG_PATH, stat.S_IWUSR, missing_ok=True ) async with aiofiles.open( @@ -41,7 +41,7 @@ async def _save_etag(etag: str, /) -> None: async def _save_geodb( *, progress: Progress, response: ClientResponse, task: TaskID ) -> None: - await asyncify(fs.add_permission)(GEODB_PATH, stat.S_IWUSR, missing_ok=True) + await fs.async_add_permission(GEODB_PATH, stat.S_IWUSR, missing_ok=True) async with aiofiles.open(GEODB_PATH, "wb") as geodb: async for chunk in response.content.iter_any(): await geodb.write(chunk) diff --git a/proxy_scraper_checker/settings.py b/proxy_scraper_checker/settings.py index a77ad47..29dde27 100644 --- a/proxy_scraper_checker/settings.py +++ b/proxy_scraper_checker/settings.py @@ -31,7 +31,7 @@ from . import fs, sort from .http import get_response_text from .null_context import NullContext from .parsers import parse_ipv4 -from .utils import IS_DOCKER, asyncify +from .utils import IS_DOCKER if TYPE_CHECKING: from .proxy import Proxy @@ -273,10 +273,10 @@ class Settings: ) _, _, (check_website_type, real_ip) = await asyncio.gather( - asyncify(fs.create_or_fix_dir)( + fs.async_create_or_fix_dir( output_path, permissions=stat.S_IXUSR | stat.S_IWUSR ), - asyncify(fs.create_or_fix_dir)( + fs.async_create_or_fix_dir( fs.CACHE_PATH, permissions=stat.S_IRUSR | stat.S_IXUSR | stat.S_IWUSR, ),