-
Notifications
You must be signed in to change notification settings - Fork 228
/
print-veins-version
executable file
·81 lines (72 loc) · 3.26 KB
/
print-veins-version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
#
# Copyright (C) 2019 Christoph Sommer <[email protected]>
#
# Documentation for these modules is at http://veins.car2x.org/
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
from __future__ import print_function
import argparse
import os
import sys
parser = argparse.ArgumentParser(description='Print version number of Veins (e.g., "5.0") or a component thereof.', epilog='Not all combinations of switches are supported.')
parser.add_argument('-M', '--major', action='store_true', help='print only the major version')
parser.add_argument('-m', '--minor', action='store_true', help='print only the minor version')
parser.add_argument('-p', '--patch', action='store_true', help='print only the patch level')
parser.add_argument('-a', '--alpha', action='store_true', help='print only the alpha stage')
args = parser.parse_args()
header_file_name = os.path.join(os.path.dirname(__file__), 'src', 'veins', 'veins.h')
major = None
minor = None
patch = None
alpha = None
with open(header_file_name) as f:
for line in f:
line = line.strip()
if line.startswith('#define VEINS_VERSION_MAJOR '):
major = int(line[28:])
if line.startswith('#define VEINS_VERSION_MINOR '):
minor = int(line[28:])
if line.startswith('#define VEINS_VERSION_PATCH '):
patch = int(line[28:])
if line.startswith('#define VEINS_VERSION_ALPHA '):
alpha = int(line[28:])
if None in (major, minor, patch, alpha):
print('Could not parse "{}". Aborting.'.format(header_file_name), file=sys.stderr)
sys.exit(1)
version_string = ''
if (args.major, args.minor, args.patch, args.alpha) == (True, False, False, False):
version_string = "{}".format(major)
elif (args.major, args.minor, args.patch, args.alpha) == (True, True, False, False):
version_string = "{}.{}".format(major, minor)
elif (args.major, args.minor, args.patch, args.alpha) == (False, True, False, False):
version_string = "{}".format(minor)
elif (args.major, args.minor, args.patch, args.alpha) == (False, False, True, False):
version_string = "{}".format(patch)
elif (args.major, args.minor, args.patch, args.alpha) == (False, False, False, True):
version_string = "{}".format(alpha)
elif (args.major, args.minor, args.patch, args.alpha) == (False, False, False, False):
version_string = "{}.{}".format(major, minor)
if patch > 0:
version_string += ".{}".format(patch)
if alpha > 0:
version_string += "-alpha{}".format(alpha)
else:
print('Invalid version format requested', file=sys.stderr)
sys.exit(1)
print(version_string)