#-*-coding:utf-8-*-##################################################Features: Internationalization testing for extracting Chinese characters from the app design package and outputting the report#Yuebai 20160328#Extract ---Filter---finishing path---extracting Chinese---output report##################################################ImportOSImportShutilImportSYSImportReImportZipFileImportGlobworkpath="c:\\users\\yuebai\\desktop\\ Internationalization Test Pack"Reportpath="c:\\users\\yuebai\\desktop\\ Internationalization Output report"#Defining log FunctionsdefLoginfo (Info): Log= Open ("%s\\run.log"%workpath,"a") Log.write ("[Info]%s\n"%info) log.close ()#Define decompression file functionsdefExtractzip (Filename,extrapath): F= ZipFile. ZipFile (FileName,"R") F.extractall (Extrapath) f.close () Loginfo ("%s File decompression complete"%fileName)#function function to find Chinese charactersdefGetchinese (Filefullpath): Ischinese= Re.compile ("([\u4e00-\u9fa5]+) +?") F= Open (Filefullpath,"R", encoding="UTF-8")#Open File to extractf_in = open ("%s\\chinesetxt.txt"%reportpath,"a")#Open Output File forLineinchf.readlines (): Getstr= Ischinese.findall (str (line))#row by line to extract Chinese if notGetstr = =[]: F_in.write ("find Chinese characters (╯ '-') ╯︵┻━┻, file path is%s\n"%filefullpath) F_in.write ("%s\n"%Line ) F.close () f_in.close () Loginfo ("find complete, Output report path:%s"%Reportpath)#function function, list all files under pathdefListany (workpath):if notos.path.exists (workpath):Print("error,no such dictionary%s,plz check"%workpath) Ziplist=Os.listdir (Workpath)returnziplist#Delete a package that is not a zip typeNotziplist = Glob.glob ("%s\\*[!p]"%workpath) Loginfo ("notziplist =%s,prepare to delete"%notziplist) forIinchNotZipList:os.remove (i) Loginfo ("Delete Non-zip package complete")#get a list of zip packagesZiplist =Listany (Workpath)#extracting the ZIP package#print ("Start extraction") forZipPackageinchZiplist:zipname= Os.path.split (ZipPackage) [0]#cut get file nameExtrapath = Os.path.join (workpath,zipname)#Create a folder with the same name as the ZIP package under the current folder to extract the target pathos.makedirs (Extrapath) loginfo ("Construction Decompression Path complete, Extrapath =%s"%extrapath) Extrafilepath= Os.path.join (Workpath,zippackage)#absolute path of files to unzip #Start unpacking zip package, delete source zip file after completionExtractzip (Extrafilepath, Extrapath) os.remove (Extrafilepath)#summarize the process files under the extended directory to \\plan ifOs.path.exists ("%s\\plans\\extend"%extrapath): Tmpextendpath= ("%s\\plans\\extend"%extrapath) Tmpplanpath= ("%s\\plans"%Extrapath) forTinchOs.listdir (Tmpextendpath): T_fullpath= ("%s\\%s\\"%(tmpextendpath,t))#print ("T_fullpath =", T_fullpath) ifOs.path.isfile (T_fullpath): Shutil.move (T_fullpath,tmpplanpath)#call Getchinese, extract Chinese characters forYinchOs.listdir (Tmpplanpath): Y_fullpath=Os.path.join (tmpplanpath,y)#print (Y_fullpath)Loginfo ("start Check file%s, check the result path:%s"%(Y_fullpath,reportpath)) Getchinese (Y_fullpath)Print("fetch complete, result path:%s"%Reportpath)
Use Python to extract Chinese characters