Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion maven/.streamlit/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ toolbarMode = "minimal"
hideTopBar = true

[logger]
level = "warning"
level = "warning"

[theme]
base = "light"
2 changes: 1 addition & 1 deletion maven/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.3.1"
__version__ = "1.0.4"
14 changes: 7 additions & 7 deletions maven/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3006,8 +3006,8 @@ def render_yaml_portion(data, path=(), depth=0):
st.stop()

if new_using_ssh_value.lower() == "putty" and (not plink or not pscp):
st.error("Could not find PuTTY tools; install PuTTY at https://www.puttyssh.org/")
st.stop()
st.error("Could not find PuTTY tools; install PuTTY at https://www.puttyssh.org/")
st.stop()

else:
tier2_store = get_db(tier2_db_path)
Expand Down Expand Up @@ -3692,7 +3692,6 @@ def as_text(value):
else:
cmd = ["ssh", f"{username}@{hpc_name}", remote_command]
remote_run = subprocess.run(cmd, input=script, text=True, capture_output=True, check=False)
print(" \nGo back to app")
if remote_run.returncode != 0:
st.error("HPC Staging to Campaign Move Error:")
if remote_run.stderr:
Expand All @@ -3712,6 +3711,7 @@ def as_text(value):
st.code(f"Please ensure '{hpc_name}' is an HPC transfer node")
else:
st.code(remote_run.stderr)
print(" \nGo back to app")
st.stop()

if "Only testing on this HPC for now" in remote_run.stdout:
Expand Down Expand Up @@ -3771,7 +3771,7 @@ def as_text(value):
else:
st.code(remote_endpoint_run.stderr)
st.code(output)
print(" \nGo back to app")
print(" \nGo back to app")
st.stop()

# set user group and access permissions after move
Expand All @@ -3784,8 +3784,8 @@ def as_text(value):
if result.returncode != 0:
st.error("Error setting user group for data on Campaign")
st.code(result.stderr)
st.stop()
print(" \nGo back to app")
st.stop()

if access_permissions_code:
with st.spinner("Updating data access permissions on Campaign"):
Expand All @@ -3794,8 +3794,8 @@ def as_text(value):
if result.returncode != 0:
st.error("Error setting access permissions for data on Campaign")
st.code(result.stderr)
st.stop()
print(" \nGo back to app")
st.stop()
else:
if user_group and access_permissions_code:
print(" \nPassword prompt 1/1: updating user group and data access permissions on HPC campaign")
Expand All @@ -3810,8 +3810,8 @@ def as_text(value):
if result.returncode != 0:
st.error("Error updating user group and data access permissions on HPC campaign")
st.code(result.stderr)
st.stop()
print(" \nGo back to app")
st.stop()

print(" \nGo back to app")

Expand Down
47 changes: 35 additions & 12 deletions maven/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,43 @@
import socket
import getpass
import sys
import random

PORT = 8505
APP = os.path.join(os.path.dirname(__file__), "app.py")
PORT_MIN = 7000
PORT_MAX = 9000

def find_available_port():
"""Return an unused localhost port in the configured range."""
ports = list(range(PORT_MIN, PORT_MAX + 1))
random.SystemRandom().shuffle(ports)

for port in ports:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as test_socket:
try:
# Test the same interface Streamlit will use.
test_socket.bind(("127.0.0.1", port))
test_socket.listen(1)
return port
except OSError:
continue

raise RuntimeError(f"No available port found between {PORT_MIN} and {PORT_MAX}.")

def main():
APP = os.path.join(os.path.dirname(__file__), "app.py")
PORT = find_available_port()

env = os.environ.copy()
env["PYTHONUNBUFFERED"] = "1"

if os.name != "nt":
subprocess.run(f"lsof -t -iTCP:{PORT} -sTCP:LISTEN | xargs -r kill -9", shell=True,
check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
from colorama import Fore, Style, init
init(autoreset=True)
subprocess.run(f'for /f "tokens=5" %a in (\'netstat -ano ^| findstr :{PORT} ^| findstr LISTENING\') do taskkill /F /PID %a >nul 2>&1',
shell=True, check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# if os.name != "nt":
# subprocess.run(f"lsof -t -iTCP:{PORT} -sTCP:LISTEN | xargs -r kill -9", shell=True,
# check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# else:
# from colorama import Fore, Style, init
# init(autoreset=True)
# subprocess.run(f'for /f "tokens=5" %a in (\'netstat -ano ^| findstr :{PORT} ^| findstr LISTENING\') do taskkill /F /PID %a >nul 2>&1',
# shell=True, check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

is_remote = any(os.environ.get(x) for x in ["SSH_CONNECTION", "SSH_CLIENT", "SSH_TTY"])
if is_remote:
Expand All @@ -30,6 +50,8 @@ def main():
if os.name != "nt":
print(f" \033[1mssh -L {PORT}:localhost:{PORT} {remote_user}@{remote_host}\033[0m")
else:
from colorama import Fore, Style, init
init(autoreset=True)
print(f" {Style.BRIGHT}ssh -L {PORT}:localhost:{PORT} {remote_user}@{remote_host}{Style.RESET_ALL}")
print(" (Leave the new terminal running while using the app)")

Expand All @@ -40,8 +62,8 @@ def main():
print(" It may take a few minutes to load the first time")
print("\nTo exit, press Ctrl+C here")

cmd = [sys.executable, "-m", "streamlit", "run", APP, f"--server.port={PORT}", "--server.headless=true",
"--browser.gatherUsageStats=false"]
cmd = [sys.executable, "-m", "streamlit", "run", APP, f"--server.port={PORT}", "--server.address=127.0.0.1",
"--server.headless=true", "--browser.gatherUsageStats=false"]
proc = subprocess.Popen(cmd, env=env, stdin=None, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1)
try:
for line in proc.stdout:
Expand All @@ -58,6 +80,7 @@ def main():
or "Could not bind IPv6 wildcard address" in line
or "Did not auto detect external IP" in line
or "debugging hints" in line
or "URL: " in line
or line == ""
):
continue
Expand Down