Generalize search for proposals
Avoid hardcoding specific years in proposal paths
This commit is contained in:
parent
89fffed5d1
commit
e30035350b
@ -36,14 +36,18 @@ proposal_textinput.on_change("value_input", proposal_textinput_callback)
|
|||||||
doc.proposal_textinput = proposal_textinput
|
doc.proposal_textinput = proposal_textinput
|
||||||
|
|
||||||
def apply_button_callback():
|
def apply_button_callback():
|
||||||
|
proposal = proposal_textinput.value.strip()
|
||||||
|
if proposal:
|
||||||
try:
|
try:
|
||||||
proposal_path = pyzebra.find_proposal_path(proposal_textinput.value)
|
proposal_path = pyzebra.find_proposal_path(proposal)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(e)
|
print(e)
|
||||||
return
|
return
|
||||||
|
apply_button.disabled = True
|
||||||
|
else:
|
||||||
|
proposal_path = ""
|
||||||
|
|
||||||
proposal_textinput.name = proposal_path
|
proposal_textinput.name = proposal_path
|
||||||
apply_button.disabled = True
|
|
||||||
|
|
||||||
apply_button = Button(label="Apply", button_type="primary")
|
apply_button = Button(label="Apply", button_type="primary")
|
||||||
apply_button.on_click(apply_button_callback)
|
apply_button.on_click(apply_button_callback)
|
||||||
|
@ -1,20 +1,17 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
ZEBRA_PROPOSALS_PATHS = [
|
SINQ_PATH = "/afs/psi.ch/project/sinqdata"
|
||||||
f"/afs/psi.ch/project/sinqdata/{year}/zebra/" for year in (2016, 2017, 2018, 2020, 2021, 2022)
|
ZEBRA_PROPOSALS_PATH = os.path.join(SINQ_PATH, "{year}/zebra/{proposal}")
|
||||||
]
|
|
||||||
|
|
||||||
def find_proposal_path(proposal):
|
def find_proposal_path(proposal):
|
||||||
proposal = proposal.strip()
|
for entry in os.scandir(SINQ_PATH):
|
||||||
if proposal:
|
if entry.is_dir() and len(entry.name) == 4 and entry.name.isdigit():
|
||||||
for zebra_proposals_path in ZEBRA_PROPOSALS_PATHS:
|
proposal_path = ZEBRA_PROPOSALS_PATH.format(year=entry.name, proposal=proposal)
|
||||||
proposal_path = os.path.join(zebra_proposals_path, proposal)
|
|
||||||
if os.path.isdir(proposal_path):
|
if os.path.isdir(proposal_path):
|
||||||
# found it
|
# found it
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Can not find data for proposal '{proposal}'.")
|
raise ValueError(f"Can not find data for proposal '{proposal}'.")
|
||||||
else:
|
|
||||||
proposal_path = ""
|
|
||||||
|
|
||||||
return proposal_path
|
return proposal_path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user