From 3013780ea1030f7695c92b062c7100b135afdb24 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 26 Sep 2023 12:56:35 -0400 Subject: [PATCH] cephadm: move pathify & get_file_timestamp to file_utils Signed-off-by: John Mulligan --- src/cephadm/cephadm.py | 19 ++----------------- src/cephadm/cephadmlib/file_utils.py | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 30a824f2983..f2fff9409b6 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -107,7 +107,9 @@ from cephadmlib.data_utils import ( with_units_to_int, ) from cephadmlib.file_utils import ( + get_file_timestamp, makedirs, + pathify, populate_files, read_file, recursive_chown, @@ -1404,23 +1406,6 @@ def read_config(fn): return cp -def pathify(p): - # type: (str) -> str - p = os.path.expanduser(p) - return os.path.abspath(p) - - -def get_file_timestamp(fn): - # type: (str) -> Optional[str] - try: - mt = os.path.getmtime(fn) - return datetime.datetime.fromtimestamp( - mt, tz=datetime.timezone.utc - ).strftime(DATEFMT) - except Exception: - return None - - def try_convert_datetime(s): # type: (str) -> Optional[str] # This is super irritating because diff --git a/src/cephadm/cephadmlib/file_utils.py b/src/cephadm/cephadmlib/file_utils.py index 1ce4a6d3998..7c9e6f69e43 100644 --- a/src/cephadm/cephadmlib/file_utils.py +++ b/src/cephadm/cephadmlib/file_utils.py @@ -1,6 +1,7 @@ # file_utils.py - generic file and directory utility functions +import datetime import logging import os import tempfile @@ -9,7 +10,7 @@ from contextlib import contextmanager from pathlib import Path from typing import Dict, Any, Union, Tuple, Optional, Generator, IO, List -from .constants import DEFAULT_MODE +from .constants import DEFAULT_MODE, DATEFMT from .data_utils import dict_get_join logger = logging.getLogger() @@ -121,3 +122,20 @@ def read_file(path_list, file_name=''): else: return content return 'Unknown' + + +def pathify(p): + # type: (str) -> str + p = os.path.expanduser(p) + return os.path.abspath(p) + + +def get_file_timestamp(fn): + # type: (str) -> Optional[str] + try: + mt = os.path.getmtime(fn) + return datetime.datetime.fromtimestamp( + mt, tz=datetime.timezone.utc + ).strftime(DATEFMT) + except Exception: + return None -- 2.39.5