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
|
||||
|
||||
def apply_button_callback():
|
||||
proposal = proposal_textinput.value.strip()
|
||||
if proposal:
|
||||
try:
|
||||
proposal_path = pyzebra.find_proposal_path(proposal_textinput.value)
|
||||
proposal_path = pyzebra.find_proposal_path(proposal)
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
return
|
||||
apply_button.disabled = True
|
||||
else:
|
||||
proposal_path = ""
|
||||
|
||||
proposal_textinput.name = proposal_path
|
||||
apply_button.disabled = True
|
||||
|
||||
apply_button = Button(label="Apply", button_type="primary")
|
||||
apply_button.on_click(apply_button_callback)
|
||||
|
@ -1,20 +1,17 @@
|
||||
import os
|
||||
|
||||
ZEBRA_PROPOSALS_PATHS = [
|
||||
f"/afs/psi.ch/project/sinqdata/{year}/zebra/" for year in (2016, 2017, 2018, 2020, 2021, 2022)
|
||||
]
|
||||
SINQ_PATH = "/afs/psi.ch/project/sinqdata"
|
||||
ZEBRA_PROPOSALS_PATH = os.path.join(SINQ_PATH, "{year}/zebra/{proposal}")
|
||||
|
||||
|
||||
def find_proposal_path(proposal):
|
||||
proposal = proposal.strip()
|
||||
if proposal:
|
||||
for zebra_proposals_path in ZEBRA_PROPOSALS_PATHS:
|
||||
proposal_path = os.path.join(zebra_proposals_path, proposal)
|
||||
for entry in os.scandir(SINQ_PATH):
|
||||
if entry.is_dir() and len(entry.name) == 4 and entry.name.isdigit():
|
||||
proposal_path = ZEBRA_PROPOSALS_PATH.format(year=entry.name, proposal=proposal)
|
||||
if os.path.isdir(proposal_path):
|
||||
# found it
|
||||
break
|
||||
else:
|
||||
raise ValueError(f"Can not find data for proposal '{proposal}'.")
|
||||
else:
|
||||
proposal_path = ""
|
||||
|
||||
return proposal_path
|
||||
|
Loading…
x
Reference in New Issue
Block a user