Move the cache dir to the top level directory

This commit is contained in:
Christoph Reiter 2021-05-14 07:41:58 +02:00
parent 24bfec26a1
commit 7f7bb0aee4
4 changed files with 16 additions and 7 deletions

3
.gitignore vendored
View File

@ -5,4 +5,5 @@ node_modules
*srcinfo.json
.mypy_cache
_cache
.vscode
.vscode
*.cache

View File

@ -1,6 +1,9 @@
# Copyright 2016-2020 Christoph Reiter
# SPDX-License-Identifier: MIT
from typing import Optional
REPO_URL = "https://repo.msys2.org"
REPOSITORIES = [
@ -53,4 +56,4 @@ BUILD_STATUS_CONFIG = [
UPDATE_INTERVAL = 60 * 5
REQUEST_TIMEOUT = 60
CACHE_LOCAL = False
CACHE_DIR: Optional[str] = None

View File

@ -31,13 +31,12 @@ def get_update_urls() -> List[str]:
async def get_content_cached(url: str, *args: Any, **kwargs: Any) -> bytes:
if not appconfig.CACHE_LOCAL:
cache_dir = appconfig.CACHE_DIR
if cache_dir is None:
async with httpx.AsyncClient() as client:
r = await client.get(url, *args, **kwargs)
return r.content
base = os.path.dirname(os.path.realpath(__file__))
cache_dir = os.path.join(base, "_cache")
os.makedirs(cache_dir, exist_ok=True)
cache_fn = quote_plus(
@ -233,7 +232,7 @@ async def update_arch_versions() -> None:
async def check_needs_update(_cache_key: List[str] = [""]) -> bool:
"""Raises RequestException"""
if appconfig.CACHE_LOCAL:
if appconfig.CACHE_DIR:
return True
async def get_headers(client: httpx.AsyncClient, *args: Any, **kwargs: Any) -> httpx.Headers:

8
run.py
View File

@ -1,6 +1,7 @@
# Copyright 2016-2020 Christoph Reiter
# SPDX-License-Identifier: MIT
import os
import sys
import argparse
from typing import List, Optional, Union
@ -18,7 +19,12 @@ def main(argv: List[str]) -> Optional[Union[int, str]]:
help="port number")
args = parser.parse_args()
appconfig.CACHE_LOCAL = args.cache
if args.cache:
base = os.path.dirname(os.path.realpath(__file__))
cache_dir = os.path.join(base, ".app.cache")
print(f"Using cache: {repr(cache_dir)}")
appconfig.CACHE_DIR = cache_dir
uvicorn.run(app, host="127.0.0.1", port=args.port)
return None