最近看了下阿里的 mPass莺丑,發(fā)現(xiàn)是真滴狠,拉下來好多倉庫墩蔓,眼睛都花了梢莽。
和原有項(xiàng)目里的庫混在一起,無法分清了奸披,所以寫了一個pthon
腳本昏名,來幫我把 mPass 的依賴 pods 庫分離出來,方便自己看阵面。
分享一下轻局,給有同樣煩惱的朋友。
后續(xù)打算統(tǒng)計下 mPass 這些庫(靜態(tài)庫)的大小样刷,現(xiàn)在沒時間做仑扑,以后再來補(bǔ)充
import json
def get_pods_from_mpass_config(file_path) :
with open('/Users/Shared/.mPaaSCocoaPodsPlugin/baseline/xxxxx/content.json', 'r') as fcc_file:
fcc_data = json.load(fcc_file)
options = fcc_data['options']
modules = fcc_data['modules']
default_mpass_pods = ['mPaaS_TinyApp', 'mPaaS_ScanCode', 'mPaaS_TinyApp_Scan','mPaaS_TinyApp_BabaSSL','mPaaS_TinyApp_Player','mPaaS_Canvas','mPaaS_Log']
origin_mpass_pods = default_mpass_pods
mpass_pods = [] + origin_mpass_pods
for mpass_pod in origin_mpass_pods :
if mpass_pod in options :
mpass_pods += options[mpass_pod]
real_pods = []
for pod in mpass_pods :
if pod in modules :
real_pods += modules[pod]
uni_list = list(set(real_pods))
## uni_list.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
# print('真實(shí)pod(去重):')
# for p in sorted_mpass_pod:
# print(p)
# print('\n')
return sorted(uni_list, key=str.casefold)
def get_pods_from_lockfile(file_path) :
with open('./Podfile.lock', 'r') as f:
pods_lock = []
line = f.readline()
entry_flag = False
while line :
res0 = line.find('SPEC REPOS:')
if res0 > -1:
print('find spec')
entry_flag = False
if entry_flag:
# print(line, end='')
pods_lock.append(line)
res1 = line.find('DEPENDENCIES:')
if res1 != -1 :
print('find depends')
entry_flag = True
line = f.readline()
return pods_lock
def depart_mpass_installed_or_not(sorted_mpass_pod, pods_lock) :
# 下面的內(nèi)容也可以通過set做,但是要統(tǒng)一格式
# 輸出 mpass 配置和實(shí)際 pod 拉取差別
config_inlock = []
config_not_in = []
for mpass_pod in sorted_mpass_pod :
found = False
for pod_lock in pods_lock :
res = pod_lock.find(mpass_pod)
if res > -1 :
found = True
if found :
config_inlock.append(mpass_pod)
else :
config_not_in.append(mpass_pod)
f = open('./MPASS_INSTALLED_RES.txt', 'w')
f.write('=======config_inlock:=======\n')
for pod_str in config_inlock :
f.write(pod_str + '\n')
f.write('=======config_not_in:=======\n')
for pod_str in config_not_in :
f.write(pod_str + '\n')
f.close()
def depart_lock_mpass_and_others(sorted_mpass_pod, pods_lock) :
mpass_pod_lock = []
other_pod_lock = []
for pod_lock in pods_lock :
found = False
for mpass_pod in sorted_mpass_pod :
res = pod_lock.find(mpass_pod)
if res > -1 :
found = True
if found :
mpass_pod_lock.append(pod_lock)
else :
other_pod_lock.append(pod_lock)
f = open('./PODFILE_ANALYSIS.txt', 'w')
f.write('=======mpass_pod_info:=======\n')
for pod_str in mpass_pod_lock :
f.write(pod_str)
f.write('=======other_pod_info:=======\n')
for pod_str in other_pod_lock :
f.write(pod_str)
f.close()
def main():
# 1.讀取mpass baseline 配置置鼻,得到真實(shí) pod 數(shù)據(jù)
sorted_mpass_pod = get_pods_from_mpass_config('')
# 2.讀取podfile.lock 中的 pod 數(shù)據(jù)
pods_lock = get_pods_from_lockfile('')
# 3.區(qū)分 mpass 中的那些pod 被下載了镇饮,哪些沒有
depart_mpass_installed_or_not(sorted_mpass_pod, pods_lock)
# 4.區(qū)分 lock 中哪些是 mpass 的庫,哪些不是
depart_lock_mpass_and_others(sorted_mpass_pod, pods_lock)
if __name__=="__main__":
main()