-
Notifications
You must be signed in to change notification settings - Fork 3
/
modify.py
36 lines (30 loc) · 1.11 KB
/
modify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import re
# Specs目录
specsDir = os.path.expanduser('~') + '/.cocoapods/repos/trunk/Specs/'
# specsDir = './example/'
# https://github.com/Alamofire/Alamofire.git => git@github.com:Alamofire/Alamofire.git
# 只更改git repo路径,其他的资源路径不改,如https://github.com/Alamofire/Alamofire/releases/v1.0.0.zip
httpPattern = '"https://github.com/([^"]+).git"'
# 更改包计数
modifyCount = 0
def modifyFile(filePath):
f = open(filePath, 'r')
content = f.read()
f.close()
matches = re.findall(httpPattern, content)
if matches and len(matches) > 0:
global modifyCount
modifyCount += 1
newContent = content
for match in matches:
httpStr = '"https://github.com/'+match+'.git"'
sshStr = '"git@github.com:'+match+'.git"'
newContent = newContent.replace(httpStr, sshStr)
f2 = open(filePath, 'w')
f2.write(newContent)
f2.close()
for root, dirs, files in os.walk(specsDir, topdown=False):
for name in files:
modifyFile(os.path.join(root, name))
print(f'完成,更改包{modifyCount}个')