Skip to content

Commit

Permalink
STY: update shellcmd shell=true option variables to not explicity ref…
Browse files Browse the repository at this point in the history
…erence Bash

Since shell=true does not necessarily run cmds through a Bash shell
always
  • Loading branch information
nstelter-slac committed Nov 3, 2023
1 parent fa1c645 commit eb5d68b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/shell_command/example_cmd.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

# This script can be called by a PyDMShellCommand widget,
# allowing it to make use of command chaining and other Bash features.
# allowing it to make use of command chaining and other shell features.
echo "Hello World!" && echo "Hello Again!"
20 changes: 10 additions & 10 deletions examples/shell_command/shell_command_bash.ui
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<string/>
</property>
<property name="text">
<string>Bash Option Enabled</string>
<string>runCmdsInFullShell Option Enabled</string>
</property>
<property name="alarmSensitiveContent" stdset="0">
<bool>false</bool>
Expand All @@ -56,9 +56,6 @@
<property name="showConfirmDialog" stdset="0">
<bool>false</bool>
</property>
<property name="runCommandsInBash" stdset="0">
<bool>true</bool>
</property>
<property name="confirmMessage" stdset="0">
<string>Are you sure you want to proceed?</string>
</property>
Expand Down Expand Up @@ -91,6 +88,9 @@
<property name="protectedPassword" stdset="0">
<string/>
</property>
<property name="runCommandsInBash" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -129,9 +129,6 @@
<property name="showConfirmDialog" stdset="0">
<bool>false</bool>
</property>
<property name="runCommandsInBash" stdset="0">
<bool>false</bool>
</property>
<property name="confirmMessage" stdset="0">
<string>Are you sure you want to proceed?</string>
</property>
Expand Down Expand Up @@ -164,6 +161,9 @@
<property name="protectedPassword" stdset="0">
<string/>
</property>
<property name="runCommandsInBash" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
Expand All @@ -189,9 +189,6 @@
<property name="showConfirmDialog" stdset="0">
<bool>false</bool>
</property>
<property name="runCommandsInBash" stdset="0">
<bool>false</bool>
</property>
<property name="confirmMessage" stdset="0">
<string>Are you sure you want to proceed?</string>
</property>
Expand Down Expand Up @@ -227,6 +224,9 @@
<property name="protectedPassword" stdset="0">
<string/>
</property>
<property name="runCommandsInBash" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
Expand Down
24 changes: 12 additions & 12 deletions pydm/widgets/shell_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def __init__(
self.process = None
self._show_icon = True
self._redirect_output = False
# Bash allows for more options such as command chaining ("cmd1;cmd2", "cmd1 && cmd2", etc ...)
self._run_cmds_in_bash = False
# shell allows for more options such as command chaining ("cmd1;cmd2", "cmd1 && cmd2", etc ...)
self._run_cmds_in_full_shell = False

self._password_protected = False
self._password = ""
Expand Down Expand Up @@ -129,27 +129,27 @@ def showConfirmDialog(self, value: bool) -> None:
self._show_confirm_dialog = value

@Property(bool)
def runCommandsInBash(self) -> bool:
def runCommandsInFullShell(self) -> bool:
"""
Whether or not to run shell cmds with Popen's option to run them through a bash shell.
Whether or not to run cmds with Popen's option for running them through a shell subprocess.
Returns
-------
bool
"""
return self._run_cmds_in_bash
return self._run_cmds_in_full_shell

@runCommandsInBash.setter
def runCommandsInBash(self, value: bool) -> None:
@runCommandsInFullShell.setter
def runCommandsInFullShell(self, value: bool) -> None:
"""
Whether or not to run shell cmds with Popen's option to run them through a bash shell.
Whether or not to run cmds with Popen's option for running them through a shell subprocess.
Parameters
----------
value : bool
"""
if self._run_cmds_in_bash != value:
self._run_cmds_in_bash = value
if self._run_cmds_in_full_shell != value:
self._run_cmds_in_full_shell = value

@Property(str)
def confirmMessage(self) -> str:
Expand Down Expand Up @@ -552,7 +552,7 @@ def execute_command(self, command: str) -> None:
cmd = os.path.expanduser(os.path.expandvars(command))
args = shlex.split(cmd, posix="win" not in sys.platform)
# when Bash enabled, Popen takes the cmds as a single string (not list)
if self._run_cmds_in_bash:
if self._run_cmds_in_full_shell:
args = cmd
try:
logger.debug("Launching process: %s", repr(args))
Expand All @@ -566,7 +566,7 @@ def execute_command(self, command: str) -> None:
if self._redirect_output:
stdout = None
self.process = subprocess.Popen(
args, stdout=stdout, stderr=subprocess.PIPE, env=env_var, shell=self._run_cmds_in_bash
args, stdout=stdout, stderr=subprocess.PIPE, env=env_var, shell=self._run_cmds_in_full_shell
)

except Exception as exc:
Expand Down

0 comments on commit eb5d68b

Please sign in to comment.