forked from nwjs/nw.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage_binaries.py
More file actions
181 lines (123 loc) · 3.86 KB
/
package_binaries.py
File metadata and controls
181 lines (123 loc) · 3.86 KB
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
#!/usr/bin/env python
import os
import shutil
import tarfile
import sys
script_dir = os.path.dirname(__file__)
nw_root = os.path.normpath(os.path.join(script_dir, os.pardir))
project_root = os.path.normpath(os.path.join(nw_root, os.pardir, os.pardir));
#default project path
project_root = os.path.join(project_root, 'out', 'Release')
#parse command line arguments
"""
-p <path>, the absolute path of executable files
"""
if '-p' in sys.argv:
tmp = sys.argv[sys.argv.index('-p') + 1]
if not os.path.isabs(tmp):
print 'the path is not an absolute path.\n'
exit()
if not os.path.exists(tmp):
print 'the directory does not exist.\n'
exit()
project_root = tmp
#get platform information
if sys.platform.startswith('linux'):
platform_name = 'linux'
if sys.platform in ('win32', 'cygwin'):
platform_name = 'win'
if sys.platform == 'darwin':
platform_name = 'osx'
#judge whether the target exist or not
if platform_name == 'linux' and not os.path.exists(
os.path.join(project_root, 'nw')):
print 'nw file does not exist.\n'
exit()
if platform_name == 'win' and not os.path.exists(
os.path.join(project_root, 'nw.exe')):
print 'nw file does not exist.\n'
exit()
if platform_name == 'osx' and not os.path.exists(
os.path.join(project_root, 'node-webkit.app')):
print 'nw file does not exist.\n'
exit()
required_file_linux = (
'nw',
'nw.pak',
'libffmpegsumo.so',
)
required_file_win = (
'ffmpegsumo.dll',
'icudt.dll',
'libEGL.dll',
'libGLESv2.dll',
'nw.exe',
'nw.pak',
)
required_file_mac = (
'node-webkit.app',
)
if (platform_name == 'linux'):
required_file = required_file_linux
if (platform_name == 'win'):
required_file = required_file_win
if (platform_name == 'osx'):
required_file = required_file_mac
#generate binary tar name
import getnwisrelease
import getnwversion
import platform
nw_version = 'v' + getnwversion.nw_version
is_release = getnwisrelease.release
if is_release == 0:
nw_version += '-pre'
bits = platform.architecture()[0]
if bits == '64bit':
arch = 'x64'
else:
arch = 'ia32'
tarname = 'node-webkit-' + nw_version
binary_name = tarname + '-' + platform_name + '-' + arch
binary_tar = binary_name + '.tar.gz'
#use zip in mac and windows
if platform_name in ('win', 'osx'):
binary_tar = binary_name + '.zip'
#make directory for binary_tar
binary_store_path = os.path.join(project_root,
'node-webkit-binaries')
if not os.path.exists(binary_store_path):
os.mkdir(binary_store_path)
binary_full_path = os.path.join(binary_store_path, binary_name)
binary_tar_full_path = os.path.join(binary_store_path, binary_tar)
if os.path.exists(binary_full_path):
shutil.rmtree(binary_full_path)
os.mkdir(binary_full_path)
#copy file to binary
print 'Begin copy file.'
for file in required_file:
shutil.copy(os.path.join(project_root, file),
os.path.join(binary_full_path, file))
print 'copy file end.\n'
if (os.path.isfile(binary_tar_full_path)):
os.remove(binary_tar_full_path)
print 'Begin compress file'
if platform_name in ('win', 'osx'):
"""
If there are sub directors, this should be modified
"""
import zipfile
zip = zipfile.ZipFile(binary_tar_full_path, 'w',
compression=zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(binary_full_path):
for name in filenames:
path = os.path.normpath(os.path.join(dirpath, name))
if os.path.isfile(path):
zip.write(path, os.path.join(os.path.basename(binary_full_path), name))
zip.close()
else:
tar = tarfile.open(binary_tar_full_path, 'w:gz')
tar.add(binary_full_path, os.path.basename(binary_full_path))
tar.close()
print 'compress file end.\n'
print 'the binaries files store in path:', os.path.normpath(
os.path.join(os.getcwd(), binary_store_path))