forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_version
executable file
·37 lines (29 loc) · 1.17 KB
/
get_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
#!/usr/bin/env python3
import os
import re
import argparse
pattern = re.compile(r'(const\s|)\w*(v|V)ersion\s=\s"(?P<version>.*)"')
vendored_libbeat = os.path.normpath("vendor/github.com/elastic/beats")
def get_filepath(filename):
script_directory = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
index = script_directory.find(vendored_libbeat)
if index > 0:
# Community beat detected
filename = os.path.join(script_directory[:index], filename)
if os.path.exists(filename):
return filename # Community beat version exists
return os.path.abspath(os.path.join(script_directory, os.pardir, "libbeat","version","version.go"))
def main():
parser = argparse.ArgumentParser(
description="Prints the current version at stdout.")
args = parser.parse_args()
goversion_filepath = get_filepath("version.go")
with open(goversion_filepath, "r") as f:
for line in f:
match = pattern.match(line)
if match:
print(match.group('version'))
return
print ("No version found in file {}".format(goversion_filepath))
if __name__ == "__main__":
main()