Re: PyReloc - BinReloc for python
"Jan Niklas Hasse" <[email protected]>
| Newsgroups | gmane.comp.autopackage.devel |
|---|---|
| Message-ID | <[email protected]> |
2007/8/18, Isak Savo <[email protected]>: > > 2007/8/17, Jan Niklas Hasse <[email protected]>: > > > 1) Is the __file__ variable always a full path? For all python > > > versions/implementations? > > > - If not, it should be documented which versions are supported. > > I'm sorry, i don't know and i couldn't find anything about it in the > docs. > > Let's assume that it is then. If you could write a small test program, > we could then test it on various machines. I have Python 2.4.4 and > 2.5.1 on my system. I've attached testreloc.py which just prints all variables. > > 3) I see the source mentions a web address with more documentation > > > about how to use it. Are you planning on writing this? > > I just edited the header of binreloc. I could write a short doc, but > > my english isn't good. > > That would be great. A few paragraphs with an example is enough. Me, > (or taj or curtis who's both native English speaking) can correct it > for spelling and grammar if needed. You don't need to do any special > formatting to make it fit the web or something, I'll do that for you. > > Okay thanks! I've attached reloc.txt and also a new version of reloc.py(added EXE variable). --------------------------------------------------------------------- To unsubscribe, e-mail: autopackage-dev-unsubscribe-OfajU3CKLf1/[email protected] For additional commands, e-mail: autopackage-dev-help-OfajU3CKLf1/[email protected]
reloc.py
(text/x-python, 760 B)
# PyReloc - a library for creating relocatable python applications # Written by: Jan Niklas Hasse <[email protected]> # http://autopackage.org/ # # This source code is public domain. You can relicense this code # under whatever license you want. # # See http://autopackage.org/docs/pyreloc/ for # more information and how to use this. import os EXE = __file__ EXEDIR = os.path.dirname(EXE) PREFIX = os.path.normpath(os.path.join(EXEDIR, "..")) BINDIR = os.path.join(PREFIX, "bin") SBINDIR = os.path.join(PREFIX, "sbin") DATADIR = os.path.join(PREFIX, "share") LIBDIR = os.path.join(PREFIX, "lib") LIBEXECDIR = os.path.join(PREFIX, "libexec") ETCDIR = os.path.join(PREFIX, "etc") BINDIR = os.path.join(PREFIX, "bin") LOCALE = os.path.join(DATADIR, "locale")
reloc.txt
(text/plain, 699 B)
Basic usage
Place the reloc.py file somewhere, where your python script can import it and then import it:
import reloc
Now you can use reloc to replace your paths. For example replace
glade = gtk.glade.XML('/usr/share/myproject/main.glade')
with
glade = gtk.glade.XML(os.path.join(reloc.DATADIR, 'myproject/main.glade'))
Other Variables are:
EXE Path to your main python script (__file__).
EXEDIR The directory of your python script.
PREFIX The prefix, e.g. "/usr".
BINDIR PREFIX + "/bin"
SBINDIR PREFIX + "/sbin"
DATADIR PREFIX + "/share"
LIBDIR PREFIX + "/lib"
LIBEXECDIR PREFIX + "/libexec"
ETCDIR PREFIX + "/etc"
LOCALEDIR DATADIR + "/locale"
testreloc.py
(text/x-python, 249 B)
#!/usr/bin/env python import reloc print reloc.EXE print reloc.EXEDIR print reloc.PREFIX print reloc.BINDIR print reloc.SBINDIR print reloc.DATADIR print reloc.LIBDIR print reloc.LIBEXECDIR print reloc.ETCDIR print reloc.BINDIR print reloc.LOCALE