syntax fix
This commit is contained in:
@@ -5,10 +5,10 @@ import argparse
|
||||
from datetime import datetime, timezone
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shlex
|
||||
import sqlite3
|
||||
import sys
|
||||
import re
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
@@ -18,19 +18,20 @@ def database_path(project_root):
|
||||
settings = {}
|
||||
env_file = project_root / ".env"
|
||||
try:
|
||||
for number, line in enumerate(env_file.read_text(encoding="utf-8-sig").splitlines(), 1):
|
||||
line = re.sub(r'^\s*export\s+', '', line).strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
if line.startswith("export "):
|
||||
line = line[7:].lstrip()
|
||||
key, separator, value = line.partition("=")
|
||||
if not separator:
|
||||
raise ValueError(f"Ungültige .env-Angabe in Zeile {number}.")
|
||||
try:
|
||||
settings[key.strip()] = " ".join(shlex.split(value, comments=True))
|
||||
except ValueError as error:
|
||||
raise ValueError(f"Ungültige .env-Anführungszeichen in Zeile {number}.") from error
|
||||
contents = env_file.read_text(encoding="utf-8-sig")
|
||||
except FileNotFoundError:
|
||||
contents = ""
|
||||
for number, line in enumerate(contents.splitlines(), 1):
|
||||
line = re.sub(r'^\s*export\s+', '', line).strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
key, separator, value = line.partition("=")
|
||||
if not separator:
|
||||
raise ValueError(f"Ungültige .env-Angabe in Zeile {number}.")
|
||||
try:
|
||||
settings[key.strip()] = " ".join(shlex.split(value, comments=True))
|
||||
except ValueError as error:
|
||||
raise ValueError(f"Ungültige .env-Anführungszeichen in Zeile {number}.") from error
|
||||
data_dir = os.environ.get("DATA_DIR", settings.get("DATA_DIR", "")) or "data"
|
||||
return (project_root / data_dir / "wegwichtel.sqlite").resolve()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user