Skip to content

Commit

Permalink
python/grass/script/utils.py: split the command string using shell-li…
Browse files Browse the repository at this point in the history
…ke syntax on the win32 platform same as on POSIX-compliant platforms

* e.g. launch 'd.vect map=census where="cat > 10 AND cat < 20"' with where parameter

non-POSIX platform

>>> import shlex
>>> shlex.split('where="cat > 10 AND cat < 20"', posix=False)
['where="cat', '>', '10', 'AND', 'cat', '<', '20"']

POSIX-compliant platform

>>> import shlex
>>> shlex.split('where="cat > 10 AND cat < 20"', posix=True)
['where=cat > 10 AND cat < 20']

* launch 'd.vect map=census where="cat > 10 AND cat < 20"' command from
MS Windows Command Prompt require use ^ carret symbol for escaping special
characters < > ( ) & | , ; "

e.g. 'd.vect map=census where="cat ^> 10 AND cat ^< 20"'
  • Loading branch information
tmszi committed Oct 1, 2021
1 parent e03efc2 commit 573cd90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 9 additions & 2 deletions display/d.vect/d.vect.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ <h2>NOTES</h2>
which allow the user to specify vector type, colors, data fields, SQL
queries, label size and justification, etc.

<p>By default <em>d.vect</em> areas are filled with <b>fill_color</b> and
<p>When <em>d.vect</em> is used with <b>where</b> parameter on MS Windows
Command Prompt, it is important to use <tt>&#710;</tt>
carret symbol for escaping special characters <tt>&lt; &gt; ( ) &amp; &#124; , ; &quot;</tt>.
<div class="code"><pre>
d.vect map=vector_map where="cat &#710;&gt; 10 AND cat &#710;&lt; 20"
</pre></div>

<p>By default <em>d.vect</em> areas are filled with <b>fill_color</b> and
outlined with <b>color</b>. Area outlines can be suppressed with
<div class="code"><pre>
d.vect map=vector_map color=none
Expand Down Expand Up @@ -84,7 +91,7 @@ <h2>EXAMPLES</h2>
<p>3D points, 3D lines and 3D polygons colorized according to z height
(for 3D lines and polygons a z height is computed by a midpoint of
line/area bounding box):

<div class="code"><pre>
g.region raster=elevation.10m
r.random input=elevation.10m n=5000 vector=random3d -d
Expand Down
14 changes: 9 additions & 5 deletions python/grass/script/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,15 @@ def get_num_suffix(number, max_number):


def split(s):
"""!Platform specific shlex.split"""
if sys.version_info >= (2, 6):
return shlex.split(s, posix=(sys.platform != "win32"))
elif sys.platform == "win32":
return shlex.split(s.replace("\\", r"\\"))
"""!Platform specific shlex.split
:param str s: cmd string
return list: cmd list
"""
if sys.platform == "win32":
# ^ carret symbol for escaping special MS Windows Command Prompt characters < > ( ) & | , ; "
return shlex.split(s.replace("\\", r"\\").replace("^", ""))
else:
return shlex.split(s)

Expand Down

0 comments on commit 573cd90

Please sign in to comment.