Skip to content

Commit e2ecd55

Browse files
author
Vladimir Kotal
committed
re-enable printing to the console by default in opengrok-indexer
also make --doprint toggle-able fixes #2935
1 parent 761dba5 commit e2ecd55

File tree

4 files changed

+87
-4
lines changed

4 files changed

+87
-4
lines changed

opengrok-tools/src/main/python/opengrok_tools/indexer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,16 @@ def main():
6161
if not args.no_ctags_check and not FindCtags(logger):
6262
logger.warning("Unable to determine Universal CTags command")
6363

64+
if args.doprint is None:
65+
logger.debug("Console logging is enabled by default")
66+
doprint = True
67+
else:
68+
doprint = args.doprint[0]
69+
logger.debug("Console logging: {}".format(doprint))
70+
6471
indexer = Indexer(args.options, logger=logger, java=args.java,
6572
jar=args.jar, java_opts=args.java_opts,
66-
env_vars=args.environment, doprint=args.doprint)
73+
env_vars=args.environment, doprint=doprint)
6774
indexer.execute()
6875
ret = indexer.getretcode()
6976
if ret is None or ret != SUCCESS_EXITVAL:

opengrok-tools/src/main/python/opengrok_tools/utils/command.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class Command:
5252
def __init__(self, cmd, args_subst=None, args_append=None, logger=None,
5353
excl_subst=False, work_dir=None, env_vars=None, timeout=None,
5454
redirect_stderr=True, resource_limits=None, doprint=False):
55+
56+
if doprint is None:
57+
doprint = False
58+
59+
if isinstance(doprint, list):
60+
doprint = doprint[0]
61+
5562
self.cmd = cmd
5663
self.state = "notrun"
5764
self.excl_subst = excl_subst

opengrok-tools/src/main/python/opengrok_tools/utils/parsers.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
from ..version import __version__ as tools_version
55

66

7+
def str2bool(v):
8+
if isinstance(v, bool):
9+
return v
10+
11+
if isinstance(v, str):
12+
v_lower = v.lower()
13+
if v_lower in ('yes', 'true', 'y', '1'):
14+
return True
15+
elif v_lower in ('no', 'false', 'n', '0'):
16+
return False
17+
18+
raise argparse.ArgumentTypeError('Boolean value or its string '
19+
'representation expected.')
20+
21+
722
def get_baseparser(tool_version=None):
823
"""
924
Get the base parser which supports --version option reporting
@@ -31,9 +46,10 @@ def get_javaparser():
3146
help='java options', action='append')
3247
parser.add_argument('-e', '--environment', action='append',
3348
help='Environment variables in the form of name=value')
34-
parser.add_argument('--doprint', action='store_true', default=False,
35-
help='Print messages from the application as they '
36-
'are produced.')
49+
parser.add_argument('--doprint', type=str2bool, nargs=1, default=None,
50+
metavar='boolean',
51+
help='Enable/disable printing of messages '
52+
'from the application as they are produced.')
3753

3854
group = parser.add_mutually_exclusive_group(required=True)
3955
group.add_argument('-a', '--jar',
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# CDDL HEADER START
5+
#
6+
# The contents of this file are subject to the terms of the
7+
# Common Development and Distribution License (the "License").
8+
# You may not use this file except in compliance with the License.
9+
#
10+
# See LICENSE.txt included in this distribution for the specific
11+
# language governing permissions and limitations under the License.
12+
#
13+
# When distributing Covered Code, include this CDDL HEADER in each
14+
# file and include the License file at LICENSE.txt.
15+
# If applicable, add the following below this CDDL HEADER, with the
16+
# fields enclosed by brackets "[]" replaced with your own identifying
17+
# information: Portions Copyright [yyyy] [name of copyright owner]
18+
#
19+
# CDDL HEADER END
20+
#
21+
22+
#
23+
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
24+
#
25+
26+
import argparse
27+
import pytest
28+
from opengrok_tools.utils.parsers import str2bool
29+
30+
31+
def test_str2bool_exception():
32+
with pytest.raises(argparse.ArgumentTypeError):
33+
str2bool('foo')
34+
35+
36+
def test_str2bool_exception_empty_str():
37+
with pytest.raises(argparse.ArgumentTypeError):
38+
str2bool('')
39+
40+
41+
def test_str2bool_bool():
42+
assert str2bool(True)
43+
assert not str2bool(False)
44+
45+
46+
def test_str2bool():
47+
for val in ['true', 'y', 'yes']:
48+
assert str2bool(val)
49+
assert str2bool(val.upper())
50+
51+
for val in ['false', 'n', 'no']:
52+
assert not str2bool(val)
53+
assert not str2bool(val.upper())

0 commit comments

Comments
 (0)