[Twisted-Python] tap-relative filenames?
I'm not even sure I know how to ask this question properly, so please bear with me... I'm writing an application in Twisted (a news server, serving mbox files as read-only groups, FWIW). I'm including a simple interface to dynamically add new files (groups). No problem, but I'd rather keep things as relocatable as possible. Ultimately, I'll have a tap file, which I'll use to start the application using the twistd daemon. So what I'd like to do is store filenames relative to the directory which contains the tap file. OK, so I can cd to that directory, and start twistd from there. But in the more general case, I may start the app from an arbitrary directory and give the full path to the tap file. So what I'm saying is, can I find the name of the tap file from within the application code? I imagine this is non-trivial, because the code won't always even be started from a tap file (my test rig does reactor.listenTCP/reactor.run manually) but when it isn't then names won't be getting persisted, so I don't care (I guess...) Can anybody help? Does anyone even follow the question??? :-) Thanks, Paul -- This signature intentionally left blank
On Wed, 13 Nov 2002, Paul Moore <lists@morpheus.demon.co.uk> wrote:
Ultimately, I'll have a tap file, which I'll use to start the application using the twistd daemon. So what I'd like to do is store filenames relative to the directory which contains the tap file.
This is not a good idea -- on Debian systems, for example, tha tap would be somewhere on /etc while the data files would be under /var. In general, the tap should store the actual file names. (BTW: Debian is used here as a system which adheres to the FHS religiously, but really this is a consequence of the FHS) This seems akin to the classic UNIX question "how do I find the name of the executable?" to which the answer is "you don't".
Moshe Zadka <m@moshez.org> writes:
On Wed, 13 Nov 2002, Paul Moore <lists@morpheus.demon.co.uk> wrote:
Ultimately, I'll have a tap file, which I'll use to start the application using the twistd daemon. So what I'd like to do is store filenames relative to the directory which contains the tap file.
This is not a good idea -- on Debian systems, for example, tha tap would be somewhere on /etc while the data files would be under /var. In general, the tap should store the actual file names.
On Unix, yes, quite probably. But on Windows, storing data in an application-relative location is quite common. On Windows, there are no standardised directories like /etc or /var. So absolute filenames are much less usable, in general.
This seems akin to the classic UNIX question "how do I find the name of the executable?" to which the answer is "you don't".
Yes, but on Windows, the answer is to use the Windows API GetModuleFileName(). It's a cultural difference between the two operating systems. If there isn't a way of locating the tap file at the moment, is there any possibility of one getting added? (I can't do so myself, I'm nowhere near familiar enough with the internals of Twisted yet). Paul. -- This signature intentionally left blank
Hi, Paul Moore:
On Unix, yes, quite probably. But on Windows, storing data in an application-relative location is quite common.
On Windows, programs are not installable without an elaborate installation program dance. Some people consider that a bug -- on Mac systems, for instance, you drag the whole application to the hard disk, _that's_it_, and a sensible application will _never_ write into its own program space (it could reside on a read-only file server).
On Windows, there are no standardised directories like /etc or /var. So absolute filenames are much less usable, in general.
Setup stuff under Windows typically lives in that arcane thing called "registry"...
This seems akin to the classic UNIX question "how do I find the name of the executable?" to which the answer is "you don't".
Under Linux, you readlink("/proc/self/cmd") (and check if that file exists and has the same inode). Other OSes are not interesting. ;-)
If there isn't a way of locating the tap file at the moment, is there any possibility of one getting added?
That'd interest me too. -- Matthias Urlichs | noris network AG | http://smurf.noris.de/
On Thu, 14 Nov 2002 20:46:21 +0000, Paul Moore <lists@morpheus.demon.co.uk> wrote:
If there isn't a way of locating the tap file at the moment, is there any possibility of one getting added? (I can't do so myself, I'm nowhere near familiar enough with the internals of Twisted yet).
Yes, this is on my radar and I agree it's probably a necessity at least in some form. However, there is quite a bit of plumbing that does os.path.abspath or depends on relative pathnames being relative to the run directory and not the tap file. We should probably add an --absolutize=true option to mktap or something that will be the default on unix and not on win32. Anyone want to volunteer to do this? I sure don't have time :) -- | <`'> | Glyph Lefkowitz: Traveling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |
participants (4)
-
Glyph Lefkowitz -
Matthias Urlichs -
Moshe Zadka -
Paul Moore