#!python
# coding: utf-8
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===========================================================================
"""deployer entry"""
import os
import sys
import subprocess
import ascend_deployer.downloader as d

if __name__ == '__main__':
    root_path = os.path.dirname(os.path.dirname(d.__file__))
    if 'site-packages' not in root_path and 'dist-packages' not in root_path:
        script = os.path.join(root_path, "install.sh")
        subprocess.call([script] + sys.argv[1:])
        sys.exit(0)

    d.copy_scripts()

    deployer_home = os.getenv('HOME')
    if os.getenv('ASCEND_DEPLOYER_HOME') is not None:
        deployer_home = os.getenv('ASCEND_DEPLOYER_HOME')
    ad_path= os.path.join(deployer_home, 'ascend-deployer')

    script = os.path.join(ad_path, "install.sh")
    subprocess.call([script] + sys.argv[1:])
