Thoughts on running Python zips

Colin Brown cbrown at metservice.com
Thu Nov 13 23:59:21 EST 2003


As I am getting a larger collection of python program packages the idea of
saving them as zips is becoming increasingly attractive. The latest idea is
to launch them from a generic wrapper listed below. I have chosen to set the
default directory to the location of the zipfile because I usually have an
associated configuration inifile alongside.

Periodically the topic of program protection crops up. Some zip applications
allow password protection. If python did then one could possibly tie a
user's distribution to their network card MAC address. I guess the
commandline "-i" option could be programmatically overidden preventing
post-use access.

Colin Brown
PyNZ
--------------------------------------------------------------------
# A generic wrapper utility for running zipped python programs
#
# Usage: python [-options] RunZip.py app_path/application.zip [*args]
#
# application.zip is a package with main program named
# application.py in directory "application". Cwd is set
# to location of app_path. sys.args has "RunZip.py" removed.

import os, sys

zipf = ''
for path in sys.argv:
    if path.find('RunZip.py') > -1:
        myself = path
    elif path.find('.zip') > -1:
        zipf = path
        break
sys.argv.remove(myself)
if zipf:
    sys.path.insert(0,zipf)
    name = os.path.splitext(os.path.basename(zipf))[0]
    os.chdir(os.path.dirname(os.path.abspath(zipf)))
    exec('from '+name+' import '+name)







More information about the Python-list mailing list