d
This commit is contained in:
11
SYS/utils.py
11
SYS/utils.py
@@ -11,11 +11,12 @@ try:
|
||||
import ffmpeg # type: ignore
|
||||
except Exception:
|
||||
ffmpeg = None # type: ignore
|
||||
import os
|
||||
import base64
|
||||
import logging
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Any, Iterable
|
||||
from typing import Any, Iterable, Optional
|
||||
from datetime import datetime
|
||||
from dataclasses import dataclass, field
|
||||
from fnmatch import fnmatch
|
||||
@@ -32,6 +33,14 @@ CHUNK_SIZE = 1024 * 1024 # 1 MiB
|
||||
_format_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def expand_path(p: str | Path | None) -> Path:
|
||||
"""Expand ~ and environment variables in path."""
|
||||
if p is None:
|
||||
return None # type: ignore
|
||||
expanded = os.path.expandvars(str(p))
|
||||
return Path(expanded).expanduser()
|
||||
|
||||
|
||||
def ensure_directory(path: Path) -> None:
|
||||
"""Ensure *path* exists as a directory."""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user