Skip to content

Commit 3d4593c

Browse files
committed
qemu: Add --callback for specifying callbacks to run
1 parent b3d7334 commit 3d4593c

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

lib/qemu.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def configure_from_args(self, orig_args):
9090
parser.add_argument('--cap', dest='machine_caps', type=str, default=[], action='append', help='Machine caps')
9191
parser.add_argument('--qemu-path', dest='qemu_path', type=str, help='Path to qemu bin directory')
9292
parser.add_argument('--root-disk-path', dest='root_disk_path', type=str, help='Path to root disk directory')
93+
parser.add_argument('--callback', metavar='callback', dest='callbacks', type=str, default=[], action='append', help='Callback to run')
9394
args = parser.parse_args(orig_args)
9495

9596
if args.gdb:
@@ -154,6 +155,26 @@ def configure_from_args(self, orig_args):
154155
self.host_mounts.extend(args.mounts)
155156
self.machine_caps.extend(args.machine_caps)
156157

158+
def make_callback(func, arg_str):
159+
if arg_str:
160+
return lambda qconf, p: func(qconf, p, arg_str)
161+
else:
162+
return func
163+
164+
for cb in args.callbacks:
165+
# Callbacks can take args, like callback(foo bar)
166+
# But the callback just gets a string "foo bar"
167+
if '(' in cb:
168+
name, arg_str = cb.split('(', 1)
169+
arg_str = arg_str[:-1] # Crop trailing )
170+
else:
171+
name = cb
172+
arg_str = None
173+
174+
func = getattr(qemu_callbacks, name)
175+
self.callbacks.append(make_callback(func, arg_str))
176+
177+
157178
def apply_defaults(self):
158179
if not self.expected_release:
159180
logging.error("Couldn't find kernel.release")

0 commit comments

Comments
 (0)