main.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import os
  2. from pathlib import Path
  3. import typer
  4. from clients import run
  5. app = typer.Typer(help="PC-Visit Filetracker")
  6. def default_session_history() -> Path:
  7. user_profile = Path(os.environ.get("USERPROFILE", str(Path.home())))
  8. return user_profile / "AppData" / "Roaming" / "pcvisit Data" / "Session History"
  9. @app.callback(invoke_without_command=True)
  10. def app_callback(context: typer.Context) -> None:
  11. """Verwalten der PC-Visit-Filetracker-Befehle."""
  12. if context.invoked_subcommand is None:
  13. typer.echo(context.get_help())
  14. @app.command()
  15. def clients(
  16. directory: Path | None = typer.Argument(None, help="Verzeichnis mit XML-Dateien"),
  17. output: Path = typer.Option(Path("clients.csv"), "--output", "-o", help="Zielpfad der CSV-Datei"),
  18. ) -> None:
  19. """Importiert Client-Daten aus Session-XML-Dateien."""
  20. directory = directory or default_session_history()
  21. try:
  22. xml_count, row_count = run(directory, output)
  23. except ValueError as error:
  24. raise typer.BadParameter(str(error), param_hint="directory") from error
  25. typer.echo(f"{xml_count} XML-Dateien gelesen, {row_count} Einträge nach {output} geschrieben.")
  26. if __name__ == "__main__":
  27. app()