Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-01-03 15:47:06 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-01-03 15:47:06 (GMT)
commitfaeee47f531a83159f351495e2b96b61426b53fa (patch)
tree8066e2faab2ae603cc403df34ccbb8b47b2f9532 /src
parent44cabc891b9311fa7a20ac229ee9c04090caba2d (diff)
Add util.TempFilePath to track the creation and release of temporal files
Diffstat (limited to 'src')
-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)
+