Warning, new comer at large. I've been playing with Gordon's win32 installer and really like the idea of the .pyz to wrap things up. I've been doing the same thing with zlib to create .pyc files. I send them too other people I work with. They execute the .pyc which explodes on their disk. It runs a setup.py file and handles platform details. Archives are real handy and zip is a pretty standard one. So wouldn't zip compatibility be good. It seems that understanding the header format for zip along with zlib might let you decode a zip. There's a bunch of zip info at: http://www.cdrom.com/pub/infozip/Info-ZIP.html And an unzip.dll that could be used if decoding the header was too much pain. Has anyone tried to work with zips from python ? --Darrell
Darrell wrote:
Has anyone tried to work with zips from python ?
We don't use compression within Python, although we like the idea of a .pyl Python library file. The reason is we use a commercial installer (Wise) to distribute programs, and it supplies compression itself. Jim Ahlstrom
"James C. Ahlstrom" wrote:
Darrell wrote:
Has anyone tried to work with zips from python ?
We don't use compression within Python, although we like the idea of a .pyl Python library file. The reason is we use a commercial installer (Wise) to distribute programs, and it supplies compression itself.
Since I wanted to wait for Grodon's next release and I had to create an installer ASAP, here is what I did before my translate-"Learning Python"-vacation. The idea is very simple in this case: - use the WISE installer to distribute files - create a new "pyrun.exe" with slightly different defaults - don't ship .pyc but .py in this case (since we are in alpha mode) - do not change python15.dll at all The "pyrun.exe" has one simple main feature: It does not try to go interactive, but by default calls a function via "-c" . By modification of the environment, the default path is in the executable's directory, and in /lib below. All the rest has to be done by scripts from there. If and only if called without parameters, an argument of -c runapp() is supplied. This has some advantages: Users may double-click on pyrun.exe, and it will simply run the application, without having to create default parameters, links and such. The Python executable is still usable as a standard interpreter, if renamed into something different from "pyrun". If pyrun.exe is given any parameters, it will use them. This makes it possible to let the Unwise uninstaller use Python itself to clean up a tree of directories with .pyc files. Find attached my minimum python.c program, and some scripts which I use in the executable's directory: site.py: Installs a function abspath to make file paths absolute. Putsit together with runapp in module __main__. eraser.py: Used for unwise.exe as a file cleanup. It works, since it can remove its own .pyc files after creating it. If run multiple times, use it with its own file tree at the last call. This file has to be on top of the directory with these scripts and the pyrun.exe, dll's, lib etc.: app.py The real application bootstrap file. It has to be adjusted according to the application. The complete Python installation sits in a subdirectory and can be replaced as a whole without interference with the application. For Wise users, I also attached our simple installation script which installs Python with a redaction server for one of our customers. Some of Wise's text editing features are used to patch one or two Python scripts which take some path variables. ciao - chris -- Christian Tismer :^) <mailto:tismer@appliedbiometrics.com> Applied Biometrics GmbH : Have a break! Take a ride on Python's Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net 10553 Berlin : PGP key -> http://wwwkeys.pgp.net PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF we're tired of banana software - shipped green, ripens at home # sitecustomize for an application. # CT 990722 changes for pyrun.exe # CT 990613 # better: this is an override for site.py # by this trick, we only need "." in the path at # startup time. All the rest can be done in site.py. """ Assumptions: The executable and its helper dlls are in the same directory. Above this directory, a file named "app.py" must exist. Actions: The path is cleared out totally. Only the executable's path, and the lib path are valid. The proper version of the interpreter is checked, also the existance and correctness of "app.py". If an error is detected, a message box will show up if possible. The application will end with exit status 2. If everything is ok, "app.py" is run. It is then responsible to modify the path further and to actually start the application. """ print "test" # globals: PROGDIR = '' # Python program directory ROOTDIR = '' # root directory where app.py is found DLLVERSION = "1.5.42b1" import sys # not os, yet! path = sys.executable while path and path[-1] != "\\": path = path[:-1] #print path , " do isser" sys.path=[path+".",path+"lib",path+"lib/plat-win"] del path #print sys.path import os # but now :-) def abspath(somedir, root=None): """make an absolute path from somedir. The directory must exist. It is built from ROOTDIR with somedir appended. It is tried to chdir into that, with no error checking, to make sure that the directory exists """ if not root: root=ROOTDIR here = os.getcwd() target = os.path.join(root, somedir) os.chdir(target) os.chdir(here) return target def checkpath(somedir): try: return abspath(somedir) except os.error: return None def init_app(): prog = sys.executable progdir = os.path.split(sys.executable)[0] appdir = os.path.split(progdir)[0] sys.path = [appdir, progdir, abspath("lib", progdir), abspath("lib/plat-win", progdir), ] # reload os, since we have an absolute path now reload(os) # now we believe we have "string" global string import string vers = string.split(sys.version, None, 1)[0] if vers != DLLVERSION: raise SystemError, "wrong system dll version" global ROOTDIR ROOTDIR=appdir global PROGDIR PROGDIR=progdir def runapp(filename=os.path.join(ROOTDIR, "app.py")): execfile(filename) return runapp try: runapp = init_app() # gives a function object, bound to the filename except SystemExit: sys.exit(0) except: err, reason, tb = sys.exc_info() del tb txt = "Problem encountered:\n" txt = txt+str(err)+"\n" txt = txt+str(reason)+"\n" head = "PNS Application Error" try: import win32api win32api.MessageBox(0,txt, head) except: print head print txt sys.exit(2) import __main__ __main__.abspath = abspath __main__.runapp = runapp # put this into the cmdline: -c runapp() # 990722 done by default from pyrun.exe # cleanup certain files recursively # CT 990722 import os, sys, string args = sys.argv[1:] path = "" types = [] if args: path = args[0] types = args[1:] if not path: path = "." if not types: types = [".pyc", ".pyo"] types = map(string.lower, types) def eraser(types, d, files): for namex in files: namex = string.lower(namex) name, ext = os.path.splitext(namex) if string.lower(ext) in types: try: fname = os.path.join(d, namex) print "removing", fname, os.unlink(fname) print " - done." except os.error: print " - cannot remove!" os.path.walk(path, eraser, types) import sys, os, string if "" in sys.path:sys.path.remove("") print sys.path paths = ["medusa", "medusa/RsScriptHandler"] for path in paths: print path sys.path.insert(0, abspath(path)) print "after" print "schnaudiwaudi" from RsHttpServer import * # let it happen
"James C. Ahlstrom" wrote:
Darrell wrote:
Has anyone tried to work with zips from python ?
We don't use compression within Python, although we like the idea of a .pyl Python library file. The reason is we use a commercial installer (Wise) to distribute programs, and it supplies compression itself.
Since I wanted to wait for Grodon's next release and I had to create an installer ASAP, here is what I did before my translate-"Learning Python"-vacation. The idea is very simple in this case: - use the WISE installer to distribute files - create a new "pyrun.exe" with slightly different defaults - don't ship .pyc but .py in this case (since we are in alpha mode) - do not change python15.dll at all The "pyrun.exe" has one simple main feature: It does not try to go interactive, but by default calls a function via "-c" . By modification of the environment, the default path is in the executable's directory, and in /lib below. All the rest has to be done by scripts from there. If and only if called without parameters, an argument of -c runapp() is supplied. This has some advantages: Users may double-click on pyrun.exe, and it will simply run the application, without having to create default parameters, links and such. The Python executable is still usable as a standard interpreter, if renamed into something different from "pyrun". If pyrun.exe is given any parameters, it will use them. This makes it possible to let the Unwise uninstaller use Python itself to clean up a tree of directories with .pyc files. Find attached my minimum python.c program, and some scripts which I use in the executable's directory: site.py: Installs a function abspath to make file paths absolute. Putsit together with runapp in module __main__. eraser.py: Used for unwise.exe as a file cleanup. It works, since it can remove its own .pyc files after creating it. If run multiple times, use it with its own file tree at the last call. This file has to be on top of the directory with these scripts and the pyrun.exe, dll's, lib etc.: app.py The real application bootstrap file. It has to be adjusted according to the application. The complete Python installation sits in a subdirectory and can be replaced as a whole without interference with the application. For Wise users, I also attached our simple installation script which installs Python with a redaction server for one of our customers. Some of Wise's text editing features are used to patch one or two Python scripts which take some path variables. ciao - chris p.s.: posted twice - first version was too long, zipped the .wse file. -- Christian Tismer :^) <mailto:tismer@appliedbiometrics.com> Applied Biometrics GmbH : Have a break! Take a ride on Python's Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net 10553 Berlin : PGP key -> http://wwwkeys.pgp.net PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF we're tired of banana software - shipped green, ripens at home # sitecustomize for an application. # CT 990722 changes for pyrun.exe # CT 990613 # better: this is an override for site.py # by this trick, we only need "." in the path at # startup time. All the rest can be done in site.py. """ Assumptions: The executable and its helper dlls are in the same directory. Above this directory, a file named "app.py" must exist. Actions: The path is cleared out totally. Only the executable's path, and the lib path are valid. The proper version of the interpreter is checked, also the existance and correctness of "app.py". If an error is detected, a message box will show up if possible. The application will end with exit status 2. If everything is ok, "app.py" is run. It is then responsible to modify the path further and to actually start the application. """ print "test" # globals: PROGDIR = '' # Python program directory ROOTDIR = '' # root directory where app.py is found DLLVERSION = "1.5.42b1" import sys # not os, yet! path = sys.executable while path and path[-1] != "\\": path = path[:-1] #print path , " do isser" sys.path=[path+".",path+"lib",path+"lib/plat-win"] del path #print sys.path import os # but now :-) def abspath(somedir, root=None): """make an absolute path from somedir. The directory must exist. It is built from ROOTDIR with somedir appended. It is tried to chdir into that, with no error checking, to make sure that the directory exists """ if not root: root=ROOTDIR here = os.getcwd() target = os.path.join(root, somedir) os.chdir(target) os.chdir(here) return target def checkpath(somedir): try: return abspath(somedir) except os.error: return None def init_app(): prog = sys.executable progdir = os.path.split(sys.executable)[0] appdir = os.path.split(progdir)[0] sys.path = [appdir, progdir, abspath("lib", progdir), abspath("lib/plat-win", progdir), ] # reload os, since we have an absolute path now reload(os) # now we believe we have "string" global string import string vers = string.split(sys.version, None, 1)[0] if vers != DLLVERSION: raise SystemError, "wrong system dll version" global ROOTDIR ROOTDIR=appdir global PROGDIR PROGDIR=progdir def runapp(filename=os.path.join(ROOTDIR, "app.py")): execfile(filename) return runapp try: runapp = init_app() # gives a function object, bound to the filename except SystemExit: sys.exit(0) except: err, reason, tb = sys.exc_info() del tb txt = "Problem encountered:\n" txt = txt+str(err)+"\n" txt = txt+str(reason)+"\n" head = "PNS Application Error" try: import win32api win32api.MessageBox(0,txt, head) except: print head print txt sys.exit(2) import __main__ __main__.abspath = abspath __main__.runapp = runapp # put this into the cmdline: -c runapp() # 990722 done by default from pyrun.exe # cleanup certain files recursively # CT 990722 import os, sys, string args = sys.argv[1:] path = "" types = [] if args: path = args[0] types = args[1:] if not path: path = "." if not types: types = [".pyc", ".pyo"] types = map(string.lower, types) def eraser(types, d, files): for namex in files: namex = string.lower(namex) name, ext = os.path.splitext(namex) if string.lower(ext) in types: try: fname = os.path.join(d, namex) print "removing", fname, os.unlink(fname) print " - done." except os.error: print " - cannot remove!" os.path.walk(path, eraser, types) import sys, os, string if "" in sys.path:sys.path.remove("") print sys.path paths = ["medusa", "medusa/RsScriptHandler"] for path in paths: print path sys.path.insert(0, abspath(path)) print "after" print "schnaudiwaudi" from RsHttpServer import * # let it happen
participants (3)
-
Christian Tismer
-
Darrell
-
James C. Ahlstrom