From ebcf3c79ff4ca1f88a961252231ce6712664458f Mon Sep 17 00:00:00 2001 From: Kayou Date: Wed, 17 Jul 2024 16:45:43 +0200 Subject: [PATCH] Fix "log list" : use root_dir for iglob / make sure we use absolute paths (#1913) * use root_dir for iglob, fix parent_symlink path and check if it exists * fix log path * do not try to read a yaml of a symlink to /dev/null * use hidden files, needs python 3.11 (bookworm) * don't worry, I'm an expert! * Update log.py: log_file -> log_md_fullpath (otherwise it feel like log_file refers to the .log) * Update log.py: remove debug statement * Update log.py: revert unecessary if change --------- Co-authored-by: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> --- src/log.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/log.py b/src/log.py index 1e116baf1..7e17d527e 100755 --- a/src/log.py +++ b/src/log.py @@ -87,9 +87,10 @@ def _update_log_parent_symlinks(): one_year_ago = time.time() - 365 * 24 * 3600 - logs = glob.iglob(OPERATIONS_PATH + "*" + METADATA_FILE_EXT) + logs = glob.iglob("*" + METADATA_FILE_EXT, root_dir=OPERATIONS_PATH) for log_md in logs: - if os.path.getctime(log_md) < one_year_ago: + log_md_fullpath = os.path.join(OPERATIONS_PATH, log_md) + if os.path.getctime(log_md_fullpath) < one_year_ago: # Let's ignore files older than one year because hmpf reading a shitload of yml is not free continue @@ -100,7 +101,7 @@ def _update_log_parent_symlinks(): try: metadata = ( - read_yaml(log_md) or {} + read_yaml(log_md_fullpath) or {} ) # Making sure this is a dict and not None..? except Exception as e: # If we can't read the yaml for some reason, report an error and ignore this entry... @@ -110,7 +111,6 @@ def _update_log_parent_symlinks(): parent = metadata.get("parent") parent = parent + METADATA_FILE_EXT if parent else "/dev/null" try: - print(parent, parent_symlink) os.symlink(parent, parent_symlink) except Exception as e: logger.warning(f"Failed to create symlink {parent_symlink} ? {e}")