Move the cache dir to the top level directory
This commit is contained in:
parent
24bfec26a1
commit
7f7bb0aee4
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,4 +5,5 @@ node_modules
|
|||||||
*srcinfo.json
|
*srcinfo.json
|
||||||
.mypy_cache
|
.mypy_cache
|
||||||
_cache
|
_cache
|
||||||
.vscode
|
.vscode
|
||||||
|
*.cache
|
||||||
@ -1,6 +1,9 @@
|
|||||||
# Copyright 2016-2020 Christoph Reiter
|
# Copyright 2016-2020 Christoph Reiter
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
REPO_URL = "https://repo.msys2.org"
|
REPO_URL = "https://repo.msys2.org"
|
||||||
|
|
||||||
REPOSITORIES = [
|
REPOSITORIES = [
|
||||||
@ -53,4 +56,4 @@ BUILD_STATUS_CONFIG = [
|
|||||||
|
|
||||||
UPDATE_INTERVAL = 60 * 5
|
UPDATE_INTERVAL = 60 * 5
|
||||||
REQUEST_TIMEOUT = 60
|
REQUEST_TIMEOUT = 60
|
||||||
CACHE_LOCAL = False
|
CACHE_DIR: Optional[str] = None
|
||||||
|
|||||||
@ -31,13 +31,12 @@ def get_update_urls() -> List[str]:
|
|||||||
|
|
||||||
|
|
||||||
async def get_content_cached(url: str, *args: Any, **kwargs: Any) -> bytes:
|
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:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await client.get(url, *args, **kwargs)
|
r = await client.get(url, *args, **kwargs)
|
||||||
return r.content
|
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)
|
os.makedirs(cache_dir, exist_ok=True)
|
||||||
|
|
||||||
cache_fn = quote_plus(
|
cache_fn = quote_plus(
|
||||||
@ -233,7 +232,7 @@ async def update_arch_versions() -> None:
|
|||||||
async def check_needs_update(_cache_key: List[str] = [""]) -> bool:
|
async def check_needs_update(_cache_key: List[str] = [""]) -> bool:
|
||||||
"""Raises RequestException"""
|
"""Raises RequestException"""
|
||||||
|
|
||||||
if appconfig.CACHE_LOCAL:
|
if appconfig.CACHE_DIR:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def get_headers(client: httpx.AsyncClient, *args: Any, **kwargs: Any) -> httpx.Headers:
|
async def get_headers(client: httpx.AsyncClient, *args: Any, **kwargs: Any) -> httpx.Headers:
|
||||||
|
|||||||
8
run.py
8
run.py
@ -1,6 +1,7 @@
|
|||||||
# Copyright 2016-2020 Christoph Reiter
|
# Copyright 2016-2020 Christoph Reiter
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
@ -18,7 +19,12 @@ def main(argv: List[str]) -> Optional[Union[int, str]]:
|
|||||||
help="port number")
|
help="port number")
|
||||||
args = parser.parse_args()
|
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)
|
uvicorn.run(app, host="127.0.0.1", port=args.port)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user