#!/usr/bin/env python
#
# $LicenseInfo:firstyear=2010&license=mit$
# Copyright (c) 2010, Linden Research, Inc.
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# $/LicenseInfo$

"""
Command to manage the creation and installation of package archives.
"""

import sys
import logging
import os

script_path = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
lib_path = os.path.dirname(script_path)
if os.path.exists(os.path.join(lib_path, 'autobuild', '__init__.py')):
    if not lib_path in sys.path:
        sys.path.insert(0, lib_path)
from autobuild.autobuild_main import Autobuild
from autobuild.common import AutobuildError

if __name__ == "__main__":
    logger = logging.getLogger('autobuild')
    try:
        os.environ['PATH'] = os.environ.get('PATH') + os.pathsep + script_path
        sys.exit( Autobuild().main(sys.argv[1:]) )
    except KeyboardInterrupt, e:
        sys.exit("Aborted...")
    except AutobuildError, e:
        if logger.getEffectiveLevel() <= logging.DEBUG:
            logger.exception(str(e))
        sys.exit("ERROR: %s\nFor more information: try re-running your command with --verbose or --debug" % e)

