#!/usr/bin/python3
"""Entry point of the Python port of sophomorix-objectsearch (called by the dispatcher)."""
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.search_cli import main  # noqa: E402
from sophomorix_py.runtime import R  # noqa: E402

try:
    raise SystemExit(main('objectsearch', sys.argv[1:]))
except SystemExit as e:
    R.flush()
    raise
except (OSError, RuntimeError, ValueError) as error:
    R.err('sophomorix-objectsearch: ' + str(error) + '\n')
    R.flush()
    raise SystemExit(1)
