-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
31 lines (21 loc) · 836 Bytes
/
Copy pathutils.py
File metadata and controls
31 lines (21 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
utils.py
Helper functions used across the SOC Log Analyzer project.
"""
import os
from datetime import datetime
def ensure_dir(path: str) -> None:
"""Create a directory if it doesn't already exist."""
os.makedirs(path, exist_ok=True)
def read_lines(filepath: str):
"""Read a log file and return a list of non-empty lines."""
if not os.path.isfile(filepath):
raise FileNotFoundError(f"Log file not found: {filepath}")
with open(filepath, "r", encoding="utf-8", errors="ignore") as f:
return [line.rstrip("\n") for line in f if line.strip()]
def timestamp() -> str:
"""Return a human-readable timestamp for reports."""
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def severity_label(level: str) -> str:
"""Normalize severity labels."""
return level.strip().upper()