Skip to content

Commit e1f92fa

Browse files
tulinkryVladimir Kotal
authored andcommitted
adding python tool specific version (#2720)
- --version now reports the tool specific version along with the tools global version
1 parent 65ec671 commit e1f92fa

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
from .utils.repofactory import get_repository
5050
from .utils.utils import is_exe, check_create_dir, get_int, diff_list, \
5151
is_web_uri
52+
53+
# do not reorder this import, it must be imported after utils.
54+
# (for me) idea reorders the import to the top, causing an import error
5255
from .scm.repository import RepositoryException
5356

5457
major_version = sys.version_info[0]
@@ -122,7 +125,9 @@ def main():
122125
ret = 0
123126

124127
parser = argparse.ArgumentParser(description='project mirroring',
125-
parents=[get_baseparser()])
128+
parents=[get_baseparser(
129+
tool_version=__version__)
130+
])
126131

127132
parser.add_argument('project')
128133
parser.add_argument('-c', '--config',

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def main():
207207
parser = argparse.ArgumentParser(description='project management.',
208208
formatter_class=argparse.
209209
ArgumentDefaultsHelpFormatter,
210-
parents=[get_baseparser()])
210+
parents=[get_baseparser(
211+
tool_version=__version__)
212+
])
211213

212214
parser.add_argument('-b', '--base', default="/var/opengrok",
213215
help='OpenGrok instance base directory')

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ def main():
6767
dirs_to_process = []
6868

6969
parser = argparse.ArgumentParser(description='Manage parallel workers.',
70-
parents=[get_baseparser()])
70+
parents=[
71+
get_baseparser(
72+
tool_version=__version__)
73+
])
7174
parser.add_argument('-w', '--workers', default=multiprocessing.cpu_count(),
7275
help='Number of worker processes')
7376

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import argparse
22

33
from .log import add_log_level_argument
4-
from ..version import __version__ as version
4+
from ..version import __version__ as tools_version
55

66

7-
def get_baseparser():
7+
def get_baseparser(tool_version=None):
8+
"""
9+
Get the base parser which supports --version option reporting
10+
the overall version of the tools and the specific version of the
11+
invoked tool.
12+
:param tool_version: the specific version tool if applicable
13+
:return: the parser
14+
"""
815
parser = argparse.ArgumentParser(add_help=False)
916
add_log_level_argument(parser)
17+
version = tools_version
18+
if tool_version:
19+
version += ' (v{})'.format(tool_version)
1020
parser.add_argument('-v', '--version', action='version', version=version,
1121
help='Version of the tool')
1222
return parser

opengrok-tools/src/test/python/test_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def test_opengrok_version(command):
5353
cmd.execute()
5454
assert cmd.getretcode() == 0
5555
assert cmd.getstate() == Command.FINISHED
56-
assert cmd.getoutputstr() == version
56+
assert version in cmd.getoutputstr()

0 commit comments

Comments
 (0)