Author: dmeyer
Date: Sat Jan 13 20:38:20 2007
New Revision: 2386
Added:
trunk/base/src/tmpfile.py
Modified:
trunk/base/src/__init__.py
Log:
move TEMP variable to extra file and add tempfile function
Modified: trunk/base/src/__init__.py
==============================================================================
--- trunk/base/src/__init__.py (original)
+++ trunk/base/src/__init__.py Sat Jan 13 20:38:20 2007
@@ -25,10 +25,6 @@
#
# -----------------------------------------------------------------------------
-# python imports
-import os
-import stat
-
# import logger to update the Python logging module
import logger
@@ -38,15 +34,5 @@
# strutils
import strutils
-TEMP = '/tmp/kaa-%s' % os.getuid()
-
-if os.path.isdir(TEMP):
- # temp dir is already there, check permissions
- if os.path.islink(TEMP):
- raise IOError('Security Error: %s is a link, aborted')
- if stat.S_IMODE(os.stat(TEMP)[stat.ST_MODE]) != 0700:
- raise IOError('Security Error: %s has wrong permissions, aborted')
- if os.stat(TEMP)[stat.ST_UID] != os.getuid():
- raise IOError('Security Error: %s does not belong to you, aborted')
-else:
- os.mkdir(TEMP, 0700)
+# tempfile support. FIXME: remove TEMP when no longer used
+from tmpfile import tempfile, TEMP
Added: trunk/base/src/tmpfile.py
==============================================================================
--- (empty file)
+++ trunk/base/src/tmpfile.py Sat Jan 13 20:38:20 2007
@@ -0,0 +1,33 @@
+import os
+import stat
+import tempfile
+
+__all__ = [ 'tempfile' ]
+
+TEMP = '/tmp/kaa-%s' % os.getuid()
+
+if os.path.isdir(TEMP):
+ # temp dir is already there, check permissions
+ if os.path.islink(TEMP):
+ raise IOError('Security Error: %s is a link, aborted')
+ if stat.S_IMODE(os.stat(TEMP)[stat.ST_MODE]) != 0700:
+ raise IOError('Security Error: %s has wrong permissions, aborted')
+ if os.stat(TEMP)[stat.ST_UID] != os.getuid():
+ raise IOError('Security Error: %s does not belong to you, aborted')
+else:
+ os.mkdir(TEMP, 0700)
+
+
+def tempfile(name, unique=False):
+ """
+ Return a filename in the secure kaa tmp directory with the given name.
+ Name can also be a relative path in the temp directory, directories will
+ be created if missing. If unique is set, it will return a unique name based
+ on the given name.
+ """
+ name = os.path.join(TEMP, name)
+ if not os.path.isdir(os.path.dirname(name)):
+ os.mkdir(os.path.dirname(name))
+ if not unique:
+ return name
+ return tempfile.mktemp(os.path.basename(name), dir=os.path.dirname(name))
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog