Thoughts on running Python zips

C

Colin Brown

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top