#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
 (c) 2018 - Copyright Red Hat Inc

 Authors:
   Patrick Uiterwijk <puiterwijk@redhat.com>

 Notes:
   If you've installed Pagure with a virtual environment, replace the
   interpreter path like this:

   #!/path/to/pagure_env/bin/python

"""

from __future__ import unicode_literals, absolute_import

import os
import sys

# The following is only needed if you did not install pagure
# as a python module (for example if you run it from a git clone).
#sys.path.insert(0, '/path/to/pagure/')

if os.environ.get("internal_no_hooks", False):
    # we do this check before any pagure machinery is imported
    # and initialized to make sure this is very fast (used
    # when pushing code from original repos to forks)
    sys.exit(0)

if "PAGURE_CONFIG" not in os.environ and os.path.exists(
    "/etc/pagure/pagure.cfg"
):
    os.environ["PAGURE_CONFIG"] = "/etc/pagure/pagure.cfg"

import pagure.lib
import pagure.utils
from pagure.config import config as pagure_config
from pagure.hooks import run_hook_file

confkey = "LOGGING_GIT_HOOKS" if "LOGGING_GIT_HOOKS" in pagure_config else "LOGGING"

pagure.utils.set_up_logging(configkey=confkey)
hooktype = os.path.basename(sys.argv[0])

run_hook_file(hooktype)
