test: add proper --verbose handling to the xkeyboard-config tester

Instead of defaulting to verbose on/off depending on isatty, make it an
argument instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
master
Peter Hutterer 2021-04-15 08:57:51 +10:00 committed by Ran Benita
parent f04c7e93ce
commit 44e8d4b044
1 changed files with 22 additions and 11 deletions

View File

@ -8,7 +8,7 @@ import xml.etree.ElementTree as ET
from multiprocessing import Pool
verbose = True
verbose = False
DEFAULT_RULES_XML = '@XKB_CONFIG_ROOT@/rules/evdev.xml'
@ -17,20 +17,24 @@ EXTRA_PATH = '@MESON_BUILD_ROOT@'
os.environ['PATH'] = ':'.join([EXTRA_PATH, os.getenv('PATH')])
def noop_progress_bar(x, total):
return x
def escape(s):
return s.replace('"', '\\"')
# The function generating the progress bar (if any).
progress_bar = noop_progress_bar
if os.isatty(sys.stdout.fileno()):
try:
from tqdm import tqdm
progress_bar = tqdm
def create_progress_bar(verbose):
def noop_progress_bar(x, total):
return x
verbose = False
except ImportError:
pass
progress_bar = noop_progress_bar
if not verbose and os.isatty(sys.stdout.fileno()):
try:
from tqdm import tqdm
progress_bar = tqdm
except ImportError:
pass
return progress_bar
def xkbcommontool(rmlvo):
@ -172,6 +176,9 @@ def run(combos, tool, njobs):
def main(args):
global progress_bar
global verbose
tools = {
'libxkbcommon': xkbcommontool,
'xkbcomp': xkbcomp,
@ -190,8 +197,12 @@ def main(args):
parser.add_argument('--jobs', '-j', type=int,
default=os.cpu_count() * 4,
help='number of processes to use')
parser.add_argument('--verbose', '-v', default=False, action="store_true")
args = parser.parse_args()
verbose = args.verbose
progress_bar = create_progress_bar(verbose)
tool = tools[args.tool]
combos = parse(args.path)