From: John Mulligan Date: Tue, 26 Sep 2023 16:56:35 +0000 (-0400) Subject: cephadm: move pathify & get_file_timestamp to file_utils X-Git-Tag: v19.0.0~386^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3013780ea1030f7695c92b062c7100b135afdb24;p=ceph.git cephadm: move pathify & get_file_timestamp to file_utils Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 30a824f2983a5..f2fff9409b632 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 1ce4a6d399871..7c9e6f69e4341 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