FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cefpython/tools/make_installer.py at cefpython55 · pythonthings/cefpython · GitHub
pythonthings
cefpython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cefpython
/
tools
/
make_installer.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
309 lines (262 loc) · 10.5 KB
Breadcrumbs
cefpython
/
tools
/
make_installer.py
Copy path
File metadata and controls
309 lines (262 loc) · 10.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# Copyright (c) 2017 The CEF Python authors. All rights reserved.
# Licensed under BSD 3-clause license.
"""
Create setup.py package installer.
Usage:
make_installer.py VERSION
Options:
VERSION Version number eg. 50.0
"""
from
common
import
*
import
glob
import
os
import
re
import
shutil
import
subprocess
import
sys
import
sysconfig
# Command line args
VERSION
=
""
# Globals
SETUP_DIR
=
""
PKG_DIR
=
""
# Config
IGNORE_EXT
=
[
".log"
,
".pyc"
,
".pdb"
, ]
IGNORE_DIRS
=
[
"__pycache__"
]
def
main
():
command_line_args
()
# Setup and package directories
global
SETUP_DIR
,
PKG_DIR
setup_dir_name
=
(
"cefpython3-{version}-{os}-setup"
.
format
(
version
=
VERSION
,
os
=
OS_POSTFIX2
))
SETUP_DIR
=
os
.
path
.
join
(
BUILD_DIR
,
setup_dir_name
)
PKG_DIR
=
os
.
path
.
join
(
SETUP_DIR
,
"cefpython3"
)
# Print src and dest for file operations
print
(
"[make_installer.py] Src: {src}"
.
format
(
src
=
ROOT_DIR
))
print
(
"[make_installer.py] Dst: {dst}"
.
format
(
dst
=
SETUP_DIR
))
# Make directories
if
os
.
path
.
exists
(
SETUP_DIR
):
print
(
"[make_installer.py] Delete: {dir}"
.
format
(
dir
=
SETUP_DIR
.
replace
(
ROOT_DIR
,
""
)))
shutil
.
rmtree
(
SETUP_DIR
)
os
.
makedirs
(
SETUP_DIR
)
os
.
makedirs
(
os
.
path
.
join
(
SETUP_DIR
,
"examples/"
))
os
.
makedirs
(
PKG_DIR
)
os
.
makedirs
(
os
.
path
.
join
(
PKG_DIR
,
"examples/"
))
# Copy files from tools/installer/
copy_tools_installer_files
(
SETUP_DIR
,
PKG_DIR
)
# Multiple copy operations using glob patterns
copy_operations
=
[
(
ROOT_DIR
,
"License"
), (
PKG_DIR
,),
(
CEF_BINARIES_LIBRARIES
,
"*.txt"
), (
PKG_DIR
,),
(
CEF_BINARIES_LIBRARIES
,
"bin/*"
), (
PKG_DIR
,),
(
CEFPYTHON_BINARY
,
"*"
), (
PKG_DIR
,),
(
EXAMPLES_DIR
,
"*"
), (
PKG_DIR
,
"examples/"
),
(
EXAMPLES_DIR
,
"*"
), (
SETUP_DIR
,
"examples/"
),
]
perform_copy_operations
(
copy_operations
)
# Linux only operations
if
LINUX
:
copy_operations_linux
=
[
(
LINUX_DIR
,
"binaries_64bit/kivy_.py"
),
(
PKG_DIR
,
"examples/"
),
(
LINUX_DIR
,
"binaries_64bit/kivy-select-boxes/*"
),
(
PKG_DIR
,
"examples/"
)
]
perform_copy_operations
(
copy_operations_linux
)
# Create empty debug.log files so that package uninstalls cleanly
# in case examples or CEF tests were launched. See Issue #149.
create_empty_log_file
(
os
.
path
.
join
(
PKG_DIR
,
"debug.log"
))
create_empty_log_file
(
os
.
path
.
join
(
PKG_DIR
,
"examples/debug.log"
))
print
(
"[make_installer.py] DONE. Installer package created: {setup_dir}"
.
format
(
setup_dir
=
SETUP_DIR
))
def
command_line_args
():
args
=
" "
.
join
(
sys
.
argv
)
match
=
re
.
search
(
r"\d+\.\d+"
,
args
)
if
match
:
global
VERSION
VERSION
=
match
.
group
(
0
)
else
:
print
(
__doc__
)
sys
.
exit
(
1
)
def
copy_tools_installer_files
(
setup_dir
,
pkg_dir
):
variables
=
dict
()
variables
[
"VERSION"
]
=
VERSION
variables
[
"SYSCONFIG_PLATFORM"
]
=
sysconfig
.
get_platform
()
shutil
.
copy
(
os
.
path
.
join
(
INSTALLER_DIR
,
"cefpython3.README.txt"
),
os
.
path
.
join
(
setup_dir
,
"README.txt"
))
copy_template_file
(
os
.
path
.
join
(
INSTALLER_DIR
,
"cefpython3.setup.py"
),
os
.
path
.
join
(
setup_dir
,
"setup.py"
),
variables
)
copy_template_file
(
os
.
path
.
join
(
INSTALLER_DIR
,
"cefpython3.__init__.py"
),
os
.
path
.
join
(
pkg_dir
,
"__init__.py"
),
variables
)
def
copy_template_file
(
src
,
dst
,
variables
):
"""Copy file and replaces template variables in that file."""
print
(
"[make_installer.py] Copy_t: {src} ==> {dst}"
.
format
(
src
=
short_src_path
(
src
),
dst
=
short_dst_path
(
dst
)))
with
open
(
src
,
"rb"
)
as
fo
:
contents
=
fo
.
read
()
contents
=
replace_template_vars
(
contents
,
variables
)
with
open
(
dst
,
"wb"
)
as
fo
:
fo
.
write
(
contents
)
return
contents
def
replace_template_vars
(
string
,
dictionary
):
"""Replaces template variables like {{SOME}} in the string
using the dictionary values."""
orig_string
=
string
for
key
,
value
in
dictionary
.
items
():
string
=
string
.
replace
(
"{{"
+
key
+
"}}"
,
value
)
if
string
==
orig_string
:
raise
Exception
(
"Nothing to format"
)
if
re
.
search
(
r"\{\{[a-zA-Z0-9_]+\}\}"
,
string
):
raise
Exception
(
"Not all strings were formatted"
)
return
string
def
perform_copy_operations
(
operations
):
assert
len
(
operations
)
%
2
==
0
count_ops
=
int
(
len
(
operations
)
/
2
)
for
op_i
in
range
(
count_ops
):
# Refer to values by index
pattern
=
operations
[
op_i
*
2
]
dst_dir
=
operations
[
op_i
*
2
+
1
]
# Convert tuples to lists
pattern
=
list
(
pattern
)
dst_dir
=
list
(
dst_dir
)
# Join paths
pattern
=
os
.
path
.
join
(
*
pattern
)
dst_dir
=
os
.
path
.
join
(
*
dst_dir
)
dst_dir
=
os
.
path
.
abspath
(
dst_dir
)
# Normalize unix slashes on Windows
pattern
=
pattern
.
replace
(
"/"
,
os
.
path
.
sep
)
# dst_dir must be a directory
if
not
os
.
path
.
isdir
(
dst_dir
):
raise
Exception
(
"Not a directory: {dst_dir}"
.
format
(
dst_dir
=
dst_dir
))
# Is pattern a file or a directory
if
os
.
path
.
isfile
(
pattern
):
if
is_ignored_path
(
pattern
):
raise
Exception
(
"Copy operation pattern is in ignore list:"
" {pattern}"
.
format
(
pattern
=
pattern
))
print
(
"[make_installer.py] Copy: {file} ==> {dir}"
.
format
(
file
=
short_src_path
(
pattern
),
dir
=
short_dst_path
(
dst_dir
)))
# Destination file must not exist
assert
not
os
.
path
.
exists
(
os
.
path
.
join
(
dst_dir
,
os
.
path
.
basename
(
pattern
)))
shutil
.
copy
(
pattern
,
dst_dir
)
else
:
# pattern is a glob pattern
base_dir
=
os
.
path
.
dirname
(
pattern
)
assert
base_dir
assert
base_dir
==
os
.
path
.
abspath
(
base_dir
)
paths
=
glob
.
glob
(
pattern
)
if
not
len
(
paths
):
raise
Exception
(
"No paths found in: {pattern}"
.
format
(
pattern
=
pattern
))
for
path
in
paths
:
# "path" variable contains absolute path
assert
path
==
os
.
path
.
abspath
(
path
)
if
os
.
path
.
isfile
(
path
):
if
is_ignored_path
(
path
):
continue
print
(
"[make_installer.py] Copy: {file} ==> {dir}"
.
format
(
file
=
short_src_path
(
path
),
dir
=
short_dst_path
(
dst_dir
)))
# Destination file must not exist
assert
not
os
.
path
.
exists
(
os
.
path
.
join
(
dst_dir
,
os
.
path
.
basename
(
path
)))
shutil
.
copy
(
path
,
dst_dir
)
elif
os
.
path
.
isdir
(
path
):
if
is_ignored_path
(
path
):
continue
relative_dir
=
path
.
replace
(
base_dir
,
""
)
assert
relative_dir
[
0
]
==
os
.
path
.
sep
relative_dir
=
relative_dir
[
1
:]
perform_copy_recursively
(
base_dir
,
relative_dir
,
dst_dir
)
else
:
raise
Exception
(
"Unknown path: {path}"
.
format
(
path
=
path
))
def
perform_copy_recursively
(
base_dir
,
relative_dir
,
new_dir
):
real_dir
=
os
.
path
.
join
(
base_dir
,
relative_dir
)
assert
os
.
path
.
exists
(
real_dir
)
and
os
.
path
.
isdir
(
real_dir
)
assert
os
.
path
.
exists
(
new_dir
)
and
os
.
path
.
isdir
(
new_dir
)
# Create subdirectory
new_subdir
=
os
.
path
.
join
(
new_dir
,
relative_dir
)
if
not
os
.
path
.
exists
(
new_subdir
):
print
(
"[make_installer.py] Create: {dir}"
.
format
(
dir
=
short_dst_path
(
new_subdir
)))
os
.
makedirs
(
new_subdir
)
# List directory
paths
=
os
.
listdir
(
real_dir
)
for
path
in
paths
:
# "path" variable contains relative path
real_path
=
os
.
path
.
join
(
real_dir
,
path
)
path
=
os
.
path
.
join
(
relative_dir
,
path
)
if
os
.
path
.
isdir
(
real_path
):
if
is_ignored_path
(
real_path
):
continue
perform_copy_recursively
(
base_dir
,
path
,
new_dir
)
elif
os
.
path
.
isfile
(
real_path
):
if
is_ignored_path
(
real_path
):
continue
new_file
=
os
.
path
.
join
(
new_dir
,
path
)
new_subdir
=
os
.
path
.
dirname
(
new_file
)
if
os
.
path
.
exists
(
new_file
):
raise
Exception
(
"Path aready exists: {new_file}"
.
format
(
new_file
=
short_dst_path
(
new_file
)))
print
(
"[make_installer.py] Copy: {file} ==> {dir}"
.
format
(
file
=
short_src_path
(
real_path
),
dir
=
short_dst_path
(
new_subdir
)))
shutil
.
copy
(
real_path
,
new_subdir
)
else
:
raise
Exception
(
"Unknown path: {path}"
.
format
(
path
=
real_path
))
def
is_ignored_path
(
path
):
basename
=
os
.
path
.
basename
(
path
)
if
basename
in
IGNORE_DIRS
:
print
(
"[make_installer.py] Ignore: {dir}"
.
format
(
dir
=
short_src_path
(
path
)))
return
True
for
ext
in
IGNORE_EXT
:
if
path
.
endswith
(
ext
):
print
(
"[make_installer.py] Ignore: {file}"
.
format
(
file
=
short_src_path
(
path
)))
return
True
return
False
def
delete_files_by_pattern
(
pattern
):
assert
len
(
pattern
)
>
2
# Normalize unix slashes on Windows
pattern
=
pattern
.
replace
(
"/"
,
os
.
path
.
sep
)
print
(
"[make_installer.py] Delete: {pattern}"
.
format
(
pattern
=
short_dst_path
(
pattern
)))
files
=
glob
.
glob
(
pattern
)
for
f
in
files
:
os
.
remove
(
f
)
def
create_empty_log_file
(
log_file
):
# Normalize unix slashes on Windows
log_file
=
log_file
.
replace
(
"/"
,
os
.
path
.
sep
)
print
(
"[make_installer.py] Create: {file}"
.
format
(
file
=
short_dst_path
(
log_file
)))
with
open
(
log_file
,
"wb"
)
as
fo
:
fo
.
write
(
""
)
# On Linux and Mac chmod so that for cases when package is
# installed using sudo. When wheel package is created it
# will remember file permissions set.
if
LINUX
or
MAC
:
command
=
"chmod 666 {file}"
.
format
(
file
=
log_file
)
print
(
"[make_installer.py] {command}"
.
format
(
command
=
command
.
replace
(
SETUP_DIR
,
""
)))
subprocess
.
call
(
command
,
shell
=
True
)
def
short_src_path
(
path
):
# Very long: \build\cef55_3.2883.1553.g80bd606_win32\
find
=
os
.
path
.
basename
(
CEF_BINARIES_LIBRARIES
)
if
len
(
find
)
>
12
:
path
=
path
.
replace
(
find
,
find
[:
12
]
+
"*"
)
path
=
path
.
replace
(
ROOT_DIR
,
""
)
return
path
def
short_dst_path
(
path
):
path
=
path
.
replace
(
SETUP_DIR
,
""
)
return
path
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL