[GRASS-SVN] r32850 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 18 00:46:28 EDT 2008
Author: cmbarton
Date: 2008-08-18 00:46:27 -0400 (Mon, 18 Aug 2008)
New Revision: 32850
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
Log:
Streamlined tempfile creation for rendering output. Switched from g.tempfile to pure Python secure tempfiles. Changed cleanup method to deal with new tempfiles.
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py 2008-08-17 21:51:15 UTC (rev 32849)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py 2008-08-18 04:46:27 UTC (rev 32850)
@@ -80,10 +80,7 @@
(self.type, self.GetCmd(string=True), self.name, self.active,
self.opacity, self.hidden))
- # generated file for layer
- #self.gtemp = utils.GetTempfile()
- #self.gtemp = os.tmpfile()
- #self.maskfile = self.gtemp + ".pgm"
+ # generated file for each layer
self.gtemp = tempfile.mkstemp()[1]
self.maskfile = self.gtemp + ".pgm"
if self.type == 'overlay':
@@ -111,17 +108,6 @@
Debug.msg (3, "Layer.Render(): type=%s, name=%s" % \
(self.type, self.name))
- #
- # to be sure, set temporary file with layer and mask
- #
- #if not self.gtemp:
- #gtemp = utils.GetTempfile()
- #gtemp = tempfile.mkstemp()[1]
- #self.maskfile = gtemp + ".pgm"
- #if self.type == 'overlay':
- # self.mapfile = gtemp + ".png"
- #else:
- # self.mapfile = gtemp + ".ppm"
#
# prepare command for each layer
@@ -154,12 +140,21 @@
try:
runcmd = gcmd.Command(cmd=self.cmdlist + ['--q'],
stderr=None)
+
if runcmd.returncode != 0:
+ #clean up after probley
+ os.remove(self.mapfile)
+ os.remove(self.maskfile)
+ os.remove(self.gtemp)
self.mapfile = None
self.maskfile = None
except gcmd.CmdError, e:
print >> sys.stderr, e
+ #clean up after probley
+ os.remove(self.mapfile)
+ os.remove(self.maskfile)
+ os.remove(self.gtemp)
self.mapfile = None
self.maskfile = None
@@ -349,9 +344,10 @@
self.gisrc = gisrc
#
- # generated file for rendering the map
+ # generated file for g.pnmcomp output for rendering the map
#
- self.mapfile = utils.GetTempfile()
+ #self.mapfile = utils.GetTempfile()
+ self.mapfile = tempfile.mkstemp(suffix='.ppm')[1]
# setting some initial env. variables
self.InitGisEnv() # g.gisenv
@@ -837,7 +833,7 @@
if mapWindow is not None:
mapWindow.onRenderCounter += 1
- wx.Yield()
+ wx.SafeYield()
# add image to compositing list
if layer.type != "overlay":
@@ -1215,22 +1211,26 @@
@return None on success
"""
try:
+ dir = os.path.dirname(self.mapfile)
+ base = os.path.basename(self.mapfile).split('.')[0]
+ removepath = os.path.join(dir,base)+r'*'
+ for f in glob.glob(removepath):
+ os.remove(f)
for layer in self.layers:
if layer.mapfile:
- base = os.path.split(layer.mapfile)[0]
- mapfile = os.path.split(layer.mapfile)[1]
- tempbase = mapfile.split('.')[0]
- basefile = os.path.join(base,tempbase)+r'.*'
- for f in glob.glob(basefile):
+ dir = os.path.dirname(layer.mapfile)
+ base = os.path.basename(layer.mapfile).split('.')[0]
+ removepath = os.path.join(dir,base)+r'*'
+ for f in glob.glob(removepath):
os.remove(f)
self.layers.remove(layer)
+
for overlay in self.overlays:
- if overlay.ovlfile:
- base = os.path.split(overlay.ovlfile)[0]
- mapfile = os.path.split(overlay.ovlfile)[1]
- tempbase = mapfile.split('.')[0]
- basefile = os.path.join(base,tempbase)+r'.*'
- for f in glob.glob(basefile):
+ if overlay.mapfile:
+ dir = os.path.dirname(overlay.mapfile)
+ base = os.path.basename(overlay.mapfile).split('.')[0]
+ removepath = os.path.join(dir,base)+r'*'
+ for f in glob.glob(removepath):
os.remove(f)
self.overlays.remove(overlay)
return None
More information about the grass-commit
mailing list