#!/usr/bin/python
#   Copyright (C) 2013 Canonical Ltd.
#
#   Author: Scott Moser <scott.moser@canonical.com>
#
#   Curtin is free software: you can redistribute it and/or modify it under
#   the terms of the GNU Affero General Public License as published by the
#   Free Software Foundation, either version 3 of the License, or (at your
#   option) any later version.
#
#   Curtin is distributed in the hope that it will be useful, but WITHOUT ANY
#   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#   FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
#   more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with Curtin.  If not, see <http://www.gnu.org/licenses/>.

import os
import sys


def call_entry_point(name):
    (istr, dot, ent) = name.rpartition('.')
    try:
        __import__(istr)
    except ImportError:
        # if that import failed, check dirname(__file__/..)
        # to support ./bin/curtin with modules in .
        _tdir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
        sys.path.append(_tdir)
        try:
            __import__(istr)
        except ImportError:
            sys.stderr.write("Unable to find %s\n" % name)
            sys.exit(2)

    sys.exit(getattr(sys.modules[istr], ent)())

if __name__ == '__main__':
    call_entry_point("curtin.commands.main.main")

# vi: ts=4 expandtab syntax=python
