예제 #1
0
def install_pkg(env_root, bsp_root, pkg):
    """Install the required packages."""

    # default true
    ret = True
    local_pkgs_path = os.path.join(env_root, 'local_pkgs')
    bsp_pkgs_path = os.path.join(bsp_root, 'packages')

    # get the .config file from env
    env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
    env_config_file = os.path.join(env_kconfig_path, '.config')

    package = Package()
    pkg_path = pkg['path']
    if pkg_path[0] == '/' or pkg_path[0] == '\\':
        pkg_path = pkg_path[1:]
    pkg_path = os.path.join(env_root, 'packages', pkg_path, 'package.json')
    package.parse(pkg_path)

    url_from_json = package.get_url(pkg['ver'])
    package_url = package.get_url(pkg['ver'])
    pkgs_name_in_json = package.get_name()

    if package_url[-4:] == '.git':
        ver_sha = package.get_versha(pkg['ver'])

    # print("==================================================>")
    # print("packages name :"%pkgs_name_in_json.encode("utf-8"))
    # print("ver :"%pkg['ver'])
    # print("url :"%package_url.encode("utf-8"))
    # print("url_from_json : "%url_from_json.encode("utf-8"))
    # print("==================================================>")

    get_package_url = None
    get_ver_sha = None
    upstream_change_flag = False

    try:
        if (not os.path.isfile(env_config_file)) or (
                os.path.isfile(env_config_file) and find_macro_in_config(
                    env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE')):
            get_package_url, get_ver_sha = get_url_from_mirror_server(
                pkgs_name_in_json, pkg['ver'])

            #  determine whether the package package url is valid
            if get_package_url != None and determine_url_valid(
                    get_package_url):
                package_url = get_package_url

                if get_ver_sha != None:
                    ver_sha = get_ver_sha

                upstream_change_flag = True
    except Exception, e:
        # print('e.message:%s\t' % e.message)
        print(
            "Failed to connect to the mirror server, package will be downloaded from non-mirror server.\n"
        )
예제 #2
0
def install_pkg(env_root, bsp_root, pkg):
    ret = True
    local_pkgs_path = os.path.join(env_root, 'local_pkgs')
    bsp_pkgs_path = os.path.join(bsp_root, 'packages')

    package = Package()
    pkg_path = pkg['path']
    if pkg_path[0] == '/' or pkg_path[0] == '\\': pkg_path = pkg_path[1:]

    #pkg_path = pkg_path.replace('/', '\\')
    pkg_path = os.path.join(env_root, 'packages', pkg_path, 'package.json')

    package.parse(pkg_path)

    package_url = package.get_url(pkg['ver'])
    package_name = pkg['name']
    pkgs_name_in_json = package.get_name()

    #print "get name here:",pkgs_name_in_json
    #print "ver:",pkg['ver']
    #print "url:",package_url
    #print "name:",package_name

    beforepath = os.getcwd()

    if package_url[-4:] == '.git':
        ver_sha = package.get_versha(pkg['ver'])
        repo_path = os.path.join(bsp_pkgs_path, pkgs_name_in_json)
        cmd = 'git clone ' + package_url + ' ' + repo_path
        os.system(cmd)
        os.chdir(repo_path)
        cmd = 'git checkout ' + ver_sha
        os.system(cmd)
        cmd = 'git submodule init '
        os.system(cmd)
        cmd = 'git submodule update '
        if not os.system(cmd):
            print "Submodule update success"
        os.chdir(beforepath)
    else:
        # download package
        if not package.download(pkg['ver'], local_pkgs_path):
            ret = False
            return ret

        pkg_dir = package.get_filename(pkg['ver'])
        pkg_dir = os.path.splitext(pkg_dir)[0]

        pkg_fullpath = os.path.join(local_pkgs_path,
                                    package.get_filename(pkg['ver']))

        # unpack package
        if not os.path.exists(pkg_dir):
            package.unpack(pkg_fullpath, bsp_pkgs_path)
            ret = True

    return ret
예제 #3
0
def update_latest_packages(pkgs_fn, bsp_packages_path):
    """ update the packages that are latest version.

    If the selected package is the latest version,
    check to see if it is the latest version after the update command,
    if not, then update the latest version from the remote repository.
    If the download has a conflict, you are currently using the prompt
    message provided by git.
    """

    env_root = Import('env_root')

    env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
    env_config_file = os.path.join(env_kconfig_path, '.config')

    with open(pkgs_fn, 'r') as f:
        read_back_pkgs_json = json.load(f)

    for pkg in read_back_pkgs_json:
        package = Package()
        pkg_path = pkg['path']
        if pkg_path[0] == '/' or pkg_path[0] == '\\':
            pkg_path = pkg_path[1:]

        pkg_path = os.path.join(env_root, 'packages', pkg_path, 'package.json')
        package.parse(pkg_path)
        pkgs_name_in_json = package.get_name()

        # Find out the packages which version is 'latest'
        if pkg['ver'] == "latest_version" or pkg['ver'] == "latest":
            repo_path = os.path.join(bsp_packages_path, pkgs_name_in_json)
            repo_path = get_pkg_folder_by_orign_path(repo_path, pkg['ver'])

            # If mirror acceleration is enabled, get the update address from
            # the mirror server.
            if os.path.isfile(env_config_file) and find_macro_in_config(
                    env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE'):
                payload_pkgs_name_in_json = pkgs_name_in_json.encode("utf-8")

                # Change repo's upstream address.
                mirror_url = get_url_from_mirror_server(
                    payload_pkgs_name_in_json, pkg['ver'])

                # print(os.getcwd())
                # print(repo_path)

                if mirror_url[0] != None:
                    cmd = 'git remote set-url origin ' + mirror_url[0]
                    git_cmd_exec(cmd, repo_path)

            # Update the package repository from upstream.
            cmd = 'git pull'
            git_cmd_exec(cmd, repo_path)

            # If the package has submodules, update the submodules.
            update_submodule(repo_path)

            # recover origin url to the path which get from packages.json file
            if package.get_url(pkg['ver']):
                cmd = 'git remote set-url origin ' + \
                    package.get_url(pkg['ver'])
                git_cmd_exec(cmd, repo_path)
            else:
                print("Can't find the package : %s's url in file : %s" %
                      (payload_pkgs_name_in_json, pkg_path))

            print("==============================>  %s update done \n" %
                  (pkgs_name_in_json))
예제 #4
0
def install_pkg(env_root, bsp_root, pkg):
    """Install the required packages."""

    # default true
    ret = True
    local_pkgs_path = os.path.join(env_root, 'local_pkgs')
    bsp_pkgs_path = os.path.join(bsp_root, 'packages')

    env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
    # get the .config file from env
    env_config_file = os.path.join(env_kconfig_path, '.config')

    package = Package()
    pkg_path = pkg['path']
    if pkg_path[0] == '/' or pkg_path[0] == '\\':
        pkg_path = pkg_path[1:]
    pkg_path = os.path.join(env_root, 'packages', pkg_path, 'package.json')
    package.parse(pkg_path)

    url_from_json = package.get_url(pkg['ver'])
    package_url = package.get_url(pkg['ver'])
    #package_name = pkg['name']
    pkgs_name_in_json = package.get_name()

    if package_url[-4:] == '.git':
        ver_sha = package.get_versha(pkg['ver'])

    # print("==================================================>")
    # print "packages name:",pkgs_name_in_json
    # print "ver:",pkg['ver']
    # print "url:",package_url
    # print "url_from_json: ",url_from_json
    # print("==================================================>")

    get_package_url = None
    get_ver_sha = None
    upstream_change_flag = False

    if os.path.isfile(env_config_file) and find_macro_in_config(
            env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE'):
        get_package_url, get_ver_sha = get_url_from_mirror_server(
            pkgs_name_in_json, pkg['ver'])

        #  determine whether the package package url is valid
        if get_package_url != None and determine_url_valid(get_package_url):
            package_url = get_package_url

            if get_ver_sha != None:
                ver_sha = get_ver_sha

            upstream_change_flag = True

    if package_url[-4:] == '.git':

        repo_path = os.path.join(bsp_pkgs_path, pkgs_name_in_json)
        repo_path = repo_path + '-' + pkg['ver']

        cmd = 'git clone ' + package_url + ' ' + repo_path
        execute_command(cmd, cwd=bsp_pkgs_path)

        cmd = 'git checkout -q ' + ver_sha
        execute_command(cmd, cwd=repo_path)

        if upstream_change_flag:
            cmd = 'git remote set-url origin ' + url_from_json
            execute_command(cmd, cwd=repo_path)

        # If there is a .gitmodules file in the package, prepare to update the
        # submodule.
        submod_path = os.path.join(repo_path, '.gitmodules')
        if os.path.isfile(submod_path):
            print("Start to update submodule")

            if os.path.isfile(env_config_file) and find_macro_in_config(
                    env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE'):
                replace_list = modify_submod_file_to_mirror(
                    submod_path)  # Modify .gitmodules file

            cmd = 'git submodule update --init --recursive'
            execute_command(cmd, cwd=repo_path)

            if os.path.isfile(env_config_file) and find_macro_in_config(
                    env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE'):
                if len(replace_list):
                    for item in replace_list:
                        submod_dir_path = os.path.join(repo_path, item[2])
                        if os.path.isdir(submod_dir_path):
                            cmd = 'git remote set-url origin ' + item[0]
                            execute_command(cmd, cwd=submod_dir_path)

        if os.path.isfile(env_config_file) and find_macro_in_config(
                env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE'):
            if os.path.isfile(submod_path):
                cmd = 'git checkout .gitmodules'
                execute_command(cmd, cwd=repo_path)

    else:
        # Download a package of compressed package type.
        if not package.download(pkg['ver'], local_pkgs_path, package_url):
            return False

        pkg_dir = package.get_filename(pkg['ver'])
        pkg_dir = os.path.splitext(pkg_dir)[0]
        pkg_fullpath = os.path.join(local_pkgs_path,
                                    package.get_filename(pkg['ver']))

        if not archive.packtest(pkg_fullpath):
            return False

        # unpack package
        if not os.path.exists(pkg_dir):
            try:
                if not package.unpack(pkg_fullpath, bsp_pkgs_path, pkg,
                                      pkgs_name_in_json):
                    ret = False
            except Exception, e:
                os.remove(pkg_fullpath)
                ret = False
                print('e.message: %s\t' % e.message)
예제 #5
0
def install_pkg(env_root, pkgs_root, bsp_root, pkg):
    """Install the required packages."""

    # default true
    ret = True
    local_pkgs_path = os.path.join(env_root, 'local_pkgs')
    bsp_pkgs_path = os.path.join(bsp_root, 'packages')

    # get the .config file from env
    env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
    env_config_file = os.path.join(env_kconfig_path, '.config')

    package = Package()
    pkg_path = pkg['path']
    if pkg_path[0] == '/' or pkg_path[0] == '\\':
        pkg_path = pkg_path[1:]
    pkg_path = os.path.join(pkgs_root, pkg_path, 'package.json')
    package.parse(pkg_path)

    url_from_json = package.get_url(pkg['ver'])
    package_url = package.get_url(pkg['ver'])
    pkgs_name_in_json = package.get_name()

    if package_url[-4:] == '.git':
        ver_sha = package.get_versha(pkg['ver'])

    # print("==================================================>")
    # print("packages name :"%pkgs_name_in_json.encode("utf-8"))
    # print("ver :"%pkg['ver'])
    # print("url :"%package_url.encode("utf-8"))
    # print("url_from_json : "%url_from_json.encode("utf-8"))
    # print("==================================================>")

    get_package_url = None
    get_ver_sha = None
    upstream_change_flag = False

    try:
        if (not os.path.isfile(env_config_file)) or (
                os.path.isfile(env_config_file) and find_macro_in_config(
                    env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE')):
            get_package_url, get_ver_sha = get_url_from_mirror_server(
                pkgs_name_in_json, pkg['ver'])

            #  determine whether the package package url is valid
            if get_package_url != None and determine_url_valid(
                    get_package_url):
                package_url = get_package_url

                if get_ver_sha != None:
                    ver_sha = get_ver_sha

                upstream_change_flag = True
    except Exception as e:
        print('error message:%s\t' % e)
        print(
            "Failed to connect to the mirror server, package will be downloaded from non-mirror server.\n"
        )

    if package_url[-4:] == '.git':
        try:
            repo_path = os.path.join(bsp_pkgs_path, pkgs_name_in_json)
            repo_path = repo_path + '-' + pkg['ver']
            repo_path_full = '"' + repo_path + '"'

            clone_cmd = 'git clone ' + package_url + ' ' + repo_path_full
            execute_command(clone_cmd, cwd=bsp_pkgs_path)

            git_check_cmd = 'git checkout -q ' + ver_sha
            execute_command(git_check_cmd, cwd=repo_path)

        except Exception as e:
            print(
                "\nFailed to download software package with git. Please check the network connection."
            )
            os.chdir(before)
            return False

        if upstream_change_flag:
            cmd = 'git remote set-url origin ' + url_from_json
            execute_command(cmd, cwd=repo_path)

        # If there is a .gitmodules file in the package, prepare to update submodule.
        submod_path = os.path.join(repo_path, '.gitmodules')
        if os.path.isfile(submod_path):
            print("Start to update submodule")
            # print("开始更新软件包子模块")

            if (not os.path.isfile(env_config_file)) or (
                    os.path.isfile(env_config_file) and find_macro_in_config(
                        env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE')):
                # print("开启了镜像加速,开始修改 .gitmodules 文件")
                replace_list = modify_submod_file_to_mirror(
                    submod_path)  # Modify .gitmodules file

            # print("开始执行更新动作")
            cmd = 'git submodule update --init --recursive'
            execute_command(cmd, cwd=repo_path)

            if (not os.path.isfile(env_config_file)) or (
                    os.path.isfile(env_config_file) and find_macro_in_config(
                        env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE')):
                if len(replace_list):
                    for item in replace_list:
                        submod_dir_path = os.path.join(repo_path, item[2])
                        if os.path.isdir(submod_dir_path):
                            cmd = 'git remote set-url origin ' + item[0]
                            execute_command(cmd, cwd=submod_dir_path)

        if (not os.path.isfile(env_config_file)) or (
                os.path.isfile(env_config_file) and find_macro_in_config(
                    env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE')):
            if os.path.isfile(submod_path):
                cmd = 'git checkout .gitmodules'
                execute_command(cmd, cwd=repo_path)

    else:
        # Download a package of compressed package type.
        if not package.download(pkg['ver'], local_pkgs_path, package_url):
            return False

        pkg_dir = package.get_filename(pkg['ver'])
        pkg_dir = os.path.splitext(pkg_dir)[0]
        pkg_fullpath = os.path.join(local_pkgs_path,
                                    package.get_filename(pkg['ver']))

        if not archive.packtest(pkg_fullpath):
            print("package : %s is invalid" % pkg_fullpath.encode("utf-8"))
            return False

        # unpack package
        if not os.path.exists(pkg_dir):

            try:
                if not package.unpack(pkg_fullpath, bsp_pkgs_path, pkg,
                                      pkgs_name_in_json):
                    ret = False
            except Exception as e:
                os.remove(pkg_fullpath)
                ret = False
                print('error message: %s\t' % e)
        else:
            print("The file does not exist.")
    return ret