]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: move pathify & get_file_timestamp to file_utils 53682/head
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 26 Sep 2023 16:56:35 +0000 (12:56 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 26 Sep 2023 16:56:35 +0000 (12:56 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py
src/cephadm/cephadmlib/file_utils.py

index 30a824f2983a55a87bb115abdf65242a42aaa158..f2fff9409b63235fef2aec5e5c86ec175d32ace6 100755 (executable)
@@ -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
index 1ce4a6d399871e234a9814cb57b89db5146bcbbc..7c9e6f69e43415bb42f0837e6da40987afe7d61d 100644 (file)
@@ -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