The project after the change of demand, product iteration, will undergo several revisions, some previously no longer used pictures can not be cleaned up in time, these useless pictures on the one hand to make the structure of the project picture resources more complex, on the other hand will lead to the volume of IPA package becomes larger.
So we need to clean up the image resources that we no longer use, and it's easy to do this with lint in the Android project, there's not much of a good tool in iOS, and we've written a Python script with the resources on the web.
Install the Silver Searcher to search for strings similar to Ack,grep, and search faster than Ack,grep. To install using the command line:
// Install homebrew First " $ (curl-fssl https://raw.github.com/Homebrew/homebrew/go/install) " // Install the Silver SearcherBrew Install The_silver_searcher
You can use the AG, Base command, etc.
" Image " ' ./ ' Os.popen ('echo $PATH') // The Bash command can be executed by Os.popen (' echo $PATH '). Read () reads the result of the execution.
The command that needs to bash be used is the ag "image" ‘./‘ and, the latter is rm -rf ‘./‘ used to delete the folder.
Ignores
You might use the following method to access a picture
for (int1; + +i) { *imagename = [NSString stringWithFormat:@ " image_%d", I]; *image = [UIImage imagenamed:imagename]; ......}
So image_1 such a picture is checked by the script as unused, so the ignores filter is added, and the images contained in this content are ignored.
ignores = {R'image_\d+'R'rlinetraveltype\d+'R'address_\d+'}def Is_ignore (str): forIgnoreinchignores: #print Ignore, Re.match (Ignore, str)ifRe.match (Ignore, str):returnTrue Print"False" returnFalse
The complete code is as follows unuserimg.py
#-*-coding:utf-8-*-import osimport globimport reignores= {R'image_\d+'R'rlinetraveltype\d+'R'address_\d+'}pathi='/adu/workspacen/qunarrn/car_rn/carbundle/images'def find_un_used (): Pics= Glob.glob1 (Pathi,'*.png') Pics= [pic[:-4].replace ('@2x',"') forPicinchpics] Print"pnames: ====================>>>>>>>>>>>>>>>"Print pics Print"pnames: <<<<<<<<<<<<<<<===================="Path='/adu/workspacen/qunarrn/car_rn/car'Unused_pics= [] forPic_nameinch Set(pics):ifIs_ignore (pic_name) = =False:command='AG '%s '%s'%(pic_name, path) result=os.popen (command). Read ()ifresult = ="': Unused_pics.append (pic_name) #os. System ('RM-RF%s'%(pic_name)) Txt_path='Pics.txt'txt='\ n'. Join (sorted (unused_pics)) Os.system ('echo "%s" >%s'%(TXT, txt_path)) print'DONE !!!!!'def is_ignore (str): forIgnoreinchignores: #print Ignore, Re.match (Ignore, str)ifRe.match (Ignore, str):returnTrue Print"False" returnFalsedef Dorm (): Path='/adu/workspacen/qunarrn/car_rn/car'Txt_path='Pics.txt'Pics=Open (Txt_path). ReadLines () forPicinchPics:pic= Pic.strip ('\ n') Sd_pic= path + pic +'. PNG'Hd_pic= path + pic +'@2x.png'Os.system ('rm "%s"'%sd_pic) Os.system ('rm "%s"'%hd_pic) Print'RN done!'if__name__ = ='__main__': find_un_used () #is_ignore ('Image3')
Execute directly at the command line: #python unuserimg.py
Clean up iOS projects without using picture scripts