-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcef.py
355 lines (272 loc) · 9.11 KB
/
cef.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/usr/bin/env python
#coding=utf-8
import urllib
import urllib2
import os
import tarfile
import _winreg
import shutil
import sys
import re
import fnmatch
import os.path
from optparse import OptionParser
import posixpath
import string
import getopt
import time
import node_cef_util
reload(sys)
sys.setdefaultencoding('utf8') # 允许中文字符串
url = '' #文件地址
decompress = False #是否压缩文件
outputPath = './../NCUI-Library/' #输出目录
clean = False
downloads = './../NCUI-Downloads/' #文件下载保存路径
tmp = downloads + 'tmp/' #临时文件目录
tmpFolder = '' #文件解压后的保存路径
cmake = False
build = False #是否编译项目
vspath = ''
copy = False #是否复制文件
version = '', #url版本号
rebuild = False, #强制重新编译
props = './Microsoft.Cpp.Common.user.props' #配置文件
sevenzip ="./resources/7z.exe"
download_url = False
try:
opts, args = getopt.getopt(sys.argv[1:],"hi:o:",["url=","output=","decompress","clean","cmake","vspath","build","copy", "props", "version=", "rebuild", "7z", "download"])
except getopt.GetoptError:
print 'cef.py url, output, decompress, clean, cmake, vspath, build, copy, props, version, rebuild, 7z, download'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'test.py -i <inputfile> -o <outputfile>, exit'
sys.exit()
elif opt == ("--decompress"):
decompress = True
elif opt == ("--clean"):
clean = True
elif opt == ("--cmake"):
cmake = True
elif opt == ("--vspath"):
vspath = arg
elif opt == ("--build"):
build = True
elif opt == ("--copy"):
copy = True
elif opt == ("--rebuild"):
rebuild = True
elif opt == ("--download"):
download_url = True
elif opt == ("--props"):
props = arg
elif opt == ("--version"):
version = arg
elif opt == ("--7z"):
sevenzip = arg
elif opt in ("-i", "--url"):
url = arg
elif opt in ("-o", "--output"):
outputPath = arg
if version <> '':
url = node_cef_util.getCefUrl(version)
print 'url ' + url
print 'outputPath ' + outputPath
print 'decompress ' , decompress
print 'clean ' , clean
print 'cmake ', cmake
print 'vspath ', vspath
print 'build ', build
print 'copy ', copy
print 'props '+ props
print 'version '+ version
print 'rebuild ', rebuild
print 'download ', download_url
if props <> '':
props = os.path.abspath(props)
if outputPath <> '':
outputPath = os.path.abspath(outputPath)
outputPath += "/"
if sevenzip <> '':
sevenzip = os.path.abspath(sevenzip)
if downloads <> '':
downloads = os.path.abspath(downloads)
downloads += "/"
if tmp <> '':
tmp = os.path.abspath(tmp)
tmp += "/"
print "props: " + props
print "outputPath: " + outputPath
print "sevenzip: " + sevenzip
print "downloads: " + downloads
print "tmp: " + tmp
#解析url
if url == '':
print 'url is empty, exit'
sys.exit(1)
url = url.replace('\\', '/')
print url
arr = url.split('/')
print arr
if len(arr) < 2:
print "invalid url, exit"
exit()
#最后一段为文件
filename = arr[len(arr)-1]
tmpFolder = tmp
keyword = "windows32_minimal"
index = filename.find(keyword)
if index == -1:
print "not found minimal cef"
keyword = "windows32"
index = filename.find(keyword)
print index
if index <> -1:
tmpFolder += filename[0:index + len(keyword)]
else:
print "invalid zip folder, exit"
exit()
print "tmpFolder: " + tmpFolder
#clean
if clean == True:
print "delete tmp folder "+ tmpFolder
shutil.rmtree(tmpFolder)
print "finished, exit"
exit()
#下载文件的保存目录
fullname = downloads + filename
#创建目录
node_cef_util.createDir(downloads)
node_cef_util.createDir(tmp)
#download file
#这一段是和node.py不同的地方
if download_url == True:
print "download url save path " + fullname
if os.path.exists(fullname) == False:
print "download: " + url
urllib.urlretrieve(url, fullname)
print "download success"
else:
print "file exists :" + fullname
else:
print "skip download url"
#decompress file
if decompress == True:
print "node_cef_util.unzip file " + fullname + " dist folder " + tmp
node_cef_util.unzip(sevenzip, fullname, tmp)
else:
print "skip node_cef_util.unzip file"
print tmpFolder
node_cef_util.createDir(tmpFolder)
#切换工作目录
os.chdir(tmpFolder)
#cmake
if cmake == True:
node_cef_util.modifyCmakeFiles()
os.system('cmake -DUSE_SANDBOX:BOOL="0" -G "Visual Studio 14"')
else:
print "skip call cmake "
print tmpFolder
libcef_dll_wrapper_path = "./libcef_dll/libcef_dll_wrapper.vcxproj"
if os.path.exists(libcef_dll_wrapper_path)<> True:
libcef_dll_wrapper_path = "./libcef_dll_wrapper/libcef_dll_wrapper.vcxproj"
node_cef_util.modifyProject(libcef_dll_wrapper_path, "<TreatWarningAsError>", "<TreatWarningAsError>false</TreatWarningAsError>\n")
#查找vs path
if vspath == '':
try:
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, r'Software\Microsoft\VisualStudio\14.0_Config')
value,type = _winreg.QueryValueEx(key,"InstallDir")
vspath = value
except WindowsError:
print "can not find vs path, exit"
exit()
if vspath == '' :
print "empty vs path, exit"
exit()
if vspath.endswith('\\') <> True and vspath.endswith('/') <> True:
vspath += '\\'
devenv = vspath + 'devenv.exe'
command = """echo off
set IDE_DIR="""
command += vspath
command +="""
echo VC IDE DIR = %IDE_DIR%
echo -----------------------------------------------------------------------
echo start build
for /f "tokens=1 delims=/ " %%j in ("%date%") do set d1=%%j
for /f "tokens=2 delims=/ " %%j in ("%date%") do set d2=%%j
for /f "tokens=3 delims=/ " %%j in ("%date%") do set d3=%%j
for /f "tokens=1 delims=: " %%j in ("%time%") do set t1=%%j
for /f "tokens=2 delims=: " %%j in ("%time%") do set t2=%%j
for /f "tokens=3 delims=:. " %%j in ("%time%") do set t3=%%j
set COMPILE_LOGFILE=%d1%-%d2%-%d3%_%t1%-%t2%-%t3%_compile.txt
echo log file = %COMPILE_LOGFILE%
echo compile [cef.sln - libcef_dll_wrapper - Release Win32]
"%IDE_DIR%devenv.exe" "%SOLUTION_DIR%cef.sln" "Release|Win32" /project libcef_dll_wrapper /out %COMPILE_LOGFILE%
if %errorlevel% NEQ 0 goto myexit
echo compile [cef.sln - libcef_dll_wrapper - Debug Win32]
"%IDE_DIR%devenv.exe" "%SOLUTION_DIR%cef.sln" "Debug|Win32" /project libcef_dll_wrapper /out %COMPILE_LOGFILE%
if %errorlevel% NEQ 0 goto myexit
echo ------------------
exit
:myexit
echo -----------------------------------------------------------------------
echo [build error]
exit """
file = open('build.bat', 'w')
file.write(command)
file.close()
print "found devenv Path :" + devenv
#rebuild
if rebuild == True:
if os.path.exists("./libcef_dll_wrapper/Release/libcef_dll_wrapper.lib") == True:
os.remove("./libcef_dll_wrapper/Release/libcef_dll_wrapper.lib")
if os.path.exists("./libcef_dll_wrapper/Debug/libcef_dll_wrapper.lib") == True:
os.remove("./libcef_dll_wrapper/Debug/libcef_dll_wrapper.lib")
if os.path.exists("./libcef_dll/Release/libcef_dll_wrapper.lib") == True:
os.remove("./libcef_dll/Release/libcef_dll_wrapper.lib")
if os.path.exists("./libcef_dll/Debug/libcef_dll_wrapper.lib") == True:
os.remove("./libcef_dll/Debug/libcef_dll_wrapper.lib")
build = True
#build
if build == True:
if os.path.exists("./libcef_dll_wrapper/Release/libcef_dll_wrapper.lib") == True and os.path.exists("./libcef_dll_wrapper/Debug/libcef_dll_wrapper.lib") == True:
print "no files need to be compiled."
elif os.path.exists("./libcef_dll/Release/libcef_dll_wrapper.lib") == True and os.path.exists("./libcef_dll/Debug/libcef_dll_wrapper.lib") == True:
print "no files need to be compiled."
else:
os.system('build.bat')
else:
print "skip build cef.sln"
#copy
if copy == True:
#先检测有没有build, 如果有那么copy,如果没有,那么检测lib目录是否已经存在,如果不存在则copy
srcPath = "./"
outputPath += "/" + filename[0:index + len(keyword)] + "/"
if os.path.exists(outputPath) == True:
print outputPath + " already exist"
#没有编译程序且目录存在,那么不拷贝文件
if build == False and os.path.exists(outputPath) == True:
print "skip copy file"
else:
print "copy files"
node_cef_util.transfer(srcPath + "include" , outputPath + "include", '.*')
node_cef_util.transfer(srcPath + "libcef_dll" , outputPath + "libcef_dll", '.cc')
node_cef_util.transfer(srcPath + "libcef_dll" , outputPath + "libcef_dll", '.h')
node_cef_util.transfer(srcPath + "libcef_dll/Debug" , outputPath + "libcef_dll_wrapper/Debug", '.lib')
node_cef_util.transfer(srcPath + "libcef_dll/Release" , outputPath + "libcef_dll_wrapper/Release", '.lib')
node_cef_util.transfer(srcPath + "libcef_dll_wrapper" , outputPath + "libcef_dll_wrapper", '.lib')
node_cef_util.transfer(srcPath + "Release" , outputPath + "bin", '.dll')
node_cef_util.transfer(srcPath + "Release" , outputPath + "bin", '.bin')
node_cef_util.transfer(srcPath + "Release" , outputPath + "bin", '.dat')
node_cef_util.transfer(srcPath + "Release" , outputPath + "bin", 'libcef.lib')
node_cef_util.transfer(srcPath + "Resources" , outputPath + "Resources", '.*')
#修改config
print "modify cef config"
config = "\t\t<LibCefFolder>$(LibraryFolder)"
config += filename[0:index + len(keyword)]
config += "/</LibCefFolder>\n"
print config
node_cef_util.modifyProps(props, "</LibCefFolder>", config)
print "complete"