Преглед на файлове

d.mon: Create a temporary file for d.text input=- (https://trac.osgeo.org/grass/ticket/3721)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73884 15284696-431f-4ddb-bdfa-cd5b030d7da7
Huidae Cho преди 6 години
родител
ревизия
ebc24a25d4
променени са 1 файла, в които са добавени 23 реда и са изтрити 0 реда
  1. 23 0
      display/d.mon/render_cmd.py

+ 23 - 0
display/d.mon/render_cmd.py

@@ -97,6 +97,27 @@ def adjust_region(width, height):
 
     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 @@ if __name__ == "__main__":
         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):