-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_exe.py
145 lines (124 loc) · 5.22 KB
/
build_exe.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
#!/usr/bin/python3.3
# -*- coding: utf-8 -*-
import argparse
import logging
import os
import textwrap
from . import runtime
def main():
parser = argparse.ArgumentParser(description="Build runtime archive for a script",
formatter_class=argparse.RawTextHelpFormatter)
# what to include, what to exclude...
parser.add_argument("-i", "--include",
help="module to include",
dest="includes",
metavar="modname",
action="append"
)
parser.add_argument("-x", "--exclude",
help="module to exclude",
dest="excludes",
metavar="modname",
action="append")
parser.add_argument("-p", "--package",
help="module to exclude",
dest="packages",
metavar="package_name",
action="append")
# how to compile the code...
parser.add_argument("-O", "--optimize",
help="use optimized bytecode",
dest="optimize",
action="count")
# reporting options...
parser.add_argument("-s", "--summary",
help="""print a single line listing how many modules were
found and how many modules are missing""",
dest="summary",
action="store_true")
parser.add_argument("-r", "--report",
help="""print a detailed report listing all found modules,
the missing modules, and which module imported them.""",
dest="report",
action="store_true")
parser.add_argument("-f", "--from",
help="""print where the module <modname> is imported.""",
metavar="modname",
dest="show_from",
action="append")
parser.add_argument("-v",
dest="verbose",
action="store_true")
parser.add_argument("-c", "--compress",
dest="compress",
action="store_true")
# what to build
parser.add_argument("-d", "--dest",
## required=True,
default="dist",
help="""destination directory""",
dest="destdir")
parser.add_argument("-l", "--library",
help="""relative pathname of the python archive""",
dest="libname")
parser.add_argument("-b", "--bundle-files",
help=textwrap.dedent("""\
How to bundle the files:
3 - create script.exe, python.dll, extensions.pyd, others.dll.
2 - create script.exe, python.dll, others.dll.
1 - create script.exe, others.dll.
0 - create script.exe.
"""),
choices=[0, 1, 2, 3],
type=int,
default=3)
parser.add_argument("-W", "--write-setup-script",
help=textwrap.dedent("""\
Do not build the executables; instead write a setup script that allows
further customizations of the build process.
"""),
metavar="setup_path",
dest="setup_path")
# exe files to build...
parser.add_argument("script",
metavar="script",
nargs="*",
)
parser.add_argument("-svc", "--service",
help="""Build a service""",
metavar="service",
action="append",
)
options = parser.parse_args()
if not options.service and not options.script:
parser.error("nothing to build")
options.service = runtime.fixup_targets(options.service, "modules")
for target in options.service:
target.exe_type = "service"
options.script = runtime.fixup_targets(options.script, "script")
for target in options.script:
if target.script.endswith(".pyw"):
target.exe_type = "windows_exe"
else:
target.exe_type = "console_exe"
if options.setup_path:
if os.path.isfile(options.setup_path):
message = "File %r already exists, are you sure you want to overwrite it? [yN]: "
answer = input(message % options.setup_path)
if answer not in "yY":
print("Canceled.")
return
from .setup_template import write_setup
write_setup(options)
# no further action
return
options.data_files = None
options.com_servers = []
options.unbuffered = False
level = logging.INFO if options.verbose else logging.WARNING
logging.basicConfig(level=level)
builder = runtime.Runtime(options)
builder.analyze()
builder.build()
if __name__ == "__main__":
main()