Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit 45f295fc authored by usov_i's avatar usov_i
Browse files

Add pyzebra handler

* allow user to specify anatric path
parent 3c58fd21
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,6 @@ import subprocess ...@@ -2,7 +2,6 @@ import subprocess
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
ANATRIC_PATH = "/afs/psi.ch/project/sinq/rhel7/bin/anatric"
DATA_FACTORY_IMPLEMENTATION = [ DATA_FACTORY_IMPLEMENTATION = [
"trics", "trics",
"morph", "morph",
...@@ -24,8 +23,8 @@ REFLECTION_PRINTER_FORMATS = [ ...@@ -24,8 +23,8 @@ REFLECTION_PRINTER_FORMATS = [
ALGORITHMS = ["adaptivemaxcog", "adaptivedynamic"] ALGORITHMS = ["adaptivemaxcog", "adaptivedynamic"]
def anatric(config_file): def anatric(config_file, anatric_path="/afs/psi.ch/project/sinq/rhel7/bin/anatric"):
subprocess.run([ANATRIC_PATH, config_file], check=True) subprocess.run([anatric_path, config_file], check=True)
class AnatricConfig: class AnatricConfig:
......
import argparse
import logging import logging
import sys import sys
from io import StringIO from io import StringIO
...@@ -11,14 +10,8 @@ import panel_ccl_integrate ...@@ -11,14 +10,8 @@ import panel_ccl_integrate
import panel_hdf_anatric import panel_hdf_anatric
import panel_hdf_viewer import panel_hdf_viewer
parser = argparse.ArgumentParser(
prog="pyzebra", formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
args = parser.parse_args()
doc = curdoc() doc = curdoc()
doc.title = "pyzebra"
sys.stdout = StringIO() sys.stdout = StringIO()
stdout_textareainput = TextAreaInput(title="print output:", height=150) stdout_textareainput = TextAreaInput(title="print output:", height=150)
...@@ -26,7 +19,7 @@ stdout_textareainput = TextAreaInput(title="print output:", height=150) ...@@ -26,7 +19,7 @@ stdout_textareainput = TextAreaInput(title="print output:", height=150)
bokeh_stream = StringIO() bokeh_stream = StringIO()
bokeh_handler = logging.StreamHandler(bokeh_stream) bokeh_handler = logging.StreamHandler(bokeh_stream)
bokeh_handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT)) bokeh_handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
bokeh_logger = logging.getLogger('bokeh') bokeh_logger = logging.getLogger("bokeh")
bokeh_logger.addHandler(bokeh_handler) bokeh_logger.addHandler(bokeh_handler)
bokeh_log_textareainput = TextAreaInput(title="server output:", height=150) bokeh_log_textareainput = TextAreaInput(title="server output:", height=150)
......
from bokeh.application.handlers import Handler
class PyzebraHandler(Handler):
"""Provides a mechanism for generic bokeh applications to build up new streamvis documents.
"""
def __init__(self, anatric_path):
"""Initialize a pyzebra handler for bokeh applications.
Args:
args (Namespace): Command line parsed arguments.
"""
super().__init__() # no-op
self.anatric_path = anatric_path
def modify_document(self, doc):
"""Modify an application document with pyzebra specific features.
Args:
doc (Document) : A bokeh Document to update in-place
Returns:
Document
"""
doc.title = "pyzebra"
doc.anatric_path = self.anatric_path
return doc
...@@ -21,6 +21,7 @@ from pyzebra.anatric import DATA_FACTORY_IMPLEMENTATION, REFLECTION_PRINTER_FORM ...@@ -21,6 +21,7 @@ from pyzebra.anatric import DATA_FACTORY_IMPLEMENTATION, REFLECTION_PRINTER_FORM
def create(): def create():
doc = curdoc()
config = pyzebra.AnatricConfig() config = pyzebra.AnatricConfig()
def _load_config_file(file): def _load_config_file(file):
...@@ -345,7 +346,7 @@ def create(): ...@@ -345,7 +346,7 @@ def create():
with tempfile.TemporaryDirectory() as temp_dir: with tempfile.TemporaryDirectory() as temp_dir:
temp_file = temp_dir + "/temp.xml" temp_file = temp_dir + "/temp.xml"
config.save_as(temp_file) config.save_as(temp_file)
pyzebra.anatric(temp_file) pyzebra.anatric(temp_file, anatric_path=doc.anatric_path)
with open(config.logfile) as f_log: with open(config.logfile) as f_log:
output_log.value = f_log.read() output_log.value = f_log.read()
...@@ -404,6 +405,6 @@ def create(): ...@@ -404,6 +405,6 @@ def create():
with open("debug.xml") as f_config: with open("debug.xml") as f_config:
output_config.value = f_config.read() output_config.value = f_config.read()
curdoc().add_periodic_callback(update_config, 1000) doc.add_periodic_callback(update_config, 1000)
return Panel(child=tab_layout, title="hdf anatric") return Panel(child=tab_layout, title="hdf anatric")
...@@ -6,6 +6,8 @@ from bokeh.application.application import Application ...@@ -6,6 +6,8 @@ from bokeh.application.application import Application
from bokeh.application.handlers import ScriptHandler from bokeh.application.handlers import ScriptHandler
from bokeh.server.server import Server from bokeh.server.server import Server
from pyzebra.app.handler import PyzebraHandler
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.INFO) logging.basicConfig(format="%(asctime)s %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -35,6 +37,13 @@ def main(): ...@@ -35,6 +37,13 @@ def main():
help="hostname that can connect to the server websocket", help="hostname that can connect to the server websocket",
) )
parser.add_argument(
"--anatric-path",
type=str,
default="/afs/psi.ch/project/sinq/rhel7/bin/anatric",
help="path to anatric executable",
)
parser.add_argument( parser.add_argument(
"--args", "--args",
nargs=argparse.REMAINDER, nargs=argparse.REMAINDER,
...@@ -46,9 +55,10 @@ def main(): ...@@ -46,9 +55,10 @@ def main():
logger.info(app_path) logger.info(app_path)
pyzebra_handler = PyzebraHandler(args.anatric_path)
handler = ScriptHandler(filename=app_path, argv=args.args) handler = ScriptHandler(filename=app_path, argv=args.args)
server = Server( server = Server(
{"/": Application(handler)}, {"/": Application(pyzebra_handler, handler)},
port=args.port, port=args.port,
allow_websocket_origin=args.allow_websocket_origin, allow_websocket_origin=args.allow_websocket_origin,
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment