From 90387174e5b434316d91eacaba84d366322c66b7 Mon Sep 17 00:00:00 2001 From: Ivan Usov Date: Tue, 11 May 2021 16:13:09 +0200 Subject: [PATCH] Add optional cli argument for spind path --- pyzebra/app/cli.py | 11 ++++++----- pyzebra/app/handler.py | 4 +++- pyzebra/app/panel_spind.py | 10 ++++++++-- scripts/pyzebra-start.sh | 2 +- scripts/pyzebra-test-start.sh | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/pyzebra/app/cli.py b/pyzebra/app/cli.py index 464ace9..79ed80e 100644 --- a/pyzebra/app/cli.py +++ b/pyzebra/app/cli.py @@ -38,10 +38,11 @@ def main(): ) parser.add_argument( - "--anatric-path", - type=str, - default=None, - help="path to anatric executable", + "--anatric-path", type=str, default=None, help="path to anatric executable", + ) + + parser.add_argument( + "--spind-path", type=str, default=None, help="path to spind scripts folder", ) parser.add_argument( @@ -55,7 +56,7 @@ def main(): logger.info(app_path) - pyzebra_handler = PyzebraHandler(args.anatric_path) + pyzebra_handler = PyzebraHandler(args.anatric_path, args.spind_path) handler = ScriptHandler(filename=app_path, argv=args.args) server = Server( {"/": Application(pyzebra_handler, handler)}, diff --git a/pyzebra/app/handler.py b/pyzebra/app/handler.py index a10dad8..334f021 100644 --- a/pyzebra/app/handler.py +++ b/pyzebra/app/handler.py @@ -5,7 +5,7 @@ class PyzebraHandler(Handler): """Provides a mechanism for generic bokeh applications to build up new streamvis documents. """ - def __init__(self, anatric_path): + def __init__(self, anatric_path, spind_path): """Initialize a pyzebra handler for bokeh applications. Args: @@ -14,6 +14,7 @@ class PyzebraHandler(Handler): super().__init__() # no-op self.anatric_path = anatric_path + self.spind_path = spind_path def modify_document(self, doc): """Modify an application document with pyzebra specific features. @@ -26,5 +27,6 @@ class PyzebraHandler(Handler): """ doc.title = "pyzebra" doc.anatric_path = self.anatric_path + doc.spind_path = self.spind_path return doc diff --git a/pyzebra/app/panel_spind.py b/pyzebra/app/panel_spind.py index e6ce1b6..6b6e1d8 100644 --- a/pyzebra/app/panel_spind.py +++ b/pyzebra/app/panel_spind.py @@ -5,6 +5,7 @@ import subprocess import tempfile import numpy as np +from bokeh.io import curdoc from bokeh.layouts import column, row from bokeh.models import ( Button, @@ -22,6 +23,8 @@ import pyzebra def create(): + doc = curdoc() + path_prefix_textinput = TextInput(title="Path prefix:", value="") selection_list = TextAreaInput(title="ROIs:", rows=7) lattice_const_textinput = TextInput( @@ -54,7 +57,7 @@ def create(): "-n", "2", "python", - os.path.expanduser("~/spind/gen_hkl_table.py"), + os.path.join(doc.spind_path, "gen_hkl_table.py"), lattice_const_textinput.value, "--max-res", str(max_res_spinner.value), @@ -81,7 +84,7 @@ def create(): "-n", "2", "python", - os.path.expanduser("~/spind/SPIND.py"), + os.path.join(doc.spind_path, "SPIND.py"), temp_peak_list_dir, temp_hkl_file, "-o", @@ -136,6 +139,9 @@ def create(): process_button = Button(label="Process", button_type="primary") process_button.on_click(process_button_callback) + if doc.spind_path is None: + process_button.disabled = True + ub_matrix_textareainput = TextAreaInput(title="UB matrix:", rows=7, width=400) hkl_textareainput = TextAreaInput(title="hkl values:", rows=7, width=400) diff --git a/scripts/pyzebra-start.sh b/scripts/pyzebra-start.sh index 4d3433a..d1211ea 100644 --- a/scripts/pyzebra-start.sh +++ b/scripts/pyzebra-start.sh @@ -1,4 +1,4 @@ source /home/pyzebra/miniconda3/etc/profile.d/conda.sh conda activate prod -pyzebra --port=80 --allow-websocket-origin=pyzebra.psi.ch:80 +pyzebra --port=80 --allow-websocket-origin=pyzebra.psi.ch:80 --spind-path=/home/pyzebra/spind diff --git a/scripts/pyzebra-test-start.sh b/scripts/pyzebra-test-start.sh index 7035d93..b0e9c4b 100644 --- a/scripts/pyzebra-test-start.sh +++ b/scripts/pyzebra-test-start.sh @@ -1,4 +1,4 @@ source /home/pyzebra/miniconda3/etc/profile.d/conda.sh conda activate test -python ~/pyzebra/pyzebra/app/cli.py --allow-websocket-origin=pyzebra.psi.ch:5006 +python ~/pyzebra/pyzebra/app/cli.py --allow-websocket-origin=pyzebra.psi.ch:5006 --spind-path=/home/pyzebra/spind