Пример #1
0
def upgrade_env_script():
    """Update env function scripts."""

    print("Begin to upgrade env scripts.")
    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')
    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(
            'env', 'latest')
        if get_package_url != None:
            env_scripts_repo = get_package_url
        else:
            print("Failed to get url from mirror server. Using default url.")
            env_scripts_repo = 'https://gitee.com/RT-Thread-Mirror/env.git'
    else:
        env_scripts_repo = 'https://github.com/RT-Thread/env.git'


#     print(get_package_url,get_ver_sha)

    env_scripts_root = os.path.join(env_root, 'tools', 'scripts')
    cmd = r'git pull ' + env_scripts_repo
    execute_command(cmd, cwd=env_scripts_root)
    print("==============================>  Env scripts upgrade done \n")
Пример #2
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"
        )
Пример #3
0
def upgrade_packages_index():
    """Update the package repository index."""

    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')
    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(
            'packages', 'latest')
        if get_package_url != None:
            git_repo = get_package_url
        else:
            print("Failed to get url from mirror server. Using default url.")
            git_repo = 'https://gitee.com/RT-Thread-Mirror/packages.git'
    else:
        git_repo = 'https://github.com/RT-Thread/packages.git'


#     print(get_package_url,get_ver_sha)

    packages_root = os.path.join(env_root, 'packages')
    pkgs_path = os.path.join(packages_root, 'packages')

    if not os.path.isdir(pkgs_path):
        cmd = 'git clone ' + git_repo + ' ' + pkgs_path
        os.system(cmd)
        print("upgrade from :%s" % (git_repo))
    else:
        print("Begin to upgrade env packages.")
        cmd = r'git pull ' + git_repo
        execute_command(cmd, cwd=pkgs_path)
        print("==============================>  Env packages upgrade done \n")

    for filename in os.listdir(packages_root):
        package_path = os.path.join(packages_root, filename)
        if os.path.isdir(package_path):

            if package_path == pkgs_path:
                continue

            if os.path.isdir(os.path.join(package_path, '.git')):
                print("Begin to upgrade %s." % filename)
                cmd = r'git pull'
                execute_command(cmd, cwd=package_path)
                print(
                    "==============================>  Env %s update done \n" %
                    filename)
Пример #4
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))
Пример #5
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)
Пример #6
0
                "\nFailed to download software package with git. Please check the network connection."
            )
            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):