Skip to content

Commit

Permalink
hides subprocess windows on os.system = "nt" (#1148)
Browse files Browse the repository at this point in the history
* hides subprocess windows on os.system = "nt"

* improved subprocess_startupinfo
  • Loading branch information
ReimarBauer authored Aug 13, 2021
1 parent cbb45be commit 1fe6977
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions mslib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@
UR.define("pptv = 1e-12 fraction")


def subprocess_startupinfo():
"""
config options to hide windows terminals on subprocess call
"""
startupinfo = None
if os.name == 'nt':
# thx to https://gist.github.com/nitely/3862493
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
return startupinfo


def parse_iso_datetime(string):
try:
result = isodate.parse_datetime(string)
Expand Down Expand Up @@ -830,7 +843,8 @@ def __init__(self, parent=None):

# Check if mamba is installed
try:
subprocess.run(["mamba"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
subprocess.run(["mamba"], startupinfo=subprocess_startupinfo(),
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
self.command = "mamba"
except FileNotFoundError:
pass
Expand All @@ -854,7 +868,9 @@ def _check_version(self):
"""
# Don't notify on updates if mss is in a git repo, as you are most likely a developer
try:
git = subprocess.run(["git", "rev-parse", "--is-inside-work-tree"], stdout=subprocess.PIPE,
git = subprocess.run(["git", "rev-parse", "--is-inside-work-tree"],
startupinfo=subprocess_startupinfo(),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, encoding="utf8")
if "true" in git.stdout:
self.is_git_env = True
Expand All @@ -863,7 +879,8 @@ def _check_version(self):

# Return if conda is not installed
try:
subprocess.run(["conda"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
subprocess.run(["conda"], startupinfo=subprocess_startupinfo(),
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except FileNotFoundError:
return

Expand Down Expand Up @@ -926,7 +943,11 @@ def _execute_command(self, command):
"""
Handles proper execution of conda subprocesses and logging
"""
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf8")
process = subprocess.Popen(command.split(),
startupinfo=subprocess_startupinfo(),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf8")
self.on_log_update.emit(" ".join(process.args) + "\n")

text = ""
Expand Down Expand Up @@ -1193,7 +1214,8 @@ def update_airspace(force_download=False, countries=["de"]):

if (force_download or is_outdated or not file_exists) \
and QtWidgets.QMessageBox.question(None, "Allow download",
f"The selected {country} airspace needs to be downloaded ({data[-1]})"
f"The selected {country} airspace "
f"needs to be downloaded ({data[-1]})"
f"\nIs now a good time?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) \
== QtWidgets.QMessageBox.Yes:
Expand Down

0 comments on commit 1fe6977

Please sign in to comment.