最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python一鍵查找iOS項(xiàng)目中未使用的圖片、音頻、視頻資源

 更新時(shí)間:2019年08月12日 13:45:32   作者:金三胖  
這篇文章主要介紹了Python-一鍵查找iOS項(xiàng)目中未使用的圖片、音頻、視頻資源,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

前言

在iOS項(xiàng)目開發(fā)的過(guò)程中,如果版本迭代開發(fā)的時(shí)間比較長(zhǎng),那么在很多版本開發(fā)以后或者說(shuō)有多人開發(fā)參與以后,工程中難免有一些垃圾資源,未被使用卻占據(jù)著api包的大??!

這里我通過(guò)Python腳本來(lái)查找項(xiàng)目中未被使用的圖片、音頻、視頻資源,然后刪除掉;以達(dá)到減小APP包大小的目的!

代碼

先查找項(xiàng)目中所以的資源文件存到你數(shù)組里面

def searchAllResName(file_dir):
 global _resNameMap
 fs = os.listdir(file_dir)
 for dir in fs:
  tmp_path = os.path.join(file_dir, dir)
  if not os.path.isdir(tmp_path):
   if isResource(tmp_path) == True and '/Pods/' not in tmp_path and '.appiconset' not in tmp_path and '.launchimage' not in tmp_path:
    imageName = tmp_path.split('/')[-1].split('.')[0]
    _resNameMap[imageName] = tmp_path
    conLog.info_delRes('[FindRes OK] ' + tmp_path)
  elif os.path.isdir(tmp_path) and tmp_path.endswith('.imageset') and '/Pods/' not in tmp_path:
   imageName = tmp_path.split('/')[-1].split('.')[0]
   _resNameMap[imageName] = tmp_path
   conLog.info_delRes('[FindRes OK] ' + tmp_path)
  else:
   searchAllResName(tmp_path)

遍歷查詢項(xiàng)目的所以代碼,查找工程中所引用的資源文件

# 查詢項(xiàng)目的所以代碼
def searchProjectCode(file_dir):
 global _projectPbxprojPath
 fs = os.listdir(file_dir)
 for dir in fs:
  tmp_path = os.path.join(file_dir, dir)
  if tmp_path.endswith('project.pbxproj'):
   _projectPbxprojPath = tmp_path
  if not os.path.isdir(tmp_path):
   if '/Pods/' not in tmp_path:
    try:
     findResNameAtFileLine(tmp_path)
     conLog.info_delRes('[ReadFileForRes OK] ' + tmp_path)
    except Exception as e:
     pass
     # conLog.error_delRes('[ReadFileForRes Fail] [' + str(e) + ']' + tmp_path)
  else:
   searchProjectCode(tmp_path)
# 查找工程中所引用的資源文件
def findResNameAtFileLine(tmp_path):
 global _resNameMap
 Ropen = open(tmp_path,'r')
 for line in Ropen:
  lineList = line.split('"')
  for item in lineList:
   # bar@2x barimg.png
   if item in _resNameMap or item.split('.')[0] in _resNameMap or item + '@1x' in _resNameMap or item + '@2x' in _resNameMap or item + '@3x' in _resNameMap:
    del _resNameMap[item]
 
 Ropen.close()

刪除垃圾資源文件,這里垃圾資源文件刪除分為兩部分一部分是Assets.xcassets里面的,一部分是直接導(dǎo)入工程目錄中的資源,如果是Assets.xcassets垃圾資源直接刪除就行了,但是如果是直接導(dǎo)入到工程目錄里面的資源,那就先刪除project.pbxproj中的引用,再刪除本地資源文件;

# 刪除無(wú)用的資源文件
def delAllRubRes():
 global _resNameMap, _hadDelMap
 # .imageset類型的資源圖片直接刪除
 for resName in list(_resNameMap.keys()):
  tmp_path = _resNameMap[resName]
  if tmp_path.endswith('.imageset'):
   if os.path.exists(tmp_path) and os.path.isdir(tmp_path):
    try:
     # 已刪除的元素
     _hadDelMap[resName] = tmp_path
     # 刪除.imageset文件夾
     delImagesetFolder(tmp_path)
     # 字典移除
     del _resNameMap[resName]
     conLog.info_delRes('[DelRubRes OK] ' + tmp_path)
    except Exception as e:
     conLog.error_delRes('[DelRubRes Fail] [' + str(e) + ']' + tmp_path)
   else:
    conLog.error_delRes('[DelRubRes Fail] [not exists] ' + tmp_path)
 delResAtProjectPbxproj()
def delImagesetFolder(rootdir):
 filelist = []
 filelist = os.listdir(rootdir)
 for f in filelist:
  filepath = os.path.join( rootdir, f )
  if os.path.isfile(filepath):
   os.remove(filepath)
  elif os.path.isdir(filepath):
   shutil.rmtree(filepath,True)
 shutil.rmtree(rootdir,True)
# 直接導(dǎo)入到工程中的圖片需要?jiǎng)h除project.pbxproj中的引用,再移除本地文件
def delResAtProjectPbxproj():
 global _projectPbxprojPath, _resNameMap, _hadDelMap
 if _projectPbxprojPath != None:
  # 先把需要?jiǎng)h除的資源名先保存一份
  _needDelResName = []
  file_data = ''
  Ropen = open(_projectPbxprojPath,'r')
  for line in Ropen:
   idAdd = True
   for resName in _resNameMap:
    if resName in line:
     idAdd = False
     if resName not in _needDelResName:
      _needDelResName.append(resName)
   if idAdd == True:
    file_data += line
  Ropen.close()
  Wopen = open(_projectPbxprojPath,'w')
  Wopen.write(file_data)
  Wopen.close()
  # 已經(jīng)清理過(guò)project.pbxproj中的引用的資源文件,開始從_resNameMap中移除已被處理過(guò)的資源文件
  # 并刪除本地的對(duì)應(yīng)的資源文件
  for item in _needDelResName:
   tmp_path = _resNameMap[item]
   if os.path.exists(tmp_path) and not os.path.isdir(tmp_path):
    # 已刪除的元素
    _hadDelMap[item] = tmp_path
    # 刪除文件
    os.remove(tmp_path)
    # 字典移除
    del _resNameMap[item]
    conLog.info_delRes('[DelRubRes OK] ' + tmp_path)
   else:
    pass

總的調(diào)用函數(shù)

# 開始清理無(wú)用的垃圾資源文件
def startCleanRubRes(file_dir, ignoreList = []):
 global _resNameMap, _hadDelMap,_isCleaing
 if _isCleaing == True:
  return
 _isCleaing = True
 initData()
 conLog.info('-' * 30 + '開始清理資源文件' + '-' * 30)
 searchAllResName(file_dir)
 conLog.info_delRes('-' * 20 + '全部的資源文件列表' + '-' * 20)
 conLog.info_delRes(_resNameMap)
 for item in ignoreList:
  if item in list(_resNameMap.keys()):
   del _resNameMap[item]
 conLog.info_delRes('-' * 20 + '忽略刪除的資源文件' + '-' * 20)
 conLog.info_delRes(ignoreList)
 searchProjectCode(file_dir)
 conLog.info_delRes('-' * 20 + '需要?jiǎng)h除的資源文件' + '-' * 20)
 conLog.info_delRes(_resNameMap)
 delAllRubRes()
 conLog.info_delRes('-' * 20 + '刪除成功的資源文件' + '-' * 20)
 conLog.info_delRes(_hadDelMap)
 conLog.info_delRes('-' * 20 + '刪除失敗的資源文件' + '-' * 20)
 conLog.info_delRes(_resNameMap)
 _isCleaing = False

軟件

鑒于有些iOS開發(fā)程序員沒有Python基礎(chǔ),這里做了一個(gè)圖形化操作界面,歡迎大家下載使用!

下載地址:

https://gitee.com/zfj1128/ZFJ...

軟件截圖:

總結(jié)

以上所述是小編給大家介紹的Python一鍵查找iOS項(xiàng)目中未使用的圖片、音頻、視頻資,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • Python實(shí)現(xiàn)OpenCV的安裝與使用示例

    Python實(shí)現(xiàn)OpenCV的安裝與使用示例

    這篇文章主要介紹了Python實(shí)現(xiàn)OpenCV的安裝與使用,結(jié)合實(shí)例形式分析了Python中OpenCV的安裝及針對(duì)圖片的相關(guān)操作技巧,需要的朋友可以參考下
    2018-03-03
  • python多維數(shù)組分位數(shù)的求取方式

    python多維數(shù)組分位數(shù)的求取方式

    這篇文章主要介紹了python多維數(shù)組分位數(shù)的求取方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • python關(guān)鍵字傳遞參數(shù)實(shí)例分析

    python關(guān)鍵字傳遞參數(shù)實(shí)例分析

    在本篇文章里小編給大家整理的是一篇關(guān)于python關(guān)鍵字傳遞參數(shù)實(shí)例分析內(nèi)容,有需要的朋友們可以學(xué)習(xí)參考下。
    2021-06-06
  • Django框架使用內(nèi)置方法實(shí)現(xiàn)登錄功能詳解

    Django框架使用內(nèi)置方法實(shí)現(xiàn)登錄功能詳解

    這篇文章主要介紹了Django框架使用內(nèi)置方法實(shí)現(xiàn)登錄功能,結(jié)合實(shí)例形式詳細(xì)分析了Django框架內(nèi)置方法實(shí)現(xiàn)登錄功能的相關(guān)操作技巧與使用注意事項(xiàng),需要的朋友可以參考下
    2019-06-06
  • pytorch 如何使用batch訓(xùn)練lstm網(wǎng)絡(luò)

    pytorch 如何使用batch訓(xùn)練lstm網(wǎng)絡(luò)

    這篇文章主要介紹了pytorch 如何使用batch訓(xùn)練lstm網(wǎng)絡(luò)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • 基于Python3讀寫INI配置文件過(guò)程解析

    基于Python3讀寫INI配置文件過(guò)程解析

    這篇文章主要介紹了基于Python3讀寫INI配置文件過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Python讀取Excel數(shù)據(jù)實(shí)現(xiàn)批量生成PPT

    Python讀取Excel數(shù)據(jù)實(shí)現(xiàn)批量生成PPT

    我們常常面臨著大量的重復(fù)性工作,通過(guò)人工方式處理往往耗時(shí)耗力易出錯(cuò)。而Python在辦公自動(dòng)化方面具有天然優(yōu)勢(shì)。本文將利用讀取Excel數(shù)據(jù)并實(shí)現(xiàn)批量生成PPT,需要的可以參考一下
    2022-05-05
  • Python實(shí)現(xiàn)一鍵收發(fā)郵件

    Python實(shí)現(xiàn)一鍵收發(fā)郵件

    這篇文章主要為大家詳細(xì)介紹了如何使用Python實(shí)現(xiàn)一鍵收發(fā)郵件功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-12-12
  • Pyecharts V1和V0.5之間相互切換的方法

    Pyecharts V1和V0.5之間相互切換的方法

    這篇文章主要介紹了Pyecharts V1和V0.5之間相互切換的方法,Pyecharts這個(gè)可視化庫(kù)火爆,官方如是說(shuō):Echarts 是一個(gè)由百度開源的數(shù)據(jù)可視化,憑借著良好的交互性,精巧的圖表設(shè)計(jì),得到了眾多開發(fā)者的認(rèn)可,下面和小編一起進(jìn)入文章了解具體內(nèi)容吧
    2022-02-02
  • python與idea的集成的實(shí)現(xiàn)

    python與idea的集成的實(shí)現(xiàn)

    這篇文章主要介紹了 python與idea的集成的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11

最新評(píng)論

灌南县| 连山| 哈巴河县| 隆子县| 治县。| 鄂托克前旗| 尉犁县| 肇源县| 康平县| 左权县| 抚宁县| 嘉善县| 吉安县| 海伦市| 兴和县| 黔南| 永靖县| 石渠县| 荥阳市| 大竹县| 揭西县| 资中县| 修水县| 大同市| 榆林市| 鄄城县| 泉州市| 灵武市| 越西县| 鄂伦春自治旗| 苏尼特左旗| 石屏县| 建始县| 肥东县| 灵台县| 玉环县| 汕头市| 遂昌县| 潮州市| 平定县| 章丘市|