.
This commit is contained in:
BIN
generator/__pycache__/cli.cpython-311.pyc
Normal file
BIN
generator/__pycache__/cli.cpython-311.pyc
Normal file
Binary file not shown.
BIN
generator/__pycache__/cli.cpython-38.pyc
Normal file
BIN
generator/__pycache__/cli.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
78
generator/cli.py
Normal file
78
generator/cli.py
Normal file
@ -0,0 +1,78 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
import havelseiten as builder
|
||||
import settings_config
|
||||
import validate
|
||||
|
||||
|
||||
ROOT_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
def format_command() -> int:
|
||||
changed = settings_config.format_settings_file()
|
||||
settings_file = settings_config.active_settings_file()
|
||||
|
||||
if not settings_file:
|
||||
print("Keine Einstellungsdatei gefunden.")
|
||||
return 1
|
||||
|
||||
path = settings_file.relative_to(ROOT_DIR)
|
||||
|
||||
if changed:
|
||||
print(f"formatiert: {path}")
|
||||
else:
|
||||
print(f"bereits formatiert: {path}")
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def validate_command() -> int:
|
||||
return validate.main()
|
||||
|
||||
|
||||
def build_command() -> int:
|
||||
builder.build_site(format_settings=True)
|
||||
return 0
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="havelseiten",
|
||||
description="Havelseiten formatieren, pruefen und bauen."
|
||||
)
|
||||
subparsers = parser.add_subparsers(dest="command", required=True)
|
||||
|
||||
subparsers.add_parser(
|
||||
"format",
|
||||
help="havelseite/einstellungen.md formatieren"
|
||||
)
|
||||
subparsers.add_parser(
|
||||
"validate",
|
||||
help="Einstellungen und Markdown-Dateien pruefen"
|
||||
)
|
||||
subparsers.add_parser(
|
||||
"build",
|
||||
help="Website nach ausgabe/ bauen"
|
||||
)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
if args.command == "format":
|
||||
return format_command()
|
||||
|
||||
if args.command == "validate":
|
||||
return validate_command()
|
||||
|
||||
if args.command == "build":
|
||||
return build_command()
|
||||
|
||||
parser.print_help()
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
@ -94,9 +94,8 @@ def load_settings() -> dict:
|
||||
SETTINGS = DEFAULT_SETTINGS
|
||||
|
||||
|
||||
def run_validation():
|
||||
settings_config.format_settings_file()
|
||||
messages, language = validate.collect_messages()
|
||||
def run_validation(format_settings: bool = True):
|
||||
messages, language = validate.collect_messages(format_settings=format_settings)
|
||||
|
||||
if not messages:
|
||||
print(validate.tr(language, "ok"))
|
||||
@ -1643,10 +1642,10 @@ def copy_content_media():
|
||||
)
|
||||
|
||||
|
||||
def build_site():
|
||||
def build_site(format_settings: bool = True):
|
||||
global SETTINGS
|
||||
|
||||
run_validation()
|
||||
run_validation(format_settings=format_settings)
|
||||
SETTINGS = load_settings()
|
||||
|
||||
if OUTPUT_DIR.exists():
|
||||
|
||||
@ -793,9 +793,12 @@ def validate_media_parameter(
|
||||
))
|
||||
|
||||
|
||||
def collect_messages() -> tuple[list[str], str]:
|
||||
def collect_messages(format_settings: bool = True) -> tuple[list[str], str]:
|
||||
messages: list[str] = []
|
||||
settings_config.format_settings_file()
|
||||
|
||||
if format_settings:
|
||||
settings_config.format_settings_file()
|
||||
|
||||
language = language_from_settings()
|
||||
|
||||
validate_settings(messages, language)
|
||||
|
||||
Reference in New Issue
Block a user