forked from M-Labs/artiq
1
0
Fork 0

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

View File

@ -1,12 +1,23 @@
import asyncio import asyncio
import sys import sys
from copy import copy from copy import copy
from operator import itemgetter
def clear_screen(): def clear_screen():
sys.stdout.write("\x1b[2J\x1b[H") 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: class AsyncioServer:
"""Generic TCP server based on asyncio. """Generic TCP server based on asyncio.

View File

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

View File

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