master/gui/client: run arguments support

This commit is contained in:
Sebastien Bourdeauducq 2015-01-07 21:37:07 +08:00
parent 492ce1632b
commit be9f7550b5
4 changed files with 43 additions and 10 deletions

View File

@ -5,6 +5,7 @@ from gi.repository import Gtk
from artiq.gui.tools import Window, ListSyncer, DictSyncer
from artiq.management.sync_struct import Subscriber
from artiq.management.tools import format_run_arguments
class _QueueStoreSyncer(ListSyncer):
@ -13,6 +14,7 @@ class _QueueStoreSyncer(ListSyncer):
row = [rid, run_params["file"]]
for e in run_params["unit"], timeout:
row.append("-" if e is None else str(e))
row.append(format_run_arguments(run_params["arguments"]))
return row
@ -28,6 +30,7 @@ class _PeriodicStoreSyncer(DictSyncer):
for e in run_params["unit"], timeout:
row.append("-" if e is None else str(e))
row.append(str(period))
row.append(format_run_arguments(run_params["arguments"]))
return row
@ -51,9 +54,9 @@ class SchedulerWindow(Window):
notebook = Gtk.Notebook()
topvbox.pack_start(notebook, True, True, 0)
self.queue_store = Gtk.ListStore(int, str, str, str)
self.queue_store = Gtk.ListStore(int, str, str, str, str)
self.queue_tree = Gtk.TreeView(self.queue_store)
for i, title in enumerate(["RID", "File", "Unit", "Timeout"]):
for i, title in enumerate(["RID", "File", "Unit", "Timeout", "Arguments"]):
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(title, renderer, text=i)
self.queue_tree.append_column(column)
@ -75,10 +78,10 @@ class SchedulerWindow(Window):
vbox.set_border_width(6)
notebook.insert_page(vbox, Gtk.Label("Queue"), -1)
self.periodic_store = Gtk.ListStore(str, int, str, str, str, str)
self.periodic_store = Gtk.ListStore(str, int, str, str, str, str, str)
self.periodic_tree = Gtk.TreeView(self.periodic_store)
for i, title in enumerate(["Next run", "PRID", "File", "Unit",
"Timeout", "Period"]):
"Timeout", "Period", "Arguments"]):
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(title, renderer, text=i)
self.periodic_tree.append_column(column)

View File

@ -1,12 +1,23 @@
import asyncio
import sys
from copy import copy
from operator import itemgetter
def clear_screen():
sys.stdout.write("\x1b[2J\x1b[H")
def format_run_arguments(arguments):
fmtargs = []
for k, v in sorted(arguments.items(), key=itemgetter(0)):
fmtargs.append(k + "=" + str(v))
if fmtargs:
return " ".join(fmtargs)
else:
return "-"
class AsyncioServer:
"""Generic TCP server based on asyncio.

View File

@ -8,7 +8,7 @@ from artiq.language.context import AutoContext
from artiq.management.dpdb import DeviceParamSupplier
def run(dps, file, unit):
def run(dps, file, unit, arguments):
module = file_import(file)
if unit is None:
units = [v for k, v in module.__dict__.items()
@ -22,7 +22,7 @@ def run(dps, file, unit):
else:
unit = getattr(module, unit)
unit_inst = unit(dps)
unit_inst.run()
unit_inst.run(**arguments)
def get_object():

View File

@ -10,7 +10,7 @@ from prettytable import PrettyTable
from artiq.management.pc_rpc import Client
from artiq.management.sync_struct import Subscriber
from artiq.management.tools import clear_screen
from artiq.management.tools import clear_screen, format_run_arguments
from artiq.management import pyon
@ -36,6 +36,8 @@ def _get_args():
parser_add.add_argument("-u", "--unit", default=None,
help="unit to run")
parser_add.add_argument("file", help="file containing the unit to run")
parser_add.add_argument("arguments", nargs="*",
help="run arguments")
parser_cancel = subparsers.add_parser("cancel",
help="cancel an experiment")
@ -74,10 +76,25 @@ def _get_args():
return parser.parse_args()
def _parse_arguments(arguments):
d = {}
for argument in arguments:
name, value = argument.split("=")
d[name] = pyon.decode(value)
return d
def _action_submit(remote, args):
try:
arguments = _parse_arguments(args.arguments)
except:
print("Failed to parse run arguments")
sys.exit(1)
run_params = {
"file": args.file,
"unit": args.unit
"unit": args.unit,
"arguments": arguments
}
if args.periodic is None:
rid = remote.run_once(run_params, args.timeout)
@ -114,11 +131,12 @@ def _action_del_parameter(remote, args):
def _show_queue(queue):
clear_screen()
if queue:
table = PrettyTable(["RID", "File", "Unit", "Timeout"])
table = PrettyTable(["RID", "File", "Unit", "Timeout", "Arguments"])
for rid, run_params, timeout in queue:
row = [rid, run_params["file"]]
for x in run_params["unit"], timeout:
row.append("-" if x is None else x)
row.append(format_run_arguments(run_params["arguments"]))
table.add_row(row)
print(table)
else:
@ -129,7 +147,7 @@ def _show_periodic(periodic):
clear_screen()
if periodic:
table = PrettyTable(["Next run", "PRID", "File", "Unit",
"Timeout", "Period"])
"Timeout", "Period", "Arguments"])
sp = sorted(periodic.items(), key=lambda x: (x[1][0], x[0]))
for prid, (next_run, run_params, timeout, period) in sp:
row = [time.strftime("%m/%d %H:%M:%S", time.localtime(next_run)),
@ -137,6 +155,7 @@ def _show_periodic(periodic):
for x in run_params["unit"], timeout:
row.append("-" if x is None else x)
row.append(period)
row.append(format_run_arguments(run_params["arguments"]))
table.add_row(row)
print(table)
else: