1991-11-12 16:38:08 +01:00
|
|
|
# Temporary file name allocation
|
|
|
|
|
|
|
|
import posix
|
|
|
|
import path
|
|
|
|
|
|
|
|
|
|
|
|
# Changeable parameters (by clients!)...
|
|
|
|
|
|
|
|
tempdir = '/usr/tmp'
|
|
|
|
template = '@'
|
|
|
|
|
1992-01-14 19:31:56 +01:00
|
|
|
# Use environment variable $TMPDIR to override default tempdir.
|
|
|
|
|
|
|
|
if posix.environ.has_key('TMPDIR'):
|
|
|
|
# XXX Could check that it's a writable directory...
|
|
|
|
tempdir = posix.environ['TMPDIR']
|
|
|
|
|
1991-11-12 16:38:08 +01:00
|
|
|
|
1991-12-26 14:10:50 +01:00
|
|
|
# Counter for generating unique names
|
1991-11-12 16:38:08 +01:00
|
|
|
|
1991-12-26 14:10:50 +01:00
|
|
|
counter = 0
|
1991-11-12 16:38:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
# User-callable function
|
|
|
|
# XXX Should this have a parameter, like C's mktemp()?
|
|
|
|
# XXX Should we instead use the model of Standard C's tempnam()?
|
|
|
|
# XXX By all means, avoid a mess with four different functions like C...
|
|
|
|
|
|
|
|
def mktemp():
|
1991-12-26 14:10:50 +01:00
|
|
|
global counter
|
1991-11-12 16:38:08 +01:00
|
|
|
while 1:
|
1991-12-26 14:10:50 +01:00
|
|
|
counter = counter+1
|
|
|
|
file = tempdir+'/'+template+`posix.getpid()`+'.'+`counter`
|
1991-11-12 16:38:08 +01:00
|
|
|
if not path.exists(file):
|
|
|
|
break
|
|
|
|
return file
|