Download this file

bundle.sh    35 lines (25 with data), 762 Bytes

 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
#!/bin/sh
#
# Bundle up a directory containing a main python script and some
# modules into a zip file with a unix python exec header. The main
# must be named __main__.py (or use symlinks). Method described here:
# http://blog.ablepear.com/2012/10/bundling-python-files-into-stand-alone.html
#
# This does not work under windows, but the comments in the link above
# have suggestions for windows: use a specific extension and association.
fatal()
{
echo $* 1>&2 ; exit 1
}
Usage()
{
fatal 'Usage: bundle.sh dir output'
}
test $# -eq 2 || Usage
dir=$1
output=$2
test -d "$dir" || fatal "cant access $dir"
(cd "$dir"; zip ../"$dir".zip *.py; cd ..)
echo '#!/usr/bin/env python' | cat - "$dir".zip > "$output"
rm -f "$dir".zip
chmod a+x "$output"