forked from theupdateframework/specification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_version.py
44 lines (31 loc) · 800 Bytes
/
get_version.py
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
#!/usr/bin/env python3
"""
<Program Name>
get_version.py
<Author>
Joshua Lock <[email protected]>
<Started>
Feb 2, 2021
<Copyright>
See LICENSE-MIT for licensing information.
<Purpose>
Quick and dirty script to get the version number from tuf-spec.md
Unfortunately GNU grep and BSD grep take different options...
"""
import re
import sys
pattern = re.compile("VERSION (\d+\.\d+\.\d+)")
def get_version():
out = ''
spec = 'tuf-spec.md'
if (len(sys.argv) > 1):
spec = sys.argv[1]
with open(spec, 'r') as spec:
for line in spec:
for match in re.finditer(pattern, line):
if match.group():
break
out = match.groups()[0]
return f'v{out}'
if __name__ == "__main__":
print(get_version())