[GRASS-SVN] r74342 - grass/trunk/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Apr 4 02:54:28 PDT 2019


Author: mmetz
Date: 2019-04-04 02:54:28 -0700 (Thu, 04 Apr 2019)
New Revision: 74342

Modified:
   grass/trunk/lib/python/script/raster.py
Log:
libpython: + option to overwrite history with raster_history()

Modified: grass/trunk/lib/python/script/raster.py
===================================================================
--- grass/trunk/lib/python/script/raster.py	2019-04-03 21:45:26 UTC (rev 74341)
+++ grass/trunk/lib/python/script/raster.py	2019-04-04 09:54:28 UTC (rev 74342)
@@ -26,7 +26,7 @@
 
 from .core import *
 from grass.exceptions import CalledModuleError
-from .utils import float_or_dms, parse_key_val
+from .utils import float_or_dms, parse_key_val, try_remove
 
 
 if sys.version_info.major == 3:
@@ -33,7 +33,7 @@
     unicode = str
 
 
-def raster_history(map):
+def raster_history(map, overwrite=False):
     """Set the command history for a raster map to the command used to
     invoke the script (interface to `r.support`).
 
@@ -45,7 +45,15 @@
     """
     current_mapset = gisenv()['MAPSET']
     if find_file(name=map)['mapset'] == current_mapset:
-        run_command('r.support', map=map, history=os.environ['CMDLINE'])
+        if overwrite == True:
+            historyfile = tempfile()
+            f = open(historyfile, 'w')
+            f.write(os.environ['CMDLINE'])
+            f.close()
+            run_command('r.support', map=map, loadhistory=historyfile)
+            try_remove(historyfile)
+        else:
+            run_command('r.support', map=map, history=os.environ['CMDLINE'])
         return True
 
     warning(_("Unable to write history for <%(map)s>. "



More information about the grass-commit mailing list