forked from M-Labs/artiq
1
0
Fork 0

applets: simplify command lines

This commit is contained in:
Sebastien Bourdeauducq 2016-09-04 23:32:09 +08:00
parent 8f6c4451ac
commit 549e09e06b
3 changed files with 27 additions and 26 deletions

View File

@ -3,6 +3,12 @@
Release notes
=============
3.0 (unreleased)
----------------
* The --embed option of applets is replaced with the environment variable
ARTIQ_APPLET_EMBED.
2.0rc1
------

View File

@ -94,10 +94,6 @@ class SimpleApplet:
"--port", default=3250, type=int,
help="TCP port to connect to")
self.argparser.add_argument(
"--embed", default=None, help="embed into GUI",
metavar="IPC_ADDRESS")
self._arggroup_datasets = self.argparser.add_argument_group("datasets")
self.dataset_args = set()
@ -114,6 +110,7 @@ class SimpleApplet:
def args_init(self):
self.args = self.argparser.parse_args()
self.embed = os.getenv("ARTIQ_APPLET_EMBED")
self.datasets = {getattr(self.args, arg.replace("-", "_"))
for arg in self.dataset_args}
@ -123,17 +120,17 @@ class SimpleApplet:
asyncio.set_event_loop(self.loop)
def ipc_init(self):
if self.args.embed is not None:
self.ipc = AppletIPCClient(self.args.embed)
if self.embed is not None:
self.ipc = AppletIPCClient(self.embed)
self.loop.run_until_complete(self.ipc.connect())
def ipc_close(self):
if self.args.embed is not None:
if self.embed is not None:
self.ipc.close()
def create_main_widget(self):
self.main_widget = self.main_widget_class(self.args)
if self.args.embed is not None:
if self.embed is not None:
self.ipc.set_close_cb(self.main_widget.close)
if os.name == "nt":
# HACK: if the window has a frame, there will be garbage
@ -166,7 +163,7 @@ class SimpleApplet:
return data
def filter_mod(self, mod):
if self.args.embed is not None:
if self.embed is not None:
# the parent already filters for us
return True
@ -201,7 +198,7 @@ class SimpleApplet:
self.emit_data_changed(self.data, [mod])
def subscribe(self):
if self.args.embed is None:
if self.embed is None:
self.subscriber = Subscriber("datasets",
self.sub_init, self.sub_mod)
self.loop.run_until_complete(self.subscriber.connect(
@ -210,7 +207,7 @@ class SimpleApplet:
self.ipc.subscribe(self.datasets, self.sub_init, self.sub_mod)
def unsubscribe(self):
if self.args.embed is None:
if self.embed is None:
self.loop.run_until_complete(self.subscriber.close())
def run(self):

View File

@ -118,17 +118,16 @@ class _AppletDock(QDockWidgetCloseDetect):
self.starting_stopping = True
try:
self.ipc = AppletIPCServer(self.datasets_sub)
if "$ipc_address" not in self.command:
logger.warning("IPC address missing from command for %s",
self.applet_name)
command_tpl = string.Template(self.command)
python = sys.executable.replace("\\", "\\\\")
command = command_tpl.safe_substitute(
python=sys.executable.replace("\\", "\\\\"),
ipc_address=self.ipc.get_address().replace("\\", "\\\\")
python=python,
artiq_applet=python + " -m artiq.applets."
)
logger.debug("starting command %s for %s", command, self.applet_name)
env = os.environ.copy()
env["PYTHONUNBUFFERED"] = "1"
env["ARTIQ_APPLET_EMBED"] = self.ipc.get_address()
try:
await self.ipc.create_subprocess(
*shlex.split(command),
@ -194,20 +193,19 @@ class _AppletDock(QDockWidgetCloseDetect):
_templates = [
("Big number", "$python -m artiq.applets.big_number "
"--embed $ipc_address NUMBER_DATASET"),
("Histogram", "$python -m artiq.applets.plot_hist "
"--embed $ipc_address COUNTS_DATASET "
("Big number", "${artiq_applet}big_number "
"NUMBER_DATASET"),
("Histogram", "${artiq_applet}plot_hist "
"COUNTS_DATASET "
"--x BIN_BOUNDARIES_DATASET"),
("XY", "$python -m artiq.applets.plot_xy "
"--embed $ipc_address Y_DATASET --x X_DATASET "
("XY", "${artiq_applet}plot_xy "
"Y_DATASET --x X_DATASET "
"--error ERROR_DATASET --fit FIT_DATASET"),
("XY + Histogram", "$python -m artiq.applets.plot_xy_hist "
"--embed $ipc_address X_DATASET "
("XY + Histogram", "${artiq_applet}plot_xy_hist "
"X_DATASET "
"HIST_BIN_BOUNDARIES_DATASET "
"HISTS_COUNTS_DATASET"),
("Image", "$python -m artiq.applets.image "
"--embed $ipc_address IMG_DATASET"),
("Image", "${artiq_applet}image IMG_DATASET"),
]