From 03d33d4fa91c02c4fbaca3d1ed4bb9850124ed0f Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Mon, 20 May 2024 13:23:06 +0200 Subject: utils: cache: redefine cache path constants Rename OGIMG as OG_IMAGE_PATH. Rename OGCACHE_MOUNTPOINT as OG_CACHE_PATH. Define OG_CACHE_IMAGE_PATH as OG_CACHE_PATH + OG_IMAGE_PATH. This will serve to have a unique point to obtain cache related paths. --- src/utils/cache.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/utils/cache.py b/src/utils/cache.py index b60b5be..374f8e0 100644 --- a/src/utils/cache.py +++ b/src/utils/cache.py @@ -13,8 +13,9 @@ from src.utils.fs import mount_mkdir, umount from src.utils.net import getifaddr from src.utils.probe import get_cache_dev_path -OGIMG='/opt/opengnsys/images/' -OGCACHE_MOUNTPOINT='/opt/opengnsys/cache' +OG_IMAGE_PATH = '/opt/opengnsys/images/' +OG_CACHE_PATH = '/opt/opengnsys/cache' +OG_CACHE_IMAGE_PATH = OG_CACHE_PATH + OG_IMAGE_PATH OGCLIENT_LOG_CACHE='/opt/opengnsys/log/{ip}.cache.txt' def mount_cache(): @@ -27,18 +28,18 @@ def mount_cache(): if cache_dev: # cache_target = cache_dev.replace('dev', 'mnt') - mount_mkdir(cache_dev, OGCACHE_MOUNTPOINT) - return OGCACHE_MOUNTPOINT + mount_mkdir(cache_dev, OG_CACHE_PATH) + return OG_CACHE_PATH return '' def umount_cache(): """ - If OGCACHE_MOUNTPOINT is a mountpoint, umounts. + If OG_CACHE_PATH is a mountpoint, umounts. If not, does nothing. """ - if os.path.ismount(OGCACHE_MOUNTPOINT): - umount(OGCACHE_MOUNTPOINT) + if os.path.ismount(OG_CACHE_PATH): + umount(OG_CACHE_PATH) def write_cache_txt(content): """ @@ -63,7 +64,7 @@ def generate_cache_txt(): if cache_path: try: - files = os.listdir(f'{cache_path}{OGIMG}') + files = os.listdir(f'{cache_path}{OG_IMAGE_PATH}') except FileNotFoundError: return content = ','.join(files) -- cgit v1.2.3-18-g5258