[GRASS-SVN] r46976 - grass/trunk/lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 5 06:05:31 EDT 2011


Author: martinl
Date: 2011-07-05 03:05:31 -0700 (Tue, 05 Jul 2011)
New Revision: 46976

Modified:
   grass/trunk/lib/python/core.py
Log:
pythonlib: tempfile/dir() use `create = False`, see r46975 


Modified: grass/trunk/lib/python/core.py
===================================================================
--- grass/trunk/lib/python/core.py	2011-07-05 09:58:48 UTC (rev 46975)
+++ grass/trunk/lib/python/core.py	2011-07-05 10:05:31 UTC (rev 46976)
@@ -464,14 +464,23 @@
 
 # interface to g.tempfile
 
-def tempfile():
-    """!Returns the name of a temporary file, created with g.tempfile."""
-    return read_command("g.tempfile", pid = os.getpid()).strip()
+def tempfile(create = True):
+    """!Returns the name of a temporary file, created with
+    g.tempfile.
+    
+    @param create True to create a file
+    
+    @return path to a tmp file
+    """
+    flags = ''
+    if not create:
+        flags += 'd'
+    
+    return read_command("g.tempfile", flags = flags, pid = os.getpid()).strip()
 
 def tempdir():
     """!Returns the name of a temporary dir, created with g.tempfile."""
-    tmp = read_command("g.tempfile", pid = os.getpid()).strip()
-    try_remove(tmp)
+    tmp = tempfile(create = False)
     os.mkdir(tmp)
     
     return tmp



More information about the grass-commit mailing list