#!@PYTHON@
import os
import os.path
import sys

CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))

# We prevent to import some module from this dir instead of e.g. standard
# module. There is no reason to import anything from this module.
sys.path.remove(CURRENT_DIR)

TEST_INSTALLED = os.environ.get("PCS_TEST.TEST_INSTALLED", "0") == "1"
PACKAGE_DIR = os.path.dirname(CURRENT_DIR)

if not TEST_INSTALLED:
    # Add pcs package.
    sys.path.insert(0, PACKAGE_DIR)
    BUNDLED_PACKAGES_DIR = os.path.join(PACKAGE_DIR, "@PCS_BUNDLED_DIR_LOCAL@", "packages")
    sys.path.insert(0, BUNDLED_PACKAGES_DIR)

if "BUNDLED_LIB_LOCATION" in os.environ:
    sys.path.insert(0, os.environ["BUNDLED_LIB_LOCATION"])

# pylint: disable=wrong-import-position
from pcs import settings

if TEST_INSTALLED:
    sys.path.insert(0, settings.pcs_bundled_packages_dir)
else:
    settings.pcsd_exec_location = os.path.join(PACKAGE_DIR, "pcsd")

settings.corosync_conf_file = None
settings.corosync_uidgid_dir = None
prefix = "PCS.SETTINGS."

for opt, val in os.environ.items():
    if opt.startswith(prefix):
        setattr(settings, opt[len(prefix):], val)

from pcs import app
app.main(sys.argv[1:])
