Browse Source

Fix bug with uninitialised variables and exit handler

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@41817 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 15 years ago
parent
commit
65e9a062aa
1 changed files with 16 additions and 8 deletions
  1. 16 8
      scripts/r.fillnulls/r.fillnulls.py

+ 16 - 8
scripts/r.fillnulls/r.fillnulls.py

@@ -60,15 +60,23 @@ import os
 import atexit
 import grass.script as grass
 
+vecttmp = None
+tmp1 = None
+usermask = None
+mapset = None
+
 # what to do in case of user break:
 def cleanup():
     #delete internal mask and any TMP files:
-    rasts = [tmp1 + ext for ext in ['', '.buf', '_filled']]
-    grass.run_command('g.remove', flags = 'f', rast = rasts)
-    grass.run_command('g.remove', flags = 'f', vect = vecttmp)
+    if tmp1:
+	rasts = [tmp1 + ext for ext in ['', '.buf', '_filled']]
+	grass.run_command('g.remove', flags = 'f', rast = rasts)
+    if vecttmp:
+	grass.run_command('g.remove', flags = 'f', vect = vecttmp)
     grass.run_command('g.remove', rast = 'MASK')
-    if grass.find_file(usermask, mapset = mapset)['file']:
-	grass.run_command('g.rename', rast = (usermask, 'MASK'))
+    if usermask and mapset:
+	if grass.find_file(usermask, mapset = mapset)['file']:
+	    grass.run_command('g.rename', rast = (usermask, 'MASK'))
 
 def main():
     global vecttmp, tmp1, usermask, mapset
@@ -78,13 +86,13 @@ def main():
     tension = options['tension']
     smooth = options['smooth']
 
+    mapset = grass.gisenv()['MAPSET']
+    unique = str(os.getpid())
+
     #check if input file exists
     if not grass.find_file(input)['file']:
 	grass.fatal(_("<%s> does not exist.") % input)
 
-    mapset = grass.gisenv()['MAPSET']
-    unique = str(os.getpid())
-
     # check if a MASK is already present:
     usermask = "usermask_mask." + unique
     if grass.find_file('MASK', mapset = mapset)['file']: