2
2
3
3
import argparse
4
4
5
+ from prettytable import PrettyTable
6
+
5
7
from artiq .management .pc_rpc import Client
6
8
7
9
@@ -15,8 +17,9 @@ def _get_args():
15
17
help = "TCP port to use to connect to the master" )
16
18
17
19
subparsers = parser .add_subparsers (dest = "action" )
20
+ subparsers .required = True
18
21
19
- parser_add = subparsers .add_parser ("add " , help = "add an experiment" )
22
+ parser_add = subparsers .add_parser ("submit " , help = "submit an experiment" )
20
23
parser_add .add_argument (
21
24
"-p" , "--periodic" , default = None , type = float ,
22
25
help = "run the experiment periodically every given number of seconds" )
@@ -29,23 +32,70 @@ def _get_args():
29
32
help = "unit to run" )
30
33
parser_add .add_argument ("file" , help = "file containing the unit to run" )
31
34
35
+
36
+ parser_cancel = subparsers .add_parser ("cancel" ,
37
+ help = "cancel an experiment" )
38
+ parser_cancel .add_argument ("-p" , "--periodic" , default = False ,
39
+ action = "store_true" ,
40
+ help = "cancel a periodic experiment" )
41
+ parser_cancel .add_argument ("rid" , type = int ,
42
+ help = "run identifier (RID/PRID)" )
43
+
44
+ parser_show = subparsers .add_parser ("show" ,
45
+ help = "show the experiment schedule" )
46
+
32
47
return parser .parse_args ()
33
48
34
49
50
+ def _action_submit (remote , args ):
51
+ run_params = {
52
+ "file" : args .file ,
53
+ "unit" : args .unit ,
54
+ "function" : args .function
55
+ }
56
+ if args .periodic is None :
57
+ rid = remote .run_once (run_params , args .timeout )
58
+ print ("RID: {}" .format (rid ))
59
+ else :
60
+ prid = remote .run_periodic (run_params , args .timeout ,
61
+ args .periodic )
62
+ print ("PRID: {}" .format (prid ))
63
+
64
+
65
+ def _action_cancel (remote , args ):
66
+ if args .periodic :
67
+ remote .cancel_periodic (args .rid )
68
+ else :
69
+ remote .cancel_once (args .rid )
70
+
71
+
72
+ def _action_show (remote , args ):
73
+ ce , queue = remote .get_schedule ()
74
+ if ce is None and not queue :
75
+ print ("Queue is empty" )
76
+ else :
77
+ table = PrettyTable (["RID" , "File" , "Unit" , "Function" , "Timeout" ])
78
+ if ce is not None :
79
+ rid , run_params , timeout , t = ce
80
+ print ("Currently executing RID {} for {:.1f}s" .format (rid , t ))
81
+ row = [rid , run_params ["file" ]]
82
+ for x in run_params ["unit" ], run_params ["function" ], timeout :
83
+ row .append ("-" if x is None else x )
84
+ table .add_row (row )
85
+ for rid , run_params , timeout in queue :
86
+ row = [rid , run_params ["file" ]]
87
+ for x in run_params ["unit" ], run_params ["function" ], timeout :
88
+ row .append ("-" if x is None else x )
89
+ table .add_row (row )
90
+ print ("Run queue:" )
91
+ print (table )
92
+
93
+
35
94
def main ():
36
95
args = _get_args ()
37
96
remote = Client (args .server , args .port , "master" )
38
97
try :
39
- if args .action == "add" :
40
- if args .periodic is None :
41
- remote .run_once (
42
- {
43
- "file" : args .file ,
44
- "unit" : args .unit ,
45
- "function" : args .function
46
- }, args .timeout )
47
- else :
48
- raise NotImplementedError
98
+ globals ()["_action_" + args .action ](remote , args )
49
99
finally :
50
100
remote .close_rpc ()
51
101
0 commit comments