Skip to content

Commit fb46bbb

Browse files
committed
refactor retrieve_all_from_ss
1 parent 82094a6 commit fb46bbb

File tree

6 files changed

+81
-49
lines changed

6 files changed

+81
-49
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[tool.isort]
2+
profile = "black"
3+
filter_files = true
4+
15
[tool.black]
26
line-length = 127
37
extend-exclude = '''

shared/sessionstate.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@ def save_in_ss(data_dict):
1919

2020

2121
def retrieve_all_from_ss():
22-
OK = ss_get("LOGIN_OK", False)
23-
MY_SSH = ss_get("MY_SSH", None)
24-
username = ss_get("user_name", "")
25-
GROUPS = ss_get("GROUPS", "")
26-
GROUP = ss_get("GROUP", "")
27-
SCRATCH = ss_get("SCRATCH", "")
28-
RDS = ss_get("RDS", "")
29-
PROJECT = ss_get("PROJECT", None)
30-
SAMPLE = ss_get("SAMPLE", None)
31-
PIPELINE = ss_get("PIPELINE", "select")
32-
return OK, MY_SSH, username, GROUPS, GROUP, SCRATCH, RDS, PROJECT, SAMPLE, PIPELINE
33-
34-
35-
# keys = ["LOGIN_OK", "MY_SSH", "user_name", "GROUPS", "GROUP", "SCRATCH", "RDS"]
36-
# def retrieve_all_from_ss(keys):
37-
# return {key: ss_get(key, default_value) for key, default_value in zip(keys, [False, None, "", "", "", "", ""])}
22+
keys_defaults = {
23+
"LOGIN_OK": False,
24+
"MY_SSH": None,
25+
"user_name": "",
26+
"GROUPS": "",
27+
"GROUP": "Select an option",
28+
"SCRATCH": "",
29+
"RDS": "",
30+
"PROJECT": None,
31+
"SAMPLE": None,
32+
"PIPELINE": "select",
33+
}
34+
35+
return tuple(ss_get(key, default) for key, default in keys_defaults.items())

tabs/tab_command.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@
1515
if "job_id" not in st.session_state:
1616
ss_set("job_id", "")
1717
# pull saved values if set, otherwise set to defaults
18-
OK, MY_SSH, username, GROUPS, GROUP, SCRATCH, RDS, PROJECT, SAMPLE, PIPELINE = retrieve_all_from_ss()
18+
(
19+
OK,
20+
MY_SSH,
21+
username,
22+
GROUPS,
23+
GROUP,
24+
SCRATCH,
25+
RDS,
26+
PROJECT,
27+
SAMPLE,
28+
PIPELINE,
29+
) = retrieve_all_from_ss()
1930

2031

2132
def get_path_to_script(selected_pipeline, selected_project, selected="all"):

tabs/tab_logon.py

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import streamlit as st
22

33
import shared.helpers as hlp
4-
from shared.sessionstate import retrieve_all_from_ss, save_in_ss, ss_get
4+
from shared.sessionstate import retrieve_all_from_ss, save_in_ss, ss_get, ss_set
5+
6+
7+
def handle_login(server, sftp_server, username, password):
8+
if username == "admin" and password == "admin":
9+
st.success("Admin login successful")
10+
return True, None, "Admin login successful", None # No SSH or groups needed for admin
11+
12+
with st.spinner("Validating login..."):
13+
OK, MY_SSH, msg, GROUPS = hlp.validate_user(server, sftp_server, username, password)
14+
15+
return OK, MY_SSH, msg, GROUPS
516

617

718
# once connected, you cannot try to re-connect
819
def tab():
920
# pull saved values if set, otherwise set to defaults
1021
keys = ["LOGIN_OK", "MY_SSH", "user_name", "GROUPS", "GROUP", "SCRATCH", "RDS", "PROJECT", "SAMPLE"]
11-
OK, MY_SSH, username, GROUPS, GROUP, SCRATCH, RDS, PROJECT, SAMPLE, PIPELINE = retrieve_all_from_ss()
22+
(OK, MY_SSH, username, GROUPS, GROUP, SCRATCH, RDS, PROJECT, SAMPLE, PIPELINE) = retrieve_all_from_ss()
1223
cols = st.columns(3)
1324
with cols[0]:
1425
server = st.text_input("Enter your remote server:", "alma.icr.ac.uk", key="server")
@@ -17,30 +28,39 @@ def tab():
1728
with cols[2]:
1829
password = st.text_input("Enter your password:", "", type="password", key="password")
1930
sftp_server = "alma-app.icr.ac.uk"
31+
32+
def update_group():
33+
GROUP = ss_get("group_selection")
34+
SCRATCH, RDS = hlp.get_scratch_rds_path(username, GROUP)
35+
save_in_ss(
36+
{
37+
"LOGIN_OK": True,
38+
"MY_SSH": MY_SSH,
39+
"user_name": username,
40+
"GROUPS": GROUPS,
41+
"GROUP": GROUP,
42+
"SCRATCH": SCRATCH,
43+
"RDS": RDS,
44+
}
45+
)
46+
47+
def handle_group_selection(GROUPS):
48+
st.radio(
49+
"Select group",
50+
["Select an option"] + GROUPS,
51+
horizontal=True,
52+
index=0,
53+
key="group_selection",
54+
on_change=update_group,
55+
)
56+
return
57+
2058
if st.button("Connect", key="connect"):
21-
if username == "admin" and password == "admin":
22-
st.success("Admin login successful")
23-
OK = True
59+
OK, MY_SSH, msg, GROUPS = handle_login(server, sftp_server, username, password)
60+
if OK:
61+
st.success(msg)
62+
handle_group_selection(GROUPS)
2463
else:
25-
with st.spinner("Validating login"):
26-
OK, MY_SSH, msg, GROUPS = hlp.validate_user(server, sftp_server, username, password)
27-
print(OK, MY_SSH, msg, GROUPS)
28-
if OK:
29-
st.success(msg)
30-
GROUP = st.radio("Select group", GROUPS, horizontal=True)
31-
SCRATCH, RDS = hlp.get_scratch_rds_path(username, GROUP)
32-
# save in session states
33-
ss_dict = {
34-
"LOGIN_OK": OK,
35-
"MY_SSH": MY_SSH,
36-
"user_name": username,
37-
"GROUPS": GROUPS,
38-
"GROUP": GROUP,
39-
"SCRATCH": SCRATCH,
40-
"RDS": RDS,
41-
}
42-
save_in_ss(ss_dict)
43-
else:
44-
st.error(msg)
45-
46-
return OK, MY_SSH, username
64+
st.error(msg)
65+
66+
return OK, MY_SSH, username, GROUP

views/login.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
st.write("Login to your alma account before running a nextflow pipeline.")
1111

1212

13-
tl.tab()
13+
OK, MY_SSH, username, GROUP = tl.tab()
1414
# pull saved values if set, otherwise set to defaults
15-
OK, MY_SSH, username, GROUPS, GROUP, SCRATCH, RDS, PROJECT, SAMPLE, PIPELINE = retrieve_all_from_ss()
15+
(OK, MY_SSH, username, GROUPS, GROUP, SCRATCH, RDS, PROJECT, SAMPLE, PIPELINE) = retrieve_all_from_ss()
1616

1717

1818
# I want to move between tabs automatically
@@ -58,8 +58,7 @@ def check_whiteList(username):
5858

5959
# if "run_pipeline" not in st.session_state:
6060
# ss_set("run_pipeline", False)
61-
62-
if OK:
61+
if OK and GROUP != "Select an option":
6362
if not check_whiteList(username):
6463
display_restricted_access(username)
6564
else:

views/run_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def reset_button_state():
1515
st.write("Select your pipeline and your project, then submit the process")
1616

1717
# pull saved values if set, otherwise set to defaults
18-
OK, MY_SSH, username, GROUPS, GROUP, SCRATCH, RDS, PROJECT, SAMPLE, PIPELINE = retrieve_all_from_ss()
18+
(OK, MY_SSH, username, GROUPS, GROUP, SCRATCH, RDS, PROJECT, SAMPLE, PIPELINE) = retrieve_all_from_ss()
1919

2020
samples = ["all", "demo"] # , "customised"]
2121

0 commit comments

Comments
 (0)