--- a/bundle.sh
+++ b/tools/bundle.sh
@@ -1,4 +1,12 @@
#!/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()
{
@@ -6,21 +14,21 @@
}
Usage()
{
- fatal 'Usage: bundle.sh dir'
+ fatal 'Usage: bundle.sh dir output'
}
-test $# -eq 1 || Usage
+test $# -eq 2 || Usage
dir=$1
+output=$2
+
test -d "$dir" || fatal "cant access $dir"
-execname="up$dir"
-cd "$dir"
-zip ../"$dir".zip *.py
-cd ..
-echo '#!/usr/bin/env python' | cat - "$dir".zip > "$execname"
+(cd "$dir"; zip ../"$dir".zip *.py; cd ..)
+
+echo '#!/usr/bin/env python' | cat - "$dir".zip > "$output"
rm -f "$dir".zip
-chmod a+x "$execname"
+chmod a+x "$output"