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 Release notes
============= =============
3.0 (unreleased)
----------------
* The --embed option of applets is replaced with the environment variable
ARTIQ_APPLET_EMBED.
2.0rc1 2.0rc1
------ ------

View File

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

View File

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