#!/usr/bin/python2.7
import os
import sys

HERE = os.path.dirname(os.path.abspath(__file__))
SRC = os.path.join(os.path.dirname(HERE), 'src')

sys.path.insert(0, SRC)


def main(dist='custodia', group='console_scripts', name='custodia'):
    # delay pkg_resources after sys.path changes
    import pkg_resources
    pkg_resources.working_set.add_entry(SRC)
    ep = pkg_resources.get_entry_info(dist, group, name)
    if os.path.normpath(ep.dist.location) != os.path.normpath(SRC):
        raise RuntimeError(ep.dist.location)
    if hasattr(ep, 'resolve'):
        func = ep.resolve()
    else:
        func = ep.load(require=False)
    sys.exit(func())

if __name__ == '__main__':
    main()
