-
Notifications
You must be signed in to change notification settings - Fork 110
/
start.py
executable file
·139 lines (111 loc) · 4.7 KB
/
start.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*- coding:utf-8 -*-
import os
import platform
import sys
parPath = os.path.dirname(os.path.abspath(__file__))
toolPath = os.path.join(parPath, "Tool")
sys.path.append(toolPath)
sitePath = os.path.join(toolPath, "SitePackages")
sys.path.append(sitePath)
from packaging import version
Red = "31"
Green = "32"
Yellow = "33"
def colorPrint(color, log):
print("\033[0;%s;m%s\033[0m" % (color, log))
# 判断当前运行操作系统
if platform.system() != "Darwin":
colorPrint(Red, "请在macOS操作系统运行该工具")
os._exit(1)
if " " in parPath:
colorPrint(Red, parPath)
colorPrint(Red, "工具所在的路径包含了空格,请移除路径中的空格后重试")
colorPrint(Yellow, "建议将工具直接放在桌面")
os._exit(1)
# 获取当前系统版本
def curSystemVersion():
output = os.popen("sw_vers | awk 'NR==2 {print $2}'")
lines = output.readlines()
output.close()
systemVersion = lines[0].strip()
colorPrint(Green, "macOS: " + systemVersion)
if version.parse(systemVersion) >= version.parse("10.15"):
output = os.popen("spctl --status | awk 'NR==1 {print $2}'")
status = output.readline()
output.close()
if status.strip() == "disabled":
return
colorPrint(Yellow, "10.15系统开始,使用本工具需要关闭spctl")
colorPrint(Yellow, "请在终端执行以下命令来关闭spctl:")
colorPrint(Green, "sudo spctl --master-disable")
colorPrint(Red, "因为涉及到sudo,本工具不提供自动执行操作,建议自行了解以上命令后决定")
colorPrint(Red, '执行完成后需要设置: 系统偏好设置.app -> 安全性与隐私 -> 通用 -> 选择"任何来源"')
colorPrint(Red, "设置之后重新运行当前脚本即可")
os._exit(1)
# 判断当前SIP状态
def curSIPStatus():
output = os.popen("sysctl -n machdep.cpu.brand_string")
status = output.readline()
if "Apple" not in status:
return
output = os.popen("csrutil status")
status = output.readline()
if "enabled" in status:
colorPrint(Red, "m1芯片设备需要关闭SIP")
colorPrint(Green, "详情见:")
colorPrint(Yellow, "https://github.com/rowliny/DiffHelper/wiki/M1芯片关闭SIP")
os._exit(1)
# 判断当前运行python环境
def curPythonVersion():
colorPrint(Green, "Python: " + platform.python_version())
if platform.python_version() != "3.10.0":
colorPrint(Red, "请确认在python3.10.0环境运行该工具,其它版本确实不能运行")
colorPrint(Green, "详情见:")
colorPrint(Yellow, "https://github.com/rowliny/DiffHelper/wiki/Python环境安装")
colorPrint(Yellow, "或者直接安装附带的python安装包:python-3.10.0post2-macos11.pkg")
os._exit(1)
# 当前Xcode版本信息
def checkXcodeInstalled():
output = os.popen("/usr/bin/xcodebuild -version")
lines = output.readlines()
output.close()
if not lines:
colorPrint(Red, "请确认已经安装Xcode")
colorPrint(Yellow, "如果确认已经安装Xcode")
colorPrint(Yellow, "请在终端执行以下命令完成设置:")
colorPrint(Green, "xcode-select -s /Applications/Xcode.app/Contents/Developer")
os._exit(1)
colorPrint(Green, lines[0].strip())
# 判断是否安装xcode-select
def checkXcodeSelect():
output = os.popen("xcode-select -p")
content = output.readline()
output.close()
if not content:
colorPrint(Yellow, "当前未安装xcode-select,现在开始安装:")
os.system("xcode-select --install")
elif "Xcode.app/Contents/Developer" not in content.strip():
colorPrint(Yellow, "工具会使用到脚本打包项目的功能,需要设置xcode-select对应的位置")
colorPrint(Yellow, "请在终端执行以下命令完成设置:")
colorPrint(Green, "sudo xcode-select -s %s" % (content.strip()))
colorPrint(Red, "因为涉及到sudo,本工具不提供自动执行操作,建议自行了解以上命令后决定")
colorPrint(Red, "执行完成后重新运行当前脚本即可")
os._exit(1)
def checkOperateEnv():
print("")
print("*" * 32 + "开始检测运行环境" + "*" * 32)
curSystemVersion()
curSIPStatus()
curPythonVersion()
checkXcodeInstalled()
checkXcodeSelect()
print("*" * 32 + "运行环境符合要求" + "*" * 32)
os.chdir(parPath)
if __name__ == "__main__":
checkOperateEnv()
try:
import JustDoIT
except Exception:
colorPrint(Red, "解决方案:\n\t请参考同级目录下的「使用演示.gif」")
colorPrint(Red, "解决方案:\n\t请参考同级目录下的「m1设置.png」")
JustDoIT.justDoIT()