diff --git a/.gitignore b/.gitignore index 7bbc71c0..9eb72a81 100644 --- a/.gitignore +++ b/.gitignore @@ -99,3 +99,6 @@ ENV/ # mypy .mypy_cache/ +.vscode/settings.json +cmds/.config.old +/cmds/.config diff --git a/archive.py b/archive.py index ad938bc5..24117f41 100644 --- a/archive.py +++ b/archive.py @@ -103,7 +103,8 @@ def unpack(archive_fn, path, pkg, pkgs_name_in_json): def packtest(path): ret = True - if ".zip" in path: + + if path.find(".zip") != -1: try: if zipfile.is_zipfile(path): # Test zip again to make sure it's a right zip file. @@ -114,24 +115,26 @@ def packtest(path): else: ret = False print('package check error. \n') - except Exception, e: - print('packtest e.message:%s\t' % e.message) -# arch.close() + except Exception as e: + print('packtest error message:%s\t' % e) print("The archive package is broken. \n") + arch.close() ret = False - if ".tar.bz2" in path: + # if ".tar.bz2" in path:. + if path.find(".tar.bz2") != -1: try: if not tarfile.is_tarfile(path): ret = False - except Exception, e: + except Exception as e: ret = False - if ".tar.gz" in path: + # if ".tar.gz" in path: + if path.find(".tar.gz") != -1: try: if not tarfile.is_tarfile(path): ret = False - except Exception, e: + except Exception as e: ret = False return ret diff --git a/cmds/cmd_menuconfig.py b/cmds/cmd_menuconfig.py index 7e86d677..a8a75d60 100644 --- a/cmds/cmd_menuconfig.py +++ b/cmds/cmd_menuconfig.py @@ -101,9 +101,9 @@ def mk_rtconfig(filename): def find_macro_in_config(filename, macro_name): try: - config = file(filename) + config = open(filename, "r") except: - print 'open .config failed' + print('open .config failed') return empty_line = 1 @@ -141,6 +141,7 @@ def find_macro_in_config(filename, macro_name): if setting[0] == macro_name and setting[1] == 'y': return True + config.close() return False @@ -178,7 +179,7 @@ def cmd(args): os.system('chcp 437 > nul') if args.menuconfig_fn: - print 'use', args.menuconfig_fn + print('use', args.menuconfig_fn) import shutil shutil.copy(args.menuconfig_fn, fn) elif args.menuconfig_g: @@ -236,18 +237,18 @@ def cmd(args): if find_macro_in_config(fn, 'SYS_AUTO_UPDATE_PKGS'): os.system('pkgs --update') - print "==============================>The packages have been updated completely." + 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" + 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" + 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" + print("Create iar project done") def add_parser(sub): diff --git a/cmds/cmd_package.py b/cmds/cmd_package.py index 608f96ac..82143bd3 100644 --- a/cmds/cmd_package.py +++ b/cmds/cmd_package.py @@ -36,6 +36,10 @@ import logging import archive import sys +from package import Package, Bridge_SConscript, Kconfig_file, Package_json_file, Sconscript_file +from vars import Import, Export +from string import Template +from .cmd_menuconfig import find_macro_in_config try: import requests @@ -49,11 +53,6 @@ "* $ sudo apt-get install python-requests\n" "****************************************\n") -from package import Package, Bridge_SConscript, Kconfig_file, Package_json_file, Sconscript_file -from vars import Import, Export -from string import Template -from cmd_menuconfig import find_macro_in_config - """package command""" def execute_command(cmdstring, cwd=None, shell=True): @@ -67,7 +66,7 @@ def execute_command(cmdstring, cwd=None, shell=True): stdout_str = '' while sub.poll() is None: - stdout_str += sub.stdout.read() + stdout_str += str(sub.stdout.read()) time.sleep(0.1) return stdout_str @@ -86,12 +85,32 @@ def user_input(msg, default_value): msg = '%s[%s]' % (msg, default_value) print(msg) - value = raw_input() + if sys.version_info < (3, 0): + value = raw_input() + else: + value = input() + if value == '': value = default_value return value +def union_input(msg = None): + """Gets the union keyboard input.""" + + if sys.version_info < (3, 0): + if msg != None: + value = raw_input(msg) + else: + value = raw_input() + else: + if msg != None: + value = input(msg) + else: + value = input() + + return value + def get_mirror_giturl(submod_name): """Gets the submodule's url on mirror server. @@ -138,14 +157,24 @@ def modify_submod_file_to_mirror(submod_path): return replace_list - except Exception, e: - print('e.message:%s\t' % e.message) + except Exception as e: + print('error message:%s\t' % e) def get_url_from_mirror_server(pkgs_name_in_json, pkgs_ver): """Get the download address from the mirror server based on the package name.""" - payload_pkgs_name_in_json = pkgs_name_in_json.encode("utf-8") + try: + if type(pkgs_name_in_json) != type("str"): + if sys.version_info < (3, 0): + pkgs_name_in_json = str(pkgs_name_in_json) + else: + pkgs_name_in_json = str(pkgs_name_in_json)[2:-1] + except Exception as e: + print('error message:%s' % e) + print("\nThe mirror server could not be contacted. Please check your network connection.") + return None, None + payload = { "userName": "RT-Thread", "packages": [ @@ -154,19 +183,16 @@ def get_url_from_mirror_server(pkgs_name_in_json, pkgs_ver): } ] } - payload["packages"][0]['name'] = payload_pkgs_name_in_json + payload["packages"][0]['name'] = pkgs_name_in_json - try: - r = requests.post( - "http://packages.rt-thread.org/packages/queries", data=json.dumps(payload)) + # print(payload) - # print(r.status_code) + try: + r = requests.post("http://packages.rt-thread.org/packages/queries", data=json.dumps(payload)) if r.status_code == requests.codes.ok: package_info = json.loads(r.text) - # print(package_info) - # Can't find package,change git package SHA if it's a git # package if len(package_info['packages']) == 0: @@ -185,11 +211,10 @@ def get_url_from_mirror_server(pkgs_name_in_json, pkgs_ver): print("\nTips : \nThe system needs to be upgraded.") print("Please use the command to upgrade packages index.\n") - return None, None - except Exception, e: - # print('e.message:%s\t' % e.message) + except Exception as e: + print('error message:%s' % e) print("\nThe mirror server could not be contacted. Please check your network connection.") return None, None @@ -213,8 +238,8 @@ def determine_url_valid(url_from_srv): return True - except Exception, e: - # print('e.message:%s\t' % e.message) + except Exception as e: + print('error message:%s\t' % e) print('Network connection error or the url : %s is invalid.\n' % url_from_srv.encode("utf-8")) @@ -267,8 +292,8 @@ def install_pkg(env_root, pkgs_root, bsp_root, pkg): ver_sha = get_ver_sha upstream_change_flag = True - except Exception, e: - # print('e.message:%s\t' % e.message) + 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': @@ -277,13 +302,15 @@ def install_pkg(env_root, pkgs_root, bsp_root, pkg): repo_path = repo_path + '-' + pkg['ver'] repo_path_full = '"' + repo_path + '"' - cmd = 'git clone ' + package_url + ' ' + repo_path_full - execute_command(cmd, cwd=bsp_pkgs_path) + clone_cmd = 'git clone ' + package_url + ' ' + repo_path_full + execute_command(clone_cmd, cwd=bsp_pkgs_path) - cmd = 'git checkout -q ' + ver_sha - execute_command(cmd, cwd=repo_path) - except Exception, e: + 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: @@ -319,27 +346,27 @@ def install_pkg(env_root, pkgs_root, bsp_root, pkg): else: # Download a package of compressed package type. - if not package.download(pkg['ver'], local_pkgs_path.decode("gbk"), package_url): + 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.encode("gbk")): + 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.encode("gbk")): + if not os.path.exists(pkg_dir): try: - if not package.unpack(pkg_fullpath.encode("gbk"), bsp_pkgs_path, pkg, pkgs_name_in_json.encode("gbk")): + if not package.unpack(pkg_fullpath, bsp_pkgs_path, pkg, pkgs_name_in_json): ret = False - except Exception, e: + except Exception as e: os.remove(pkg_fullpath) ret = False - print('e.message: %s\t' % e.message) + print('error message: %s\t' % e) else: print("The file does not exist.") return ret @@ -436,8 +463,8 @@ def get_pkg_folder_by_orign_path(orign_path, version): def git_cmd_exec(cmd, cwd): try: execute_command(cmd, cwd=cwd) - except Exception, e: - print('error message:%s%s. %s \n\t' %(cwd.encode("utf-8"), " path doesn't exist", e.message)) + except Exception as e: + print('error message:%s%s. %s \n\t' %(cwd.encode("utf-8"), " path doesn't exist", e)) print("You can solve this problem by manually removing old packages and re-downloading them using env.") @@ -489,7 +516,8 @@ def update_latest_packages(pkgs_fn, bsp_packages_path): cmd = 'git remote set-url origin ' + mirror_url[0] git_cmd_exec(cmd, repo_path) - except Exception, e: + except Exception as e: + print("error message : %s" % e) print("Failed to connect to the mirror server, using non-mirror server to update.") # Update the package repository from upstream. @@ -506,10 +534,9 @@ def update_latest_packages(pkgs_fn, bsp_packages_path): git_cmd_exec(cmd, repo_path) else: print("Can't find the package : %s's url in file : %s" % - (payload_pkgs_name_in_json.encode("utf-8"), pkg_path.encode("utf-8"))) + (payload_pkgs_name_in_json, pkg_path)) - print("==============================> %s update done \n" % - (pkgs_name_in_json.encode("utf-8"))) + print("==============================> %s update done\n" %(pkgs_name_in_json)) def pre_package_update(): @@ -544,13 +571,12 @@ def pre_package_update(): 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') + dbsqlite_pathname = dbsqlite_pathname.encode('utf-8').decode('gbk') # Avoid creating tables more than one time if not os.path.isfile(dbsqlite_pathname): @@ -561,6 +587,9 @@ def pre_package_update(): fn = '.config' pkgs = kconfig.parse(fn) + + # print("newpkgs", pkgs) + newpkgs = pkgs if not os.path.exists(bsp_packages_path): @@ -580,6 +609,8 @@ def pre_package_update(): with open(pkgs_fn, 'r') as f: oldpkgs = json.load(f) + # print("oldpkgs", oldpkgs) + # regenerate file : packages/pkgs_error.json pkgs_error_list_fn = os.path.join( bsp_packages_path, 'pkgs_error.json') @@ -597,10 +628,8 @@ def pre_package_update(): # 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() + with open(os.path.join(bsp_packages_path, 'SConscript'),'w') as f: + f.write(str(Bridge_SConscript)) return [oldpkgs, newpkgs, pkgs_error, pkgs_fn, pkgs_error_list_fn, bsp_packages_path, dbsqlite_pathname] @@ -627,7 +656,7 @@ def error_packages_handle(error_packages_list, read_back_pkgs_json, pkgs_fn): pkg['name'].encode("utf-8"), pkg['ver'].encode("utf-8"))) else: error_packages_redownload_error_list.append(pkg) - print pkg, 'download failed.' + print(pkg, 'download failed.') flag = False if len(error_packages_redownload_error_list): @@ -721,9 +750,8 @@ def write_storage_file(pkgs_fn, newpkgs): next update. """ - pkgs_file = file(pkgs_fn, 'w') - pkgs_file.write(json.dumps(newpkgs, indent=1)) - pkgs_file.close() + with open(pkgs_fn,'w') as f: + f.write(str(json.dumps(newpkgs, indent=1))) def package_update(isDeleteOld=False): @@ -758,6 +786,9 @@ def package_update(isDeleteOld=False): 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( @@ -790,27 +821,29 @@ def package_update(isDeleteOld=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 : ') + 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, e: + except Exception as e: print('Error message:%s%s. error.message: %s\n\t' % - ("Delete folder failed: ", gitdir.encode("utf-8"), e.message)) + ("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, e: + 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.message)) + "Delete folder failed, please delete the folder manually", removepath_ver.encode("utf-8"), e)) if len(pkgs_delete_fail_list): # write error messages @@ -820,9 +853,8 @@ def package_update(isDeleteOld=False): return else: # 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() + 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 @@ -840,7 +872,7 @@ def package_update(isDeleteOld=False): # If the PKG download fails, record it in the # pkgs_download_fail_list. pkgs_download_fail_list.append(pkg) - print pkg, 'download failed.' + print(pkg, 'download failed.') flag = False # Get the currently updated configuration. @@ -890,10 +922,10 @@ def package_wizard(): #first step print ('\033[5;33;40m\n1.Please input a new package name :\033[0m') - name = raw_input() + name = union_input() while name == '' or name.isspace() == True : print ('\033[1;31;40mError: you must input a package name. Try again.\033[0m') - name = raw_input() + name = union_input() default_description = 'Please add description of ' + name + ' in English.' #description = user_input('menuconfig option name,default:\n',default_description) @@ -911,37 +943,37 @@ def package_wizard(): 'peripherals', 'security', 'system', 'tools', 'peripherals/sensors') print ('\033[5;33;40m\n3.Please choose a package category from 1 to 9 : \033[0m') print ("\033[1;32;40m[1:iot]|[2:language]|[3:misc]|[4:multimedia]|[5:peripherals]|[6:security]|[7:system]|[8:tools]|[9:sensors]\033[0m") - classnu = raw_input() + classnu = union_input() while classnu == '' or classnu.isdigit()== False or int(classnu) < 1 or int(classnu) >9: if classnu == '' : print ('\033[1;31;40mError: You must choose a package category. Try again.\033[0m') else : print ('\033[1;31;40mError: You must input an integer number from 1 to 9. Try again.\033[0m') - classnu = raw_input() + classnu = union_input() pkgsclass = packageclass[int(classnu) - 1] #fourth step print ('\033[5;33;40m\n4.Please input author name of this package :\033[0m') - authorname = raw_input() + authorname = union_input() while authorname == '': print ('\033[1;31;40mError: you must input author name of this package. Try again.\033[0m') - authorname = raw_input() + authorname = union_input() #fifth step - authoremail = raw_input('\033[5;33;40m\n5.Please input author email of this package :\n\033[0m') + authoremail = union_input('\033[5;33;40m\n5.Please input author email of this package :\n\033[0m') while authoremail == '': print ('\033[1;31;40mError: you must input author email of this package. Try again.\033[0m') - authoremail = raw_input() + authoremail = union_input() #sixth step print ('\033[5;33;40m\n6.Please choose a license of this package from 1 to 4, or input other license name :\033[0m') print ("\033[1;32;40m[1:Apache-2.0]|[2:MIT]|[3:LGPL-2.1]|[4:GPL-2.0]\033[0m") license_index = ('Apache-2.0', 'MIT', 'LGPL-2.1', 'GPL-2.0') - license_class = raw_input() + license_class = union_input() while license_class == '' : print ('\033[1;31;40mError: you must choose or input a license of this package. Try again.\033[0m') - license_class = raw_input() + license_class = union_input() if license_class.isdigit()== True and int(license_class) >= 1 and int(license_class) <= 4: license = license_index[int(license_class) - 1] @@ -952,10 +984,10 @@ def package_wizard(): print ('\033[5;33;40m\n7.Please input the repository of this package :\033[0m') print ("\033[1;32;40mFor example, hello package's repository url is 'https://github.com/RT-Thread-packages/hello'.\033[0m") - repository = raw_input() + repository = union_input() while repository == '': print ('\033[1;31;40mError: you must input a repository of this package. Try again.\033[0m') - repository = raw_input() + repository = union_input() pkg_path = name if not os.path.exists(pkg_path): diff --git a/env.py b/env.py index 02cd8f70..18a4efa7 100644 --- a/env.py +++ b/env.py @@ -70,11 +70,11 @@ def main(): Export('pkgs_root') try: - bsp_root.decode("ascii") - except Exception, e: + bsp_root.encode('utf-8').decode("ascii") + except Exception as e: if platform.system() == "Windows": os.system('chcp 65001 > nul') - + print ("\n\033[1;31;40m警告:\033[0m") print ("\033[1;31;40m当前路径不支持非英文字符,请修改当前路径为纯英文路径。\033[0m") print ("\033[1;31;40mThe current path does not support non-English characters.\033[0m") diff --git a/init_env.py b/init_env.py index d19dff17..500fb0d9 100644 --- a/init_env.py +++ b/init_env.py @@ -34,7 +34,7 @@ def run_proc(name, env_root): try: os.system("python %s package --upgrade 1>%s 2>%s"%(exec_file, log_std, log_err)) - except Exception, e: + except Exception as e: print("Auto upgrade failed, please check your network.") pass diff --git a/kconfig.py b/kconfig.py index ff803216..0e904203 100644 --- a/kconfig.py +++ b/kconfig.py @@ -1,4 +1,4 @@ -# -*- coding:utf-8 -*- + # -*- coding:utf-8 -*- # # File : kconfig.py # This file is part of RT-Thread RTOS @@ -26,7 +26,7 @@ def pkgs_path(pkgs, name, path): for pkg in pkgs: - if pkg.has_key('name') and pkg['name'] == name: + if 'name' in pkg and pkg['name'] == name: pkg['path'] = path return @@ -38,7 +38,7 @@ def pkgs_path(pkgs, name, path): def pkgs_ver(pkgs, name, ver): for pkg in pkgs: - if pkg.has_key('name') and pkg['name'] == name: + if 'name' in pkg and pkg['name'] == name: pkg['ver'] = ver return @@ -51,9 +51,9 @@ def pkgs_ver(pkgs, name, ver): def parse(filename): ret = [] try: - config = file(filename) + config = open(filename, "r") except: - print 'open .config failed' + print('open .config failed') return ret for line in config: @@ -69,10 +69,8 @@ def parse(filename): if len(setting) >= 2: if setting[0].startswith('CONFIG_PKG_'): pkg_prefix = setting[0][11:] - if pkg_prefix.startswith('USING_'): pkg_name = pkg_prefix[6:] - # print 'enable package:', pkg_name else: if pkg_prefix.endswith('_PATH'): pkg_name = pkg_prefix[:-5] @@ -92,6 +90,7 @@ def parse(filename): pkg_ver = pkg_ver[:-1] pkgs_ver(ret, pkg_name, pkg_ver) + config.close() return ret diff --git a/package.py b/package.py index cde59285..0d9894ab 100644 --- a/package.py +++ b/package.py @@ -130,8 +130,8 @@ class Package: pkg = None def parse(self, filename): - f = file(filename) - json_str = f.read() + with open(filename, "r") as f: + json_str = f.read() if json_str: self.pkg = json.loads(json_str) @@ -171,7 +171,7 @@ def download(self, ver, path, url_from_srv): ret = True url = self.get_url(ver) site = self.get_site(ver) - if site and site.has_key('filename'): + if site and 'filename' in site: filename = site['filename'] path = os.path.join(path, filename) else: @@ -204,7 +204,7 @@ def download(self, ver, path, url_from_srv): flush_count = 0 - with open(path.encode("gbk"), 'wb') as f: + with open(path, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: f.write(chunk) @@ -214,27 +214,28 @@ def download(self, ver, path, url_from_srv): sys.stdout.flush() retryCount = retryCount + 1 - if archive.packtest(path.encode("gbk")): # make sure the file is right + + if archive.packtest(path): # make sure the file is right ret = True print("\rDownloded %d KB " % flush_count) print('Start to unpack. Please wait...') break else: - if os.path.isfile(path.encode("gbk")): - os.remove(path.encode("gbk")) + if os.path.isfile(path): + os.remove(path) if retryCount > 5: print( "error: Have tried downloading 5 times.\nstop Downloading file :%s" % path) - if os.path.isfile(path.encode("gbk")): - os.remove(path.encode("gbk")) + if os.path.isfile(path): + os.remove(path) ret = False break - except Exception, e: - #print url_from_srv - # print('e.message:%s\t' % e.message) + except Exception as e: + print(url_from_srv) + print('error message:%s\t' %e) retryCount = retryCount + 1 if retryCount > 5: - print('%s download fail!\n' % path.decode("gbk").encode("utf-8")) + print('%s download fail!\n' % path.encode("utf-8")) if os.path.isfile(path): os.remove(path) return False @@ -245,8 +246,8 @@ def unpack(self, fullpkg_path, path, pkg, pkgs_name_in_json): # ignore the return value archive.unpack(fullpkg_path, path, pkg, pkgs_name_in_json) return True - except Exception, e: - print('unpack e.message:%s\t' % e.message) + except Exception as e: + print('unpack error message :%s' % e) print('unpack %s failed' % os.path.basename(fullpkg_path)) os.remove(fullpkg_path) return False diff --git a/pkgsdb.py b/pkgsdb.py index 47a01b3f..488008cb 100644 --- a/pkgsdb.py +++ b/pkgsdb.py @@ -26,6 +26,7 @@ import sqlite3 import os import hashlib +import sys from vars import Import SHOW_SQL = False @@ -35,7 +36,7 @@ def GetFileMd5(filename): if not os.path.isfile(filename): return myhash = hashlib.md5() - f = file(filename, 'rb') + f = open(filename, 'rb') while True: b = f.read(8096) if not b: @@ -118,7 +119,7 @@ def savetodb(pathname, pkgspathname, before_change_name): bsp_root = Import('bsp_root') bsppkgs = os.path.join(bsp_root, 'packages') - conn = get_conn(dbpathname.decode("gbk")) + conn = get_conn(dbpathname) save_sql = '''insert into packagefile values (?, ?, ?)''' package = os.path.basename(pkgspathname) md5pathname = os.path.join(bsppkgs, before_change_name) @@ -139,9 +140,9 @@ def dbdump(dbpathname): c = get_cursor(conn) cursor = c.execute("SELECT pathname, package, md5 from packagefile") for row in cursor: - print "pathname = ", row[0] - print "package = ", row[1] - print "md5 = ", row[2], "\n" + print("pathname = ", row[0]) + print("package = ", row[1]) + print("md5 = ", row[2], "\n") conn.close() #delete the unchanged file @@ -178,8 +179,11 @@ def remove_unchangedfile(pathname, dbpathname, dbsqlname): print ('Are you sure you want to permanently delete the file: %s?' % os.path.basename(pathname)) print ('If you choose to keep the changed file,you should copy the file to another folder. \nbecaues it may be covered by the next update.') - rc = raw_input( - 'Press the Y Key to delete the file or just press Enter to keep the file.') + + if sys.version_info < (3, 0): + rc = raw_inuput('Press the Y Key to delete the file or just press Enter to keep the file.') + else: + rc = input('Press the Y Key to delete the file or just press Enter to keep the file.') if rc == 'y' or rc == 'Y': sql = "DELETE from packagefile where pathname = '" + dbsqlname + "'" cursor = c.execute(sql)