[GRASS-SVN] r73884 - grass/trunk/display/d.mon
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Dec 29 10:52:36 PST 2018
Author: hcho
Date: 2018-12-29 10:52:36 -0800 (Sat, 29 Dec 2018)
New Revision: 73884
Modified:
grass/trunk/display/d.mon/render_cmd.py
Log:
d.mon: Create a temporary file for d.text input=- (#3721)
Modified: grass/trunk/display/d.mon/render_cmd.py
===================================================================
--- grass/trunk/display/d.mon/render_cmd.py 2018-12-29 16:43:02 UTC (rev 73883)
+++ grass/trunk/display/d.mon/render_cmd.py 2018-12-29 18:52:36 UTC (rev 73884)
@@ -97,6 +97,27 @@
os.environ['GRASS_REGION'] = grass_region
+# read any input from stdin and create a temporary file
+def read_stdin(cmd):
+ opt = None
+
+ if (cmd[0] == 'd.text' and not 'text' in cmd[1] and
+ (not 'input' in cmd[1] or cmd[1]['input'] == '-')):
+ if sys.stdin.isatty():
+ sys.stderr.write("\nPlease enter text instructions. Enter EOF (ctrl-d) on last line to quit\n")
+ opt = 'input'
+
+ if opt:
+ tmpfile = tempfile.NamedTemporaryFile(dir=path).name + '.txt'
+ fd = open(tmpfile, 'w')
+ while 1:
+ line = sys.stdin.readline()
+ if not line:
+ break
+ fd.write(line)
+ fd.close()
+ cmd[1][opt] = tmpfile
+
if __name__ == "__main__":
cmd = gtask.cmdstring_to_tuple(sys.argv[1])
if not cmd[0] or cmd[0] == 'd.mon':
@@ -115,6 +136,8 @@
mapfile = None
adjust_region(width, height)
+ read_stdin(cmd)
+
render(cmd, mapfile)
update_cmd_file(os.path.join(path, 'cmd'), cmd, mapfile)
if cmd[0] == 'd.erase' and os.path.exists(legfile):
More information about the grass-commit
mailing list