|
1 | 1 | import contextlib |
2 | 2 | import os |
3 | | -import sys |
4 | 3 | import multiprocessing as mltp |
5 | 4 | import subprocess as sub |
6 | 5 | import shutil as sht |
7 | 6 | from math import ceil |
8 | 7 | from pathlib import Path |
9 | 8 |
|
10 | 9 | from grass.script.setup import write_gisrc |
11 | | -from grass.script import append_node_pid, available_cpus, legalize_vector_name |
| 10 | +from grass.script import Popen, append_node_pid, available_cpus, legalize_vector_name |
12 | 11 |
|
13 | 12 | from grass.pygrass.gis import Mapset, Location |
14 | 13 | from grass.pygrass.gis.region import Region |
@@ -215,16 +214,20 @@ def set_region(region, gisrc_src, gisrc_dst, env): |
215 | 214 | :type env: |
216 | 215 | :returns: None |
217 | 216 | """ |
218 | | - reg_str = ( |
219 | | - "g.region n=%(north)r s=%(south)r " |
220 | | - "e=%(east)r w=%(west)r " |
221 | | - "nsres=%(nsres)r ewres=%(ewres)r" |
222 | | - ) |
223 | | - reg_cmd = reg_str % dict(region.items()) |
| 217 | + region_dict = dict(region.items()) |
| 218 | + reg_cmd = [ |
| 219 | + "g.region", |
| 220 | + "n=%r" % region_dict["north"], |
| 221 | + "s=%r" % region_dict["south"], |
| 222 | + "e=%r" % region_dict["east"], |
| 223 | + "w=%r" % region_dict["west"], |
| 224 | + "nsres=%r" % region_dict["nsres"], |
| 225 | + "ewres=%r" % region_dict["ewres"], |
| 226 | + ] |
224 | 227 | env["GISRC"] = gisrc_src |
225 | | - sub.Popen(reg_cmd, shell=True, env=env) |
| 228 | + Popen(reg_cmd, env=env) |
226 | 229 | env["GISRC"] = gisrc_dst |
227 | | - sub.Popen(reg_cmd, shell=True, env=env) |
| 230 | + Popen(reg_cmd, env=env) |
228 | 231 |
|
229 | 232 |
|
230 | 233 | def copy_rasters(rasters, gisrc_src, gisrc_dst, processes, region=None): |
@@ -377,23 +380,22 @@ def cmd_exe(args): |
377 | 380 | src, dst = get_mapset(gisrc_src, gisrc_dst) |
378 | 381 | env = os.environ.copy() |
379 | 382 | env["GISRC"] = gisrc_dst |
380 | | - shell = sys.platform == "win32" |
381 | 383 | if mapnames: |
382 | 384 | inputs = dict(cmd["inputs"]) |
383 | 385 | # reset the inputs to |
384 | 386 | for key in mapnames: |
385 | 387 | inputs[key] = mapnames[key] |
386 | 388 | cmd["inputs"] = inputs.items() |
387 | 389 | # set the region to the tile |
388 | | - sub.Popen(["g.region", "raster=%s" % key], shell=shell, env=env).wait() |
| 390 | + Popen(["g.region", "raster=%s" % key], env=env).wait() |
389 | 391 | else: |
390 | 392 | # set the computational region |
391 | 393 | lcmd = ["g.region", *["%s=%s" % (k, v) for k, v in bbox.items()]] |
392 | | - sub.Popen(lcmd, shell=shell, env=env).wait() |
| 394 | + Popen(lcmd, env=env).wait() |
393 | 395 | if groups: |
394 | 396 | copy_groups(groups, gisrc_src, gisrc_dst, processes=1) |
395 | 397 | # run the grass command |
396 | | - sub.Popen(get_cmd(cmd), shell=shell, env=env).wait() |
| 398 | + Popen(get_cmd(cmd), env=env).wait() |
397 | 399 | # remove temp GISRC |
398 | 400 | Path(gisrc_dst).unlink() |
399 | 401 |
|
|
0 commit comments