瀏覽代碼

libpython: + option to overwrite history with raster_history()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@74342 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 6 年之前
父節點
當前提交
01c9f1c653
共有 1 個文件被更改,包括 11 次插入3 次删除
  1. 11 3
      lib/python/script/raster.py

+ 11 - 3
lib/python/script/raster.py

@@ -26,14 +26,14 @@ import time
 
 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:
     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 @@ def raster_history(map):
     """
     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>. "