mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
tools: add --keepalive option to ratbagd devel
Keeps the ratbagd daemon running until a signal is received. This is helpful for using an external client (like piper) to run against the ratbagd.devel instance. And to make that even easier, print the RATBAGCTL_DEVEL environment variable for use with ratbagd.py. In the future, this should probably be a more generic name. The integration is a bit odd because we need to add --keepalive to the actual parser, but we recreate that on every parse() call. So we set a flag on the parent object and check for that during parser creation. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Benjamin Tissoires
parent
2b49550b9b
commit
87ecd6e252
@@ -27,6 +27,7 @@
|
||||
|
||||
import os
|
||||
import toolbox
|
||||
import signal
|
||||
import sys
|
||||
|
||||
|
||||
@@ -41,11 +42,18 @@ def main(argv):
|
||||
|
||||
ratbagd = toolbox.open_ratbagd()
|
||||
parser = toolbox.get_parser()
|
||||
parser.want_keepalive = True
|
||||
print('export RATBAGCTL_DEVEL="{}"\n'.format(os.environ['RATBAGCTL_DEVEL']))
|
||||
|
||||
try:
|
||||
cmd = parser.parse(argv)
|
||||
cmd.func(ratbagd, cmd)
|
||||
finally:
|
||||
try:
|
||||
if cmd.keepalive:
|
||||
signal.pause()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
toolbox.terminate_ratbagd(ratbagd_process)
|
||||
|
||||
|
||||
|
||||
@@ -1272,6 +1272,7 @@ classes = {
|
||||
class RatbagParserRoot(object):
|
||||
def __init__(self, commands):
|
||||
self.children = [classes[def_parser[of_type]](**def_parser) for def_parser in commands]
|
||||
self.want_keepalive = False
|
||||
|
||||
def parse(self, input_string):
|
||||
# we do not care about case, use lower case for the input string
|
||||
@@ -1284,6 +1285,8 @@ class RatbagParserRoot(object):
|
||||
self.parser.add_argument("-V", "--version", action="version", version="@version@")
|
||||
self.parser.add_argument('--verbose', '-v', action='count', default=0)
|
||||
self.parser.add_argument('--help', '-h', action='store_true', default=False)
|
||||
if self.want_keepalive:
|
||||
self.parser.add_argument('--keepalive', action='store_true', default=False)
|
||||
|
||||
ns, rest = self.parser.parse_known_args(input_string)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user