#!/usr/bin/python3
"""Dispatcher entry point for sophomorix-newfile."""
import os
import sys
sys.path.insert(0, '/usr/share/sophomorix-nextgen')

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
for stream in (sys.stdout, sys.stderr):
    stream.reconfigure(encoding="utf-8", errors="surrogateescape")

from sophomorix_py.newfile_cli import main  # noqa: E402
from sophomorix_py.runtime import R  # noqa: E402

R.argv0 = os.environ.get("SOPHOMORIX_ARGV0", "/usr/sbin/sophomorix-newfile")
try:
    sys.exit(main(sys.argv[1:]))
finally:
    R.flush()
