Exemple #1
0
def package_list():
    """Print the packages list in env.

    Read the.config file in the BSP directory, 
    and list the version number of the selected package.
    """

    fn = '.config'
    env_root = Import('env_root')
    pkgs_root = Import('pkgs_root')

    if not os.path.isfile(fn):
        if platform.system() == "Windows":
            os.system('chcp 65001  > nul')

        print("\n\033[1;31;40m当前路径下没有发现 .config 文件,请确保当前目录为 BSP 根目录。\033[0m")
        print(
            "\033[1;31;40m如果确定当前目录为 BSP 根目录,请先使用 <menuconfig> 命令来生成 .config 文件。\033[0m\n"
        )

        print('\033[1;31;40mNo system configuration file : .config.\033[0m')
        print(
            '\033[1;31;40mYou should use < menuconfig > command to config bsp first.\033[0m'
        )

        if platform.system() == "Windows":
            os.system('chcp 437  > nul')

        return

    pkgs = kconfig.parse(fn)

    for pkg in pkgs:
        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)

        pkgs_name_in_json = package.get_name()
        print("package name : %s, ver : %s " %
              (pkgs_name_in_json.encode("utf-8"), pkg['ver'].encode("utf-8")))

    if not pkgs:
        print("Packages list is empty.")
        print('You can use < menuconfig > command to select online packages.')
        print('Then use < pkgs --update > command to install them.')
    return
Exemple #2
0
def savetodb(pathname,pkgspathname):
    dbpathname = Import('dbsqlite_pathname')
    bsp_root = Import('bsp_root')
    bsppkgs = os.path.join(bsp_root,'packages')
    #print bsppkgs

    conn = get_conn(dbpathname)
    c = get_cursor(conn)
    save_sql = '''insert into packagefile values (?, ?, ?)'''
    package = os.path.basename(pkgspathname)
    #print "pathname",pathname
    md5pathname = os.path.join(bsppkgs,pathname)
    md5 = GetFileMd5(md5pathname)
    #print "md5",md5
    data = [(pathname,package ,md5)]
    save(conn, save_sql, data)
Exemple #3
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")
Exemple #4
0
def save_to_database(pathname, package_pathname, before_change_name):
    db_pathname = Import('dbsqlite_pathname')
    bsp_root = Import('bsp_root')
    bsp_packages_path = os.path.join(bsp_root, 'packages')

    conn = get_conn(db_pathname)
    save_sql = '''insert into packagefile values (?, ?, ?)'''
    package = os.path.basename(package_pathname)
    md5pathname = os.path.join(bsp_packages_path, before_change_name)

    if not os.path.isfile(md5pathname):
        print("md5pathname is Invalid")

    md5 = get_file_md5(md5pathname)
    data = [(pathname, package, md5)]
    save(conn, save_sql, data)
Exemple #5
0
def upgrade_packages_index():
    """Update the package repository index."""

    env_root = Import('env_root')
    pkgs_root = Import('pkgs_root')
    env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
    env_config_file = os.path.join(env_kconfig_path, '.config')
    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(
            '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'

    packages_root = pkgs_root
    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.encode("utf-8")))
    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)
Exemple #6
0
def error_packages_handle(error_packages_list, read_back_pkgs_json, pkgs_fn):
    bsp_root = Import('bsp_root')
    env_root = Import('env_root')

    flag = None

    error_packages_redownload_error_list = []

    if len(error_packages_list):
        print(
            "\n==============================> Packages list to download :  \n"
        )
        for pkg in error_packages_list:
            print pkg['name'], pkg['ver']
        print(
            "\nThe packages in the list above are accidentally deleted, env will redownload them."
        )
        print("Warning: Packages should be deleted in <menuconfig> command.\n")

        for pkg in error_packages_list:  # Redownloaded the packages in error_packages_list
            if install_pkg(env_root, bsp_root, pkg):
                print(
                    "==============================> %s %s is redownloaded successfully. \n"
                    % (pkg['name'], pkg['ver']))
            else:
                error_packages_redownload_error_list.append(pkg)
                print pkg, 'download failed.'
                flag = False

        if len(error_packages_redownload_error_list):
            print("%s" % error_packages_redownload_error_list)
            print(
                "Packages:%s,%s redownloed error, you need to use <pkgs --update> command again to redownload them."
                % (pkg['name'], pkg['ver']))
            write_back_pkgs_json = sub_list(
                read_back_pkgs_json, error_packages_redownload_error_list)
            read_back_pkgs_json = write_back_pkgs_json
            # print("write_back_pkgs_json:%s"%write_back_pkgs_json)
            pkgs_file = file(pkgs_fn, 'w')
            pkgs_file.write(json.dumps(write_back_pkgs_json, indent=1))
            pkgs_file.close()
    else:
        print(
            "\nAll the selected packages have been downloaded successfully.\n")

    return flag
def upgrade_packages_index():
    """Update the package repository index."""

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

    if need_using_mirror_download(env_config_file):
        get_package_url, get_ver_sha = get_url_from_mirror_server(
            'packages', 'latest')

        if get_package_url is not 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'

    packages_root = pkgs_root
    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.encode("utf-8")))
    else:
        print("Begin to upgrade env packages.")
        git_pull_repo(pkgs_path, git_repo)
        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)
                git_pull_repo(package_path)
                print(
                    "==============================>  Env %s update done \n" %
                    filename)
Exemple #8
0
def savetodb(pathname, pkgspathname, before_change_name):
    dbpathname = Import('dbsqlite_pathname')
    bsp_root = Import('bsp_root')
    bsppkgs = os.path.join(bsp_root, 'packages')

    conn = get_conn(dbpathname)
    save_sql = '''insert into packagefile values (?, ?, ?)'''
    package = os.path.basename(pkgspathname)
    md5pathname = os.path.join(bsppkgs, before_change_name)
	#print("pathname to save : %s"%pathname)
	#print("md5pathname : %s"%md5pathname) 
    
    if not os.path.isfile(md5pathname):
        print("md5pathname is Invalid")
    
    md5 = GetFileMd5(md5pathname)
	#print("md5 to save : %s"%md5) 
    data = [(pathname, package, md5)]
    save(conn, save_sql, data)
Exemple #9
0
def cmd(args):
    packages_root = os.path.join(Import('env_root'), 'packages')

    if args.system_update:
        dir_list = os.listdir(packages_root)

        with open(os.path.join(packages_root, 'Kconfig'), 'w') as kconfig:
            for item in dir_list:
                if os.path.isfile(os.path.join(packages_root, item,
                                               'Kconfig')):
                    kconfig.write('source "$PKGS_DIR/' + item + '/Kconfig"')
                    kconfig.write('\n')
Exemple #10
0
def package_list():
    """Print the packages list in env.

    Read the.config file in the BSP directory, 
    and list the version number of the selected package.
    """
    fn = '.config'
    env_root = Import('env_root')
    #     bsp_root = Import('bsp_root')
    #     target_pkgs_path = os.path.join(bsp_root, 'packages')
    #     pkgs_fn = os.path.join(target_pkgs_path, 'pkgs.json')

    if not os.path.isfile(fn):
        print('No system configuration file : .config.')
        print('You should use < menuconfig > command to config bsp first.')
        return

    # if not os.path.exists(target_pkgs_path):
    #    try:
    #        os.mkdir(target_pkgs_path)
    #    except:
    #        print 'mkdir packages directory failed'
    #        return

    pkgs = kconfig.parse(fn)

    # if not os.path.isfile(pkgs_fn):
    #    pkgs_file = file(pkgs_fn, 'w')
    #    pkgs_file.write(json.dumps(pkgs, indent=1))
    #    pkgs_file.close()

    for pkg in pkgs:
        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)

        pkgs_name_in_json = package.get_name()
        print pkgs_name_in_json, pkg['ver']
        # print "package path:", pkg['path']

    if not pkgs:
        print("Packages list is empty.")
        print('You can use < menuconfig > command to select online packages.')
        print('Then use < pkgs --update > command to install them.')
    return
Exemple #11
0
def isdataexist(pathname):
    ret = True
    dbpathname = Import('dbsqlite_pathname')

    conn = get_conn(dbpathname)
    c = get_cursor(conn) 
    sql = 'SELECT md5 from packagefile where pathname = "' + pathname + '"'
    cursor = c.execute(sql)
    for row in cursor:
        dbmd5 = row[0]
    if dbmd5:
        ret = False
    conn.close()
    return ret
Exemple #12
0
def list_packages():
    """Print the packages list in env.

    Read the.config file in the BSP directory,
    and list the version number of the selected package.
    """

    config_file = '.config'
    pkgs_root = Import('pkgs_root')

    if not os.path.isfile(config_file):
        if platform.system() == "Windows":
            os.system('chcp 65001  > nul')

        print("\033[1;31;40mWarning: Can't find .config.\033[0m")
        print(
            '\033[1;31;40mYou should use <menuconfig> command to config bsp first.\033[0m'
        )

        if platform.system() == "Windows":
            os.system('chcp 437  > nul')

        return

    packages = kconfig.parse(config_file)

    for pkg in packages:
        package = PackageOperation()
        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)

        package_name_in_json = package.get_name().encode("utf-8")
        print("package name : %s, ver : %s " %
              (package_name_in_json, pkg['ver'].encode("utf-8")))

    if not packages:
        print("Packages list is empty.")
        print('You can use < menuconfig > command to select online packages.')
        print('Then use < pkgs --update > command to install them.')
    return
Exemple #13
0
def Information_statistics():

    env_root = Import('env_root')

    # 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')

    mac_addr = get_mac_address()
    env_config_file = os.path.join(env_kconfig_path, '.config')
    if find_macro_in_config(env_config_file, 'SYS_PKGS_USING_STATISTICS'):
        response = requests.get(
            'https://www.rt-thread.org/studio/statistics/api/envuse?userid=' +
            str(mac_addr) + '&username='******'&envversion=1.0&studioversion=2.0&ip=127.0.0.1')
        if response.status_code != 200:
            return
    else:
        return
Exemple #14
0
def deletepackdir(dirpath,dbpathname):
    bsp_root = Import('bsp_root')
    #print "bsproot:",bsp_root
    #print "dirpath",dirpath
    #print "os.split:", os.path.split(dirpath)[1]
    path = os.path.split(dirpath)[1]
    flag = True

    flag = getdirdisplay(dirpath,dbpathname)

    if flag == True:
        if os.path.exists(dirpath):
            for root, dirs, files in os.walk(dirpath, topdown=False):
                for name in files:
                    os.remove(os.path.join(root, name))
                for name in dirs:
                    os.rmdir(os.path.join(root, name))
            os.rmdir(dirpath)
        #print "the dir should be delete"
    return flag
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, r'tools\scripts\cmds')
    env_config_file = os.path.join(env_kconfig_path, '.config')

    if need_using_mirror_download(env_config_file):
        get_package_url, get_ver_sha = get_url_from_mirror_server(
            'env', 'latest')

        if get_package_url is not 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'

    env_scripts_root = os.path.join(env_root, 'tools', 'scripts')
    git_pull_repo(env_scripts_root, env_scripts_repo)
    print("==============================>  Env scripts upgrade done \n")
Exemple #16
0
def pre_package_update():
    """ Make preparations before updating the software package. """

    bsp_root = Import('bsp_root')
    env_root = Import('env_root')

    if not os.path.exists('.config'):
        if platform.system() == "Windows":
            os.system('chcp 65001  > nul')

        print("\n\033[1;31;40m当前路径下没有发现 .config 文件,请确保当前目录为 BSP 根目录。\033[0m")
        print(
            "\033[1;31;40m如果确定当前目录为 BSP 根目录,请先使用 <menuconfig> 命令来生成 .config 文件。\033[0m\n"
        )

        print('No system configuration file : .config.')
        print('You should use < menuconfig > command to config bsp first.')

        if platform.system() == "Windows":
            os.system('chcp 437  > nul')

        return False

    bsp_packages_path = os.path.join(bsp_root, 'packages')
    if not os.path.exists(bsp_packages_path):
        os.mkdir("packages")
        os.chdir(bsp_packages_path)
        fp = open("pkgs.json", 'w')
        fp.write("[]")
        fp.close()

        fp = open("pkgs_error.json", 'w')
        fp.write("[]")
        fp.close()

        os.chdir(bsp_root)

    # prepare target packages file
    dbsqlite_pathname = os.path.join(bsp_packages_path, 'packages.dbsqlite')
    Export('dbsqlite_pathname')
    dbsqlite_pathname = dbsqlite_pathname.decode('gbk')

    # Avoid creating tables more than one time
    if not os.path.isfile(dbsqlite_pathname):
        conn = pkgsdb.get_conn(dbsqlite_pathname)
        sql = '''CREATE TABLE packagefile
                    (pathname   TEXT  ,package  TEXT  ,md5  TEXT );'''
        pkgsdb.create_table(conn, sql)

    fn = '.config'
    pkgs = kconfig.parse(fn)
    newpkgs = pkgs

    if not os.path.exists(bsp_packages_path):
        os.mkdir(bsp_packages_path)

    pkgs_fn = os.path.join(bsp_packages_path, 'pkgs.json')

    # regenerate file : packages/pkgs.json
    if not os.path.exists(pkgs_fn):
        os.chdir(bsp_packages_path)
        fp = open("pkgs.json", 'w')
        fp.write("[]")
        fp.close()
        os.chdir(bsp_root)

    # Reading data back from pkgs.json
    with open(pkgs_fn, 'r') as f:
        oldpkgs = json.load(f)

    # regenerate file : packages/pkgs_error.json
    pkgs_error_list_fn = os.path.join(bsp_packages_path, 'pkgs_error.json')

    if not os.path.exists(pkgs_error_list_fn):
        os.chdir(bsp_packages_path)
        fp = open("pkgs_error.json", 'w')
        fp.write("[]")
        fp.close()
        os.chdir(bsp_root)

    # Reading data back from pkgs_error.json
    with open(pkgs_error_list_fn, 'r') as f:
        pkgs_error = json.load(f)

    # create SConscript file
    if not os.path.isfile(os.path.join(bsp_packages_path, 'SConscript')):
        bridge_script = file(os.path.join(bsp_packages_path, 'SConscript'),
                             'w')
        bridge_script.write(Bridge_SConscript)
        bridge_script.close()

    return [
        oldpkgs, newpkgs, pkgs_error, pkgs_fn, pkgs_error_list_fn,
        bsp_packages_path, dbsqlite_pathname
    ]
Exemple #17
0
def pre_package_update():

    bsp_root = Import('bsp_root')

    if not os.path.exists('.config'):
        print(
            "Can't find file .config.Maybe your working directory isn't in bsp root now."
        )
        print(
            "if your working directory isn't in bsp root now,please change your working directory to bsp root."
        )
        print(
            "if your working directory is in bsp root now, please use menuconfig command to create .config file first."
        )
        return

    bsp_packages_path = os.path.join(bsp_root, 'packages')
    if not os.path.exists(bsp_packages_path):
        os.mkdir("packages")
        os.chdir(bsp_packages_path)
        fp = open("pkgs.json", 'w')
        fp.write("[]")
        fp.close()

        fp = open("pkgs_error.json", 'w')
        fp.write("[]")
        fp.close()

        os.chdir(bsp_root)

    # prepare target packages file
    dbsqlite_pathname = os.path.join(bsp_packages_path, 'packages.dbsqlite')
    Export('dbsqlite_pathname')

    # Avoid creating tables more than one time
    if not os.path.isfile(dbsqlite_pathname):
        conn = pkgsdb.get_conn(dbsqlite_pathname)
        sql = '''CREATE TABLE packagefile
                    (pathname   TEXT  ,package  TEXT  ,md5  TEXT );'''
        pkgsdb.create_table(conn, sql)

    fn = '.config'
    pkgs = kconfig.parse(fn)
    newpkgs = pkgs

    if not os.path.exists(bsp_packages_path):
        os.mkdir(bsp_packages_path)

    pkgs_fn = os.path.join(bsp_packages_path, 'pkgs.json')

    if not os.path.exists(pkgs_fn):
        print("Maybe you delete the file pkgs.json by mistake.")
        print("Do you want to create a new pkgs.json ?")
        rc = raw_input('Press the Y Key to create a new pkgs.json.')
        if rc == 'y' or rc == 'Y':
            os.chdir(bsp_packages_path)
            fp = open("pkgs.json", 'w')
            fp.write("[]")
            fp.close()
            os.chdir(bsp_root)
            print("Create a new file pkgs.json done.")

    # Reading data back from pkgs.json
    with open(pkgs_fn, 'r') as f:
        oldpkgs = json.load(f)

    pkgs_error_list_fn = os.path.join(bsp_packages_path, 'pkgs_error.json')

    if not os.path.exists(pkgs_error_list_fn):
        os.chdir(bsp_packages_path)
        fp = open("pkgs_error.json", 'w')
        fp.write("[]")
        fp.close()
        os.chdir(bsp_root)


#         print ("Create a new error file : pkgs_error.json.")

# Reading data back from pkgs_error.json
    with open(pkgs_error_list_fn, 'r') as f:
        pkgs_error = json.load(f)

    # create SConscript file
    if not os.path.isfile(os.path.join(bsp_packages_path, 'SConscript')):
        bridge_script = file(os.path.join(bsp_packages_path, 'SConscript'),
                             'w')
        bridge_script.write(Bridge_SConscript)
        bridge_script.close()

    return [
        oldpkgs, newpkgs, pkgs_error, pkgs_fn, pkgs_error_list_fn,
        bsp_packages_path, dbsqlite_pathname
    ]
Exemple #18
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))
Exemple #19
0
def update_latest_packages(sys_value):
    """ 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.
    """

    logging.info("Begin to update latest version packages")

    result = True

    package_filename = sys_value[3]
    bsp_packages_path = sys_value[5]

    env_root = Import('env_root')
    pkgs_root = Import('pkgs_root')

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

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

    for pkg in read_back_pkgs_json:
        right_path_flag = True
        package = PackageOperation()
        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)
        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_package_folder(repo_path, pkg['ver'])

            # noinspection PyBroadException
            try:
                # If mirror acceleration is enabled, get the update address from the mirror server.
                if need_using_mirror_download(env_config_file):
                    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'])

                    # if git root is same as repo path, then change the upstream
                    get_git_root = get_git_root_path(repo_path)
                    if get_git_root:
                        if os.path.normcase(repo_path) == os.path.normcase(
                                get_git_root):
                            if mirror_url[0] is not None:
                                cmd = 'git remote set-url origin ' + mirror_url[
                                    0]
                                git_cmd_exec(cmd, repo_path)
                        else:
                            print("\n==============================> updating")
                            print("Package path: %s" % repo_path)
                            print("Git root: %s" % get_git_root)
                            print(
                                "Error: Not currently in a git root directory, cannot switch upstream.\n"
                            )
                            right_path_flag = False
                            result = False
                    else:
                        right_path_flag = False
                        result = False

            except Exception as e:
                logging.warning(
                    "Failed to connect to the mirror server, using non-mirror server to update."
                )

            if not right_path_flag:
                continue

            # Update the package repository from upstream.
            git_pull_repo(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)

    return result
Exemple #20
0
def package_update(isDeleteOld=False):
    """Update env's packages.

    Compare the old and new software package list and update the package.
    Remove unwanted packages and download the newly selected package.-
    Check if the files in the deleted packages have been changed, and if so, 
    remind the user saved the modified file.
    """

    sys_value = pre_package_update()

    if not sys_value:
        return

    bsp_root = Import('bsp_root')
    env_root = Import('env_root')
    flag = True

    # According to the env version, whether Chinese output is supported or not
    if determine_support_chinese(env_root):
        if platform.system() == "Windows":
            os.system('chcp 65001 > nul')

    oldpkgs = sys_value[0]
    newpkgs = sys_value[1]
    pkgs_delete_error_list = sys_value[2]
    pkgs_fn = sys_value[3]
    pkgs_error_list_fn = sys_value[4]
    bsp_packages_path = sys_value[5]
    dbsqlite_pathname = sys_value[6]

    if len(pkgs_delete_error_list):
        for error_package in pkgs_delete_error_list:
            removepath_ver = get_package_remove_path(error_package,
                                                     bsp_packages_path)

            if os.path.isdir(removepath_ver):
                print(
                    "\nError: %s package delete failed, begin to remove it." %
                    error_package['name'].encode("utf-8"))

                if rm_package(removepath_ver) == False:
                    print(
                        "Error: Delete package %s failed! Please delete the folder manually.\n"
                        % error_package['name'].encode("utf-8"))
                    return

    # 1.in old ,not in new : Software packages that need to be removed.
    casedelete = sub_list(oldpkgs, newpkgs)
    pkgs_delete_fail_list = []

    for pkg in casedelete:

        removepath_ver = get_package_remove_path(pkg, bsp_packages_path)
        removepath_git = os.path.join(removepath_ver, '.git')

        # Delete. Git directory.
        if os.path.isdir(removepath_ver) and os.path.isdir(removepath_git):
            gitdir = removepath_ver

            print("\nStart to remove %s \nplease wait..." %
                  gitdir.encode("utf-8"))
            if isDeleteOld:
                if rm_package(gitdir) == False:
                    print("Floder delete fail: %s" % gitdir.encode("utf-8"))
                    print("Please delete this folder manually.")
            else:
                print(
                    "The folder is managed by git. Do you want to delete this folder?\n"
                )
                rc = raw_input(
                    'Press the Y Key to delete the folder or just press Enter to keep it : '
                )
                if rc == 'y' or rc == 'Y':
                    try:
                        if rm_package(gitdir) == False:
                            pkgs_delete_fail_list.append(pkg)
                            print("Error: Please delete the folder manually.")
                    except Exception, e:
                        print('Error message:%s%s. error.message: %s\n\t' %
                              ("Delete folder failed: ",
                               gitdir.encode("utf-8"), e.message))
        else:
            if os.path.isdir(removepath_ver):
                print("Start to remove %s \nplease wait..." %
                      removepath_ver.encode("utf-8"))
                try:
                    pkgsdb.deletepackdir(removepath_ver, dbsqlite_pathname)
                except Exception, e:
                    pkgs_delete_fail_list.append(pkg)
                    print('Error message:\n%s %s. %s \n\t' % (
                        "Delete folder failed, please delete the folder manually",
                        removepath_ver.encode("utf-8"), e.message))
Exemple #21
0
def package_update(isDeleteOld=False):
    """Update env's packages.

    Compare the old and new software package list and update the package.
    Remove unwanted packages and download the newly selected package.
    Check if the files in the deleted packages have been changed, and if so, 
    remind the user saved the modified file.
    """

    pkgs_update_log = Logger('pkgs_update', logging.WARNING)
    bsp_root = Import('bsp_root')
    env_root = Import('env_root')
    flag = True
    sys_value = pre_package_update()
    oldpkgs = sys_value[0]
    newpkgs = sys_value[1]
    pkgs_delete_error_list = sys_value[2]
    pkgs_fn = sys_value[3]
    pkgs_error_list_fn = sys_value[4]
    bsp_packages_path = sys_value[5]
    dbsqlite_pathname = sys_value[6]

    pkgs_update_log.info('[Line: %d][Message : Begin to remove packages]' %
                         sys._getframe().f_lineno)
    pkgs_update_log.info('[Line: %d][Message : oldpkgs: %s ]' %
                         (sys._getframe().f_lineno, oldpkgs))
    pkgs_update_log.info('[Line: %d][Message : newpkgs: %s ]' %
                         (sys._getframe().f_lineno, newpkgs))
    pkgs_update_log.info('[Line: %d][Message : pkgs_delete_error_list: %s ]' %
                         (sys._getframe().f_lineno, pkgs_delete_error_list))

    if len(pkgs_delete_error_list):
        for error_package in pkgs_delete_error_list:
            removepath_ver = get_package_remove_path(error_package,
                                                     bsp_packages_path)

            if os.path.isdir(removepath_ver):
                print(
                    "\nError: %s package delete failed, begin to remove it." %
                    error_package['name'])

                if rm_package(removepath_ver) == False:
                    print(
                        "Error: Delete package %s failed! Please delete the folder manually.\n"
                        % error_package['name'])
                    return

    # 1.in old ,not in new : Software packages that need to be removed.
    casedelete = sub_list(oldpkgs, newpkgs)
    pkgs_delete_fail_list = []

    for pkg in casedelete:

        removepath_ver = get_package_remove_path(pkg, bsp_packages_path)
        removepath_git = os.path.join(removepath_ver, '.git')

        # print "removepath_git to delete",removepath_git
        # Delete. Git directory.

        if os.path.isdir(removepath_ver) and os.path.isdir(removepath_git):
            gitdir = removepath_ver

            print("\nStart to remove %s, please wait...\n" % gitdir)
            if isDeleteOld:
                if rm_package(gitdir) == False:
                    print("Floder delete fail: %s" % gitdir)
                    print("Please delete this folder manually.")
            else:
                print(
                    "The folder is managed by git. Do you want to delete this folder?\n"
                )
                rc = raw_input(
                    'Press the Y Key to delete the folder or just press Enter to keep it : '
                )
                if rc == 'y' or rc == 'Y':
                    try:
                        if rm_package(gitdir) == False:
                            pkgs_delete_fail_list.append(pkg)
                            print("Error: Please delete the folder manually.")
                    except Exception, e:
                        print('Error message:%s%s. error.message: %s\n\t' %
                              ("Delete folder failed: ", gitdir, e.message))
        else:
            if os.path.isdir(removepath_ver):
                print("Start to remove %s, please wait...\n" % removepath_ver)
                try:
                    pkgsdb.deletepackdir(removepath_ver, dbsqlite_pathname)
                except Exception, e:
                    pkgs_delete_fail_list.append(pkg)
                    print('Error message:\n%s %s. %s \n\t' % (
                        "Delete folder failed, please delete the folder manually",
                        removepath_ver, e.message))
Exemple #22
0
def cmd(args):
    env_root = Import('env_root')
    os_version = platform.platform(True)[10:13]
    kconfig_win7_path = os.path.join(env_root, 'tools', 'bin',
                                     'kconfig-mconf_win7.exe')

    if not os.path.exists('Kconfig'):
        if platform.system() == "Windows":
            os.system('chcp 65001  > nul')

        print(
            "\n\033[1;31;40m<menuconfig> 命令应当在某一特定 BSP 目录下执行,例如:\"rt-thread/bsp/stm32/stm32f091-st-nucleo\"\033[0m"
        )
        print("\033[1;31;40m请确保当前目录为 BSP 根目录,并且该目录中有 Kconfig 文件。\033[0m\n")

        print(
            "<menuconfig> command should be used in a bsp root path with a Kconfig file."
        )
        print("Example: \"rt-thread/bsp/stm32/stm32f091-st-nucleo\"")
        print(
            "You should check if there is a Kconfig file in your bsp root first."
        )

        if platform.system() == "Windows":
            os.system('chcp 437  > nul')

        return False

    fn = '.config'

    if os.path.isfile(fn):
        mtime = os.path.getmtime(fn)
    else:
        mtime = -1

    if platform.system() == "Windows":
        os.system('chcp 437  > nul')

    if args.menuconfig_fn:
        print('use', args.menuconfig_fn)
        import shutil
        shutil.copy(args.menuconfig_fn, fn)
    elif args.menuconfig_g:
        mk_rtconfig(fn)
    elif args.menuconfig_silent:
        if float(os_version) >= 6.2:
            os.system('kconfig-mconf Kconfig -n')
            mk_rtconfig(fn)
        else:
            if os.path.isfile(kconfig_win7_path):
                os.system('kconfig-mconf_win7 Kconfig -n')
            else:
                os.system('kconfig-mconf Kconfig -n')

    elif args.menuconfig_setting:
        env_kconfig_path = os.path.join(env_root, r'tools\scripts\cmds')
        beforepath = os.getcwd()
        os.chdir(env_kconfig_path)

        if float(os_version) >= 6.2:
            os.system('kconfig-mconf Kconfig')
        else:
            if os.path.isfile(kconfig_win7_path):
                os.system('kconfig-mconf_win7 Kconfig')
            else:
                os.system('kconfig-mconf Kconfig')

        os.chdir(beforepath)

        return

    else:
        if float(os_version) >= 6.2:
            os.system('kconfig-mconf Kconfig')
        else:
            if os.path.isfile(kconfig_win7_path):
                os.system('kconfig-mconf_win7 Kconfig')
            else:
                os.system('kconfig-mconf Kconfig')

    if os.path.isfile(fn):
        mtime2 = os.path.getmtime(fn)
    else:
        mtime2 = -1

    if mtime != mtime2:
        mk_rtconfig(fn)

    if platform.system() == "Windows":
        env_kconfig_path = os.path.join(env_root, r'tools\scripts\cmds')
        fn = os.path.join(env_kconfig_path, '.config')

        if not os.path.isfile(fn):
            return

        if find_macro_in_config(fn, 'SYS_AUTO_UPDATE_PKGS'):
            os.system('pkgs --update')
            print(
                "==============================>The packages have been updated completely."
            )

        if find_macro_in_config(fn, 'SYS_CREATE_MDK_IAR_PROJECT'):
            if find_macro_in_config(fn, 'SYS_CREATE_MDK4'):
                os.system('scons --target=mdk4 -s')
                print("Create mdk4 project done")
            elif find_macro_in_config(fn, 'SYS_CREATE_MDK5'):
                os.system('scons --target=mdk5 -s')
                print("Create mdk5 project done")
            elif find_macro_in_config(fn, 'SYS_CREATE_IAR'):
                os.system('scons --target=iar -s')
                print("Create iar project done")
Exemple #23
0
def cmd(args):
    env_scripts_root = os.path.join(Import('env_root'), 'tools', 'scripts')
    packages_root = os.path.join(Import('env_root'), 'packages')
    git_repo = 'https://github.com/RT-Thread/packages.git'
    env_scripts_repo = 'https://github.com/RT-Thread/env.git'

    if args.package_update:
        package_update()
    elif args.package_create:
        package_wizard()
    elif args.package_list:
        package_list()
    elif args.package_upgrade:
        beforepath = os.getcwd()
        pkgs_path = os.path.join(packages_root, 'packages')
        #print pkgs_path
        if not os.path.isdir(pkgs_path):
            cmd = 'git clone ' + git_repo + ' ' + pkgs_path
            os.system(cmd)
            print("upgrade from :%s" % (git_repo))

        for filename in os.listdir(packages_root):
            if os.path.isdir(os.path.join(packages_root, filename)):
                os.chdir(os.path.join(packages_root, filename))
                if os.path.isdir('.git'):
                    cmd = 'git pull origin master'
                    os.system(cmd)
                    os.chdir(beforepath)
                    print(
                        "==============================>  Env %s update done \n"
                        % filename)

        beforepath = os.getcwd()
        os.chdir(env_scripts_root)
        cmd = 'git pull ' + env_scripts_repo
        os.system(cmd)
        os.chdir(beforepath)
        print("==============================>  Env scripts update done \n")

    elif args.package_print_env:
        print("Here are some environmental variables.")
        print(
            "If you meet some problems,please check them. Make sure the configuration is correct."
        )
        print("RTT_EXEC_PATH:%s" % (os.getenv("RTT_EXEC_PATH")))
        print("RTT_CC:%s" % (os.getenv("RTT_CC")))
        print("SCONS:%s" % (os.getenv("SCONS")))
        print("PKGS_ROOT:%s" % (os.getenv("PKGS_ROOT")))

        env_root = os.getenv('ENV_ROOT')
        if env_root == None:
            import platform
            if platform.system() != 'Windows':
                env_root = os.path.join(os.getenv('HOME'), '.env')

        print("ENV_ROOT:%s" % (env_root))
        #print "RTT_ROOT:",os.getenv("RTT_ROOT")
        #os.putenv("RTT_EXEC_PATH","rtt_gcc_path")
        #print "after",os.getenv("RTT_EXEC_PATH")
    else:
        os.system('pkgs -h')
Exemple #24
0
def package_update():
    """Update env's packages.

    Compare the old and new software package list and update the package.
    Remove unwanted packages and download the newly selected package.
    Check if the files in the deleted packages have been changed, and if so, 
    remind the user saved the modified file.

    Args:
        none

    Returns:
        none

    Raises:
        none
    """
    bsp_root = Import('bsp_root')
    env_root = Import('env_root')

    flag = True

    #print bsp_root
    #print env_root

    if not os.path.exists('.config'):
        print(
            "Can't find file .config.Maybe your working directory isn't in bsp root now."
        )
        print(
            "if your working directory isn't in bsp root now,please change your working directory to bsp root."
        )
        print(
            "if your working directory is in bsp root now, please use menuconfig command to create .config file first."
        )
        return

    bsp_packages_path = os.path.join(bsp_root, 'packages')
    if not os.path.exists(bsp_packages_path):
        os.mkdir("packages")
        os.chdir(bsp_packages_path)
        fp = open("pkgs.json", 'w')
        fp.write("[]")
        fp.close()
        os.chdir(bsp_root)

    # prepare target packages file
    dbsqlite_pathname = os.path.join(bsp_packages_path, 'packages.dbsqlite')
    Export('dbsqlite_pathname')

    # Avoid creating tables more than one time
    if not os.path.isfile(dbsqlite_pathname):
        conn = pkgsdb.get_conn(dbsqlite_pathname)
        sql = '''CREATE TABLE packagefile
                    (pathname   TEXT  ,package  TEXT  ,md5  TEXT );'''
        pkgsdb.create_table(conn, sql)

    fn = '.config'
    pkgs = kconfig.parse(fn)
    newpkgs = pkgs

    if not os.path.exists(bsp_packages_path):
        os.mkdir(bsp_packages_path)

    pkgs_fn = os.path.join(bsp_packages_path, 'pkgs.json')

    if not os.path.exists(pkgs_fn):
        print("Maybe you delete the file pkgs.json by mistake.")
        print("Do you want to create a new pkgs.json ?")
        rc = raw_input('Press the Y Key to create a new pkgs.json.')
        if rc == 'y' or rc == 'Y':
            os.chdir(bsp_packages_path)
            fp = open("pkgs.json", 'w')
            fp.write("[]")
            fp.close()
            os.chdir(bsp_root)
            print("Create a new file pkgs.json done.")

    # Reading data back from pkgs.json
    with open(pkgs_fn, 'r') as f:
        oldpkgs = json.load(f)

    #print "newpkgs:",newpkgs
    #print "oldpkgs:",oldpkgs

    # 1.in old ,not in new
    casedelete = SubList(oldpkgs, newpkgs)
    for pkg in casedelete:
        dirpath = pkg['path']
        ver = pkg['ver']
        #print 'ver is :',ver[1:]
        if dirpath[0] == '/' or dirpath[0] == '\\': dirpath = dirpath[1:]
        #dirpath = dirpath.replace('/', '\\')
        dirpath = os.path.basename(dirpath)
        #print "basename:",os.path.basename(dirpath)
        removepath = os.path.join(bsp_packages_path, dirpath)
        #print "floder to delere",removepath

        # Delete. Git directory.

        if os.path.isdir(removepath):
            #uppername = str.upper(str(os.path.basename(removepath)))
            #dirname = os.path.dirname(removepath)
            #gitdir = os.path.join(dirname,uppername)
            gitdir = removepath

            print(
                "\nOperation : Delete a git package or change the version of a package."
            )
            print(
                "If you want to change the version of a package,you should aslo delete the old package before update.\nOtherwise,you may fail to update.\n"
            )
            print("Folder to delete: %s" % (gitdir))
            print(
                "The folder is managed by git,are you sure you want to delete this folder?\n"
            )

            rc = raw_input(
                'Press the Y Key to delete the folder or just press Enter to keep the file:'
            )
            if rc == 'y' or rc == 'Y':
                if platform.system() != "Windows":
                    shutil.rmtree(gitdir)
                else:
                    cmd = 'rd /s /q ' + gitdir
                    os.system(cmd)
                if os.path.isdir(gitdir):
                    if platform.system() != "Windows":
                        shutil.rmtree(gitdir)
                    else:
                        cmd = 'rd /s /q ' + gitdir
                        os.system(cmd)
                    print("Delete not entirely,try again.")
                else:
                    print("Folder has been removed.")
        else:
            removepath = removepath + '-' + ver[1:]
            #print removepath
            pkgsdb.deletepackdir(removepath, dbsqlite_pathname)

    # 2.in old and in new
    caseinoperation = AndList(newpkgs, oldpkgs)

    # 3.in new not in old
    # If the package download fails, record it, and then download again when the update command is executed.

    casedownload = SubList(newpkgs, oldpkgs)
    #print 'in new not in old:',casedownload
    list = []

    for pkg in casedownload:
        if install_pkg(env_root, bsp_root, pkg):
            print(
                "==============================>  %s %s is downloaded successfully. \n"
                % (pkg['name'], pkg['ver']))
        else:
            list.append(
                pkg)  # If the PKG download fails, record it in the list.
            print pkg, 'download failed.'
            flag = False

    newpkgs = SubList(newpkgs,
                      list)  # Get the currently updated configuration.

    # Give hints based on the success of the download.

    if len(list):
        print("Package download failed list: %s \n" % list)
        print(
            "You need to reuse the 'pkgs -update' command to download again.\n"
        )

    # Writes the updated configuration to pkgs.json file.
    # Packages that are not downloaded correctly will be redownloaded at the next update.

    pkgs_file = file(pkgs_fn, 'w')
    pkgs_file.write(json.dumps(newpkgs, indent=1))
    pkgs_file.close()

    # update SConscript file
    if not os.path.isfile(os.path.join(bsp_packages_path, 'SConscript')):
        bridge_script = file(os.path.join(bsp_packages_path, 'SConscript'),
                             'w')
        bridge_script.write(Bridge_SConscript)
        bridge_script.close()

    # Check to see if the packages stored in the Json file list actually exist,
    # and then download the packages if they don't exist.

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

    #print(read_back_pkgs_json)

    error_packages_list = []
    error_packages_redownload_error_list = []
    for pkg in read_back_pkgs_json:
        dirpath = pkg['path']
        ver = pkg['ver']
        #print 'ver is :',ver[1:]
        if dirpath[0] == '/' or dirpath[0] == '\\': dirpath = dirpath[1:]

        dirpath = os.path.basename(dirpath)
        removepath = os.path.join(bsp_packages_path, dirpath)
        #print "if floder exist",removepath
        removepath_ver = removepath + '-' + ver[1:]
        #print "if floder exist",removepath

        if os.path.exists(removepath):
            continue
        elif os.path.exists(removepath_ver):
            continue
        else:
            error_packages_list.append(pkg)

    if len(error_packages_list):
        print("\n==============================> Error packages list :  \n")
        for pkg in error_packages_list:
            print pkg['name'], pkg['ver']
        print("\nThe package in the list above is accidentally deleted.")
        print(
            "Env will redownload packages that have been accidentally deleted."
        )
        print(
            "If you really want to remove these packages, do that in the menuconfig command.\n"
        )

        for pkg in error_packages_list:  # Redownloaded the packages in error_packages_list
            if install_pkg(env_root, bsp_root, pkg):
                print(
                    "==============================>  %s %s is redownloaded successfully. \n"
                    % (pkg['name'], pkg['ver']))
            else:
                error_packages_redownload_error_list.append(pkg)
                print pkg, 'download failed.'
                flag = False

        if len(error_packages_redownload_error_list):
            print("%s" % error_packages_redownload_error_list)
            print(
                "Packages:%s,%s redownloed error,you need to use 'pkgs --update' command again to redownload them."
                % pkg['name'], pkg['ver'])
            write_back_pkgs_json = SubList(
                read_back_pkgs_json, error_packages_redownload_error_list)
            read_back_pkgs_json = write_back_pkgs_json
            #print("write_back_pkgs_json:%s"%write_back_pkgs_json)
            pkgs_file = file(pkgs_fn, 'w')
            pkgs_file.write(json.dumps(write_back_pkgs_json, indent=1))
            pkgs_file.close()
    else:
        print(
            "\nAll the selected packages have been downloaded successfully.\n")

    # 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.

    beforepath = os.getcwd()
    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()
        if pkg['ver'] == "latest_version" or pkg['ver'] == "latest":
            repo_path = os.path.join(bsp_packages_path, pkgs_name_in_json)
            ver_sha = package.get_versha(pkg['ver'])
            #print repo_path, ver_sha
            os.chdir(repo_path)
            cmd = 'git pull'  # Only one trace relationship can be used directly with git pull.
            os.system(cmd)
            os.chdir(beforepath)
            print("==============================>  %s update done \n" %
                  (pkgs_name_in_json))

    if flag:
        print("Operation completed successfully.")
    else:
        print("Operation failed.")
Exemple #25
0
def cmd(args):
    env_root = Import('env_root')
    currentdir = os.getcwd() 
    dirname = os.path.split(os.path.split(currentdir)[0])[0]
    get_rtt_name = os.path.basename(dirname)
    os_version = platform.platform(True)[10:13]
    #print os.path.split(currentdir)[1]
    kconfig_win7_path = os.path.join(env_root, 'tools', 'bin', 'kconfig-mconf_win7.exe')

    if not os.getenv("RTT_ROOT"):
        if get_rtt_name != 'rt-thread':  
            print ("menuconfig command should be used in a bsp root path with a Kconfig file, you should check if there is a Kconfig file in your bsp root first.")
            print ('And then you can check Kconfig file and modify the default option below to your rtthread root path.\n')

            print ('config $RTT_DIR')
            print ('string' )
            print ('option env="RTT_ROOT"')
            print ('default "../.."\n')
            print ('example:  default "F:/git_repositories/rt-thread"  \n')

            print ("using command 'set RTT_ROOT=your_rtthread_root_path' to set RTT_ROOT is ok too.\n")
            print ("you can ignore debug messages below.")
            #if not args.menuconfig_easy:                
            #    return

    fn = '.config'

    if os.path.isfile(fn):
        mtime = os.path.getmtime(fn)
    else:
        mtime = -1

    if args.menuconfig_fn:
        print 'use', args.menuconfig_fn
        import shutil
        shutil.copy(args.menuconfig_fn, fn)
    elif args.menuconfig_silent:
        if float(os_version) >=  6.2 :
            os.system('kconfig-mconf Kconfig -n')
        else:
            if os.path.isfile(kconfig_win7_path):
                os.system('kconfig-mconf_win7 Kconfig -n')
            else:
                os.system('kconfig-mconf Kconfig -n')

    elif args.menuconfig_setting:
        env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
        beforepath = os.getcwd()
        os.chdir(env_kconfig_path)

        if float(os_version) >=  6.2 :
            os.system('kconfig-mconf Kconfig')
        else:
            if os.path.isfile(kconfig_win7_path):
                os.system('kconfig-mconf_win7 Kconfig')
            else:
                os.system('kconfig-mconf Kconfig')

        os.chdir(beforepath)  
        return
    else:
        if float(os_version) >=  6.2 :
            os.system('kconfig-mconf Kconfig')
        else:
            if os.path.isfile(kconfig_win7_path):
                os.system('kconfig-mconf_win7 Kconfig')
            else:
                os.system('kconfig-mconf Kconfig')

    if os.path.isfile(fn):
        mtime2 = os.path.getmtime(fn)
    else:
        mtime2 = -1

    if mtime != mtime2:
        mk_rtconfig(fn)

    if platform.system() == "Windows":
        env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
        fn = os.path.join(env_kconfig_path,'.config')

        if not os.path.isfile(fn):
            return

        print("\nTry the command <menuconfig -s/--setting> ")
        print("\nEnable the auto update option,env will auto update the packages you select.")

        if find_macro_in_condfig(fn,'SYS_AUTO_UPDATE_PKGS'):
            os.system('pkgs --update')
            print "Auto update packages done"

        print("Select the project type your bsp support and then env will create a new mdk/iar project.")

        if find_macro_in_condfig(fn,'SYS_CREATE_MDK_IAR_PROJECT'):
            if find_macro_in_condfig(fn,'SYS_CREATE_MDK4'):
                os.system('scons --target=mdk4 -s')
                print "Create mdk4 project done"
            elif find_macro_in_condfig(fn,'SYS_CREATE_MDK5'):
                os.system('scons --target=mdk5 -s')
                print "Create mdk5 project done"
            elif find_macro_in_condfig(fn,'SYS_CREATE_IAR'):
                os.system('scons --target=iar -s')
                print "Create iar project done"
Exemple #26
0
def package_update(isDeleteOld=False):
    """Update env's packages.

    Compare the old and new software package list and update the package.
    Remove unwanted packages and download the newly selected package.-
    Check if the files in the deleted packages have been changed, and if so, 
    remind the user saved the modified file.
    """

    sys_value = pre_package_update()

    if not sys_value:
        return

    bsp_root = Import('bsp_root')
    env_root = Import('env_root')
    pkgs_root = Import('pkgs_root')
    flag = True

    # According to the env version, whether Chinese output is supported or not
    if determine_support_chinese(env_root):
        if platform.system() == "Windows":
            os.system('chcp 65001 > nul')

    oldpkgs = sys_value[0]
    newpkgs = sys_value[1]
    pkgs_delete_error_list = sys_value[2]
    pkgs_fn = sys_value[3]
    pkgs_error_list_fn = sys_value[4]
    bsp_packages_path = sys_value[5]
    dbsqlite_pathname = sys_value[6]

    # print(oldpkgs)
    # print(newpkgs)

    if len(pkgs_delete_error_list):
        for error_package in pkgs_delete_error_list:
            removepath_ver = get_package_remove_path(error_package,
                                                     bsp_packages_path)

            if os.path.isdir(removepath_ver):
                print(
                    "\nError: %s package delete failed, begin to remove it." %
                    error_package['name'].encode("utf-8"))

                if rm_package(removepath_ver) == False:
                    print(
                        "Error: Delete package %s failed! Please delete the folder manually.\n"
                        % error_package['name'].encode("utf-8"))
                    return

    # 1.in old ,not in new : Software packages that need to be removed.
    casedelete = sub_list(oldpkgs, newpkgs)
    pkgs_delete_fail_list = []

    for pkg in casedelete:

        removepath_ver = get_package_remove_path(pkg, bsp_packages_path)
        removepath_git = os.path.join(removepath_ver, '.git')

        # Delete. Git directory.
        if os.path.isdir(removepath_ver) and os.path.isdir(removepath_git):
            gitdir = removepath_ver

            print("\nStart to remove %s \nplease wait..." %
                  gitdir.encode("utf-8"))
            if isDeleteOld:
                if rm_package(gitdir) == False:
                    print("Floder delete fail: %s" % gitdir.encode("utf-8"))
                    print("Please delete this folder manually.")
            else:
                print(
                    "The folder is managed by git. Do you want to delete this folder?\n"
                )
                if sys.version_info < (3, 0):
                    rc = raw_input(
                        'Press the Y Key to delete the folder or just press Enter to keep it : '
                    )
                else:
                    rc = input(
                        'Press the Y Key to delete the folder or just press Enter to keep it : '
                    )

                if rc == 'y' or rc == 'Y':
                    try:
                        if rm_package(gitdir) == False:
                            pkgs_delete_fail_list.append(pkg)
                            print("Error: Please delete the folder manually.")
                    except Exception as e:
                        print('Error message:%s%s. error.message: %s\n\t' %
                              ("Delete folder failed: ",
                               gitdir.encode("utf-8"), e))
        else:
            if os.path.isdir(removepath_ver):
                print("Start to remove %s \nplease wait..." %
                      removepath_ver.encode("utf-8"))
                try:
                    pkgsdb.deletepackdir(removepath_ver, dbsqlite_pathname)
                except Exception as e:
                    pkgs_delete_fail_list.append(pkg)
                    print('Error message:\n%s %s. %s \n\t' % (
                        "Delete folder failed, please delete the folder manually",
                        removepath_ver.encode("utf-8"), e))

    if len(pkgs_delete_fail_list):
        # write error messages
        pkgs_file = file(pkgs_error_list_fn, 'w')
        pkgs_file.write(json.dumps(pkgs_delete_fail_list, indent=1))
        pkgs_file.close()
        return
    else:
        # write error messages
        with open(pkgs_error_list_fn, 'w') as f:
            f.write(str(json.dumps(pkgs_delete_fail_list, indent=1)))

    # 2.in new not in old : Software packages to be installed.
    # If the package download fails, record it, and then download again when
    # the update command is executed.

    casedownload = sub_list(newpkgs, oldpkgs)
    # print 'in new not in old:', casedownload
    pkgs_download_fail_list = []

    for pkg in casedownload:
        if install_pkg(env_root, pkgs_root, bsp_root, pkg):
            print(
                "==============================>  %s %s is downloaded successfully. \n"
                % (pkg['name'], pkg['ver']))
        else:
            # If the PKG download fails, record it in the
            # pkgs_download_fail_list.
            pkgs_download_fail_list.append(pkg)
            print(pkg, 'download failed.')
            flag = False

    # Get the currently updated configuration.
    newpkgs = sub_list(newpkgs, pkgs_download_fail_list)

    # Give hints based on the success of the download.
    if len(pkgs_download_fail_list):
        print("\nPackage download failed list:")
        for item in pkgs_download_fail_list:
            print(item)

        print(
            "You need to reuse the <pkgs -update> command to download again.")

    # update pkgs.json and SConscript
    write_storage_file(pkgs_fn, newpkgs)

    # handle download error packages.
    get_flag = handle_download_error_packages(pkgs_fn, bsp_packages_path)

    if get_flag != None:
        flag = get_flag

    # Update the software packages, which the version is 'latest'
    try:
        update_latest_packages(pkgs_fn, bsp_packages_path)
    except KeyboardInterrupt:
        flag = False

    if flag:
        print("Operation completed successfully.")
    else:
        print("Operation failed.")