Add pyzebra handler
* allow user to specify anatric path
This commit is contained in:
parent
3c58fd2102
commit
45f295fcf8
@ -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 = [
|
|||||||
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:
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
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
|
|||||||
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)
|
|||||||
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)
|
||||||
|
|
||||||
|
30
pyzebra/app/handler.py
Normal file
30
pyzebra/app/handler.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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
|
|||||||
|
|
||||||
|
|
||||||
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():
|
|||||||
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():
|
|||||||
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
|
|||||||
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():
|
|||||||
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():
|
|||||||
|
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user