33 lines
725 B
Python
33 lines
725 B
Python
from __future__ import annotations
|
|
|
|
import re
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
|
|
ORDERED_TIMESTAMP_STEM_RE = re.compile(r"^(?P<timestamp>\d{8}_\d{6})-[1-9]\d*$")
|
|
|
|
|
|
def naive_wall_time(dt: datetime) -> datetime:
|
|
return dt.replace(tzinfo=None)
|
|
|
|
|
|
def format_filename_stem(dt: datetime) -> str:
|
|
return naive_wall_time(dt).strftime("%Y%m%d_%H%M%S")
|
|
|
|
|
|
def normalized_extension(path: Path) -> str:
|
|
return path.suffix.lower()
|
|
|
|
|
|
def group_stem_from_name(name: str) -> str:
|
|
stem = Path(name).stem
|
|
match = ORDERED_TIMESTAMP_STEM_RE.match(stem)
|
|
if match:
|
|
return match.group("timestamp")
|
|
return stem
|
|
|
|
|
|
def group_stem(path: Path) -> str:
|
|
return group_stem_from_name(path.name)
|