[GRASS-dev] [GRASS GIS] #3637: Use the system temporary directory for all GUI rendering files

GRASS GIS trac at osgeo.org
Mon Sep 3 18:39:54 PDT 2018


#3637: Use the system temporary directory for all GUI rendering files
-------------------------------------------------+-------------------------
 Reporter:  wenzeslaus                           |      Owner:  grass-dev@…
     Type:  defect                               |     Status:  assigned
 Priority:  minor                                |  Milestone:  8.0.0
Component:  wxGUI                                |    Version:  svn-trunk
 Keywords:  rendering PPM g.pnmcomp tempfile     |        CPU:  Unspecified
  NamedTemporaryFile                             |
 Platform:  Unspecified                          |
-------------------------------------------------+-------------------------
 wxGUI uses standard Python `tempfile.NamedTemporaryFile` for rendering a
 single layer (`GRASS_RENDER_FILE`):

 {{{
             mapfile = tempfile.NamedTemporaryFile(
                 suffix=tempfile_sfx, delete=False)
             # we don't want it open, we just need the name
             self.mapfile = mapfile.name
             mapfile.close()
             os.remove(self.mapfile)  # remove empty file

         self.maskfile = self.mapfile.rsplit(".", 1)[0] + ".pgm"
 }}}

 However, it uses GRASS GIS `grass.script.tempfile` for vector legend files
 and `g.pnmcomp` output:

 {{{
         if self.type in ('vector', 'thememap'):
             self._legrow = grass.tempfile(create=True)
 ...
         # generated file for g.pnmcomp output for rendering the map
         self.legfile = grass.tempfile(create=False) + '.leg'
         self.tmpdir = os.path.dirname(self.legfile)  # looks unused (?)
         self.mapfile = grass.tempfile(create=False) + '.ppm'
 }}}

 source:grass/trunk/gui/wxpython/core/render.py

 The render command (from WX_DEBUG, edited):

 {{{
 GUI D1/5: RenderLayerMgr.Render(d.rast
 map=boundary_county_500m at PERMANENT):
           force=1 img=/tmp/grass7-vpetras-23526/tmpNqGsdb.ppm

 GUI D1/5: gcmd.RunCommand(): g.pnmcomp --o opacity=1.0 width=823
           mask=/tmp/grass7-$USER-23526/tmpNqGsdb.pgm
           height=502 bgcolor=255:255:255:255
           input=/tmp/grass7-$USER-23526/tmpNqGsdb.ppm
 output=/home/$USER/grassdata/nc_spm/a1/.tmp/$HOSTNAME/24140.0.ppm
 }}}


 `tempfile.NamedTemporaryFile` refers to `tempfile.TemporaryFile` which
 refers to `tempfile.mkstemp` which says:

 > The default directory is chosen from a platform-dependent list, but the
 user of the application can control the directory location by setting the
 `TMPDIR`, `TEMP` or `TMP` environment variables.

 The order is not explicitly guaranteed in the documentation, but the
 behavior on Linux with Python 2.7 is that `TMPDIR` is picked over `TMP`
 which is the behavior we want. If that would change, but we wanted to
 preserve the same behavior, there is a `dir` parameter which specified the
 directory.

 My intention is to use `tempfile.NamedTemporaryFile` for everything.

-- 
Ticket URL: <https://trac.osgeo.org/grass/ticket/3637>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list