3
# Copyright (c) 2007, 2008 Agostino Russo
5
# Written by Agostino Russo <agostino.russo@gmail.com>
7
# pack.py is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 2 of
10
# the License, or (at your option) any later version.
12
# pack.py is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
25
from os.path import abspath, join, basename, dirname, exists
27
SIGNATURE="@@@pylauncher@@@"
30
return abspath(join(*args))
32
def compress(target_dir):
33
#TBD the 7z compressor should be properly compiled
35
compressor = ajoin("C:", "Program Files", "7-Zip","7z.exe")
36
cmd = '%s a -t7z -m0=lzma -mx=9 -mfb=256 -md=32m -ms=on ../archive.7z *'
37
cmd = cmd % (compressor,)
43
def cat(outfile, *infiles):
44
fout = open(outfile, 'wb')
46
fin = open(abspath(fname), 'rb')
52
def make_self_extracting_exe(target_dir):
53
header = ajoin(dirname(__file__), 'header.exe')
54
archive = ajoin(dirname(target_dir),'archive.7z')
55
target = ajoin(dirname(target_dir), 'application.exe')
56
signature = ajoin(dirname(target_dir), 'signature')
57
f = open(signature, 'wb')
60
print "Creating self extracting file %s" % target
61
cat(target, header, signature, archive)
63
def add_python_interpreter(target_dir):
64
#TBD detect the dll/lib of the current python instance
65
for f in ('pylauncher.exe', 'python26.dll', 'pyrun.exe'):
66
source = ajoin(dirname(__file__), f)
67
shutil.copy(source, target_dir)
70
target_dir = sys.argv[1]
71
add_python_interpreter(target_dir)
73
make_self_extracting_exe(target_dir)
75
if __name__ == "__main__":