tools: ratbag-command.py: add verbose mode

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Benjamin Tissoires
2017-09-14 16:30:06 +02:00
parent 17380baae9
commit 1a3ef63519
2 changed files with 23 additions and 2 deletions

View File

@@ -143,6 +143,26 @@ class Ratbagd(object):
self._devices[name] = dev
self._devices_initialized = True
@property
def verbose(self):
v = libratbag.ratbag_log_get_priority(self._ratbag)
if v == libratbag.RATBAG_LOG_PRIORITY_RAW:
return 3
elif v == libratbag.RATBAG_LOG_PRIORITY_DEBUG:
# to match with setter action, we return 1 instead of 2
return 1
elif v == libratbag.RATBAG_LOG_PRIORITY_INFO:
return 1
elif v == libratbag.RATBAG_LOG_PRIORITY_ERROR:
return 0
@verbose.setter
def verbose(self, verbosity):
if verbosity > 2:
libratbag.ratbag_log_set_priority(self._ratbag, libratbag.RATBAG_LOG_PRIORITY_RAW)
elif verbosity >= 1:
libratbag.ratbag_log_set_priority(self._ratbag, libratbag.RATBAG_LOG_PRIORITY_DEBUG)
def __enter__(self):
return self

View File

@@ -1478,9 +1478,10 @@ def get_parser():
return RatbagParserRoot(parser_def)
def open_ratbagd(ratbagd_process=None):
def open_ratbagd(ratbagd_process=None, verbose=0):
try:
r = Ratbagd()
r.verbose = verbose
except RatbagdDBusUnavailable:
print("Unable to connect to ratbagd over dbus")
return None
@@ -1506,7 +1507,7 @@ def main(argv):
parser.print_help()
return
_r = open_ratbagd()
_r = open_ratbagd(verbose=cmd.verbose)
if _r is not None:
with _r as r:
try: