Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/sugar/util.py')
-rw-r--r--src/sugar/util.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/sugar/util.py b/src/sugar/util.py
index c8bdfb1..d222f9c 100644
--- a/src/sugar/util.py
+++ b/src/sugar/util.py
@@ -26,6 +26,8 @@ import sha
import random
import binascii
import gettext
+import tempfile
+import logging
_ = lambda msg: gettext.dgettext('sugar-toolkit', msg)
@@ -261,3 +263,19 @@ def timestamp_to_elapsed_string(timestamp, max_levels=2):
return ELAPSED % time_period
+class TempFilePath(str):
+
+ def __new__(cls, path=None):
+ if path is None:
+ fd, path = tempfile.mkstemp()
+ os.remove(fd)
+ logging.debug('TempFilePath created %r' % path)
+ return str.__new__(cls, path)
+
+ def __del__(self):
+ if os.path.exists(self):
+ os.unlink(self)
+ logging.debug('TempFilePath deleted %r' % self)
+ else:
+ logging.warning('TempFilePath already deleted %r' % self)
+