xion: add verbose mode

This commit is contained in:
dece 2020-11-02 23:53:36 +01:00
parent ae0edfcaa0
commit 0f3a755083
3 changed files with 12 additions and 4 deletions

View file

@ -28,9 +28,13 @@ def main():
"-y", "--yes", action="store_true", "-y", "--yes", action="store_true",
help="Do not ask for confirmation" help="Do not ask for confirmation"
) )
argparser.add_argument(
"-v", "--verbose", action="store_true",
help="Verbose output"
)
args = argparser.parse_args() args = argparser.parse_args()
xion = Xion(xq=args.xq_path) xion = Xion(xq=args.xq_path, verbose=args.verbose)
if args.export: if args.export:
channel, root, output = args.export channel, root, output = args.export
tree = xion.build_tree(channel, root) tree = xion.build_tree(channel, root)

View file

@ -17,12 +17,15 @@ class Xfconf:
"gchararray": "string", "gchararray": "string",
} }
def __init__(self, xq=None): def __init__(self, xq=None, verbose=False):
self._xq = xq or self.find_xq() self._xq = xq or self.find_xq()
self.verbose = verbose
def xq(self, command, print_failures=True): def xq(self, command, print_failures=True):
"""Run a xion-query command and return its output or None on error.""" """Run a xion-query command and return its output or None on error."""
command.insert(0, self._xq) command.insert(0, self._xq)
if self.verbose:
print(f"$ {' '.join(command)}")
try: try:
return subprocess.check_output( return subprocess.check_output(
command, stderr=subprocess.STDOUT command, stderr=subprocess.STDOUT

View file

@ -6,8 +6,9 @@ from xion.xfconf import Xfconf
class Xion: class Xion:
"""Manipulate Xfconf settings trees.""" """Manipulate Xfconf settings trees."""
def __init__(self, xq=None): def __init__(self, xq=None, verbose=False):
self.xfconf = Xfconf(xq=xq) self.xfconf = Xfconf(xq=xq, verbose=verbose)
self.verbose = verbose
def build_tree(self, channel, root="/"): def build_tree(self, channel, root="/"):
"""Return a dict of properties in this channel, filtering on root. """Return a dict of properties in this channel, filtering on root.