-
Notifications
You must be signed in to change notification settings - Fork 25
/
create_exe.py
260 lines (220 loc) · 9.23 KB
/
create_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
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
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Copyright (C) 2009 Free Software Foundation
# Author : David Bateman <[email protected]>
# This script is used to create a standalone binary package of NSF2X
# with python3
import distutils.core
import py2exe
import os
import zipfile
import sys
import subprocess
import platform
class Target(object):
'''Target is the baseclass for all executables that are created.
It defines properties that are shared by all of them.
'''
def __init__(self, **kw):
self.__dict__.update(kw)
# the VersionInfo resource, uncomment and fill in those items
# that make sense:
# The 'version' attribute MUST be defined, otherwise no versioninfo will be built:
# self.version = "1.0"
# self.company_name = "Company Name"
# self.copyright = "Copyright Company Name © 2013"
# self.legal_copyright = "Copyright Company Name © 2013"
# self.legal_trademark = ""
# self.product_version = "1.0.0.0"
# self.product_name = "Product Name"
# self.private_build = "foo"
# self.special_build = "bar"
def copy(self):
return Target(**self.__dict__)
def __setitem__(self, name, value):
self.__dict__[name] = value
def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def find_all_files_in_dir(directory):
ret = []
for root, dir, files in os.walk(directory) :
_files = ()
for file in files :
_files += (os.path.join(root, file),)
if _files :
ret += [(root, _files)]
return ret
def main () :
if platform.architecture()[0] == "32bit":
bitness = 'x86'
else :
bitness = 'amd64'
RT_BITMAP = 2
RT_MANIFEST = 24
version = "1.3.6"
author = "[email protected]"
description="NSF2X - Converts Lotus NSF files to EML, MBOX or PST files..."
# A manifest which specifies the executionlevel
# and windows common-controls library version 6
manifest_template = '''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="5.0.0.0"
processorArchitecture="*"
name="%(prog)s"
type="win32"
/>
<description>%(prog)s</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="%(level)s"
uiAccess="false">
</requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
'''
nsf2x = Target(
# We can extend or override the VersionInfo of the base class:
version = version,
file_description = description,
# comments = "Some Comments",
internal_name = "NSF2X",
script="nsf2x.py", # path of the main script
# Allows to specify the basename of the executable, if different from 'nsf2x'
# dest_base = "nsf2x",
# Icon resources:[(resource_id, path to .ico file), ...]
# icon_resources=[(1, r"nsf2x.ico")]
other_resources = [(RT_MANIFEST, 1, (manifest_template % dict(prog="nsf2x", level="asInvoker")).encode("utf-8")),
# for bitmap resources, the first 14 bytes must be skipped when reading the file:
# (RT_BITMAP, 1, open("bitmap.bmp", "rb").read()[14:]),
]
)
# ``zipfile`` and ``bundle_files`` options explained:
# ===================================================
#
# zipfile is the Python runtime library for your exe/dll-files; it
# contains in a ziparchive the modules needed as compiled bytecode.
#
# If 'zipfile=None' is used, the runtime library is appended to the
# exe/dll-files (which will then grow quite large), otherwise the
# zipfile option should be set to a pathname relative to the exe/dll
# files, and a library-file shared by all executables will be created.
#
# The py2exe runtime *can* use extension module by directly importing
# the from a zip-archive - without the need to unpack them to the file
# system. The bundle_files option specifies where the extension modules,
# the python dll itself, and other needed dlls are put.
#
# bundle_files == 3:
# Extension modules, the Python dll and other needed dlls are
# copied into the directory where the zipfile or the exe/dll files
# are created, and loaded in the normal way.
#
# bundle_files == 2:
# Extension modules are put into the library ziparchive and loaded
# from it directly.
# The Python dll and any other needed dlls are copied into the
# directory where the zipfile or the exe/dll files are created,
# and loaded in the normal way.
#
# bundle_files == 1:
# Extension modules and the Python dll are put into the zipfile or
# the exe/dll files, and everything is loaded without unpacking to
# the file system. This does not work for some dlls, so use with
# caution.
#
# bundle_files == 0:
# Extension modules, the Python dll, and other needed dlls are put
# into the zipfile or the exe/dll files, and everything is loaded
# without unpacking to the file system. This does not work for
# some dlls, so use with caution.
py2exe_options = dict(
packages = [],
## excludes = "tof_specials Tkinter".split(),
## ignores = "dotblas gnosis.xml.pickle.parsers._cexpat mx.DateTime".split(),
## dll_excludes = "MSVCP90.dll mswsock.dll powrprof.dll".split(),
optimize=0,
compressed=False, # uncompressed may or may not have a faster startup
bundle_files=3,
dist_dir='dist',
)
# Some options can be overridden by command line options...
distutils.core.setup(name="NSF2X",
# windows subsystem executables (no console)
windows=[nsf2x],
# version of the program
version=version,
# short description of the program
description=description,
# author contact details
author=author,
url='mailto:' + author,
# data files to include
data_files=[(".", ("README.txt", "LICENSE")),
("src", ("create_exe.py", "create_helper.py", "eml2pst.py",
"nsf2x.py", "mapiex.py", "testmapiex.py",
"nsf2x.nsi", "nsf2x_lang.nsi", "README.dev"))] +
find_all_files_in_dir('locale') +
find_all_files_in_dir('helper32') +
find_all_files_in_dir('helper64'),
# py2exe options
zipfile=None,
options={"py2exe": py2exe_options},
)
zf = zipfile.ZipFile("nsf2x-" + version + "-" + bitness + ".zip", "w", zipfile.ZIP_DEFLATED)
for root, dir, files in os.walk("dist") :
for file in files :
_file = os.path.join(root, file)
_arcname = "nsf2x" + _file[4:]
zf.write (_file, _arcname)
zf.close()
# Run NSIS to create the installer. Prefer the portable version if installed
makensis=which("NSISPortable.exe")
if not makensis :
makensis=which("makensis.exe")
if not makensis :
raise "Can not find NSIS executable on your path"
subprocess.call([makensis, "-DVERSION=" + version, "-DPUBLISHER=" + author,
"-DBITNESS=" + bitness, "nsf2x.nsi"])
if len(sys.argv) == 1:
sys.argv.append("py2exe")
main()