-
Notifications
You must be signed in to change notification settings - Fork 38
/
check_and_install_getgauge.py
40 lines (30 loc) · 1.15 KB
/
check_and_install_getgauge.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
import json
import sys
from subprocess import check_output
from importlib.metadata import version, PackageNotFoundError
def get_version():
out = check_output("gauge -v --machine-readable",shell=True)
data = json.loads(str(out.decode()))
for plugin in data['plugins']:
if plugin['name'] == 'python':
return plugin['version']
return ''
def install_getgauge(getgauge_version):
install_cmd = [sys.executable, "-m", "pip", "install", getgauge_version, "--user"]
if "dev" in getgauge_version:
install_cmd.append("--pre")
check_output([" ".join(install_cmd)], shell=True)
def assert_versions():
python_plugin_version = get_version()
if not python_plugin_version:
print('The gauge python plugin is not installed!')
exit(1)
expected_gauge_version = python_plugin_version
try:
getgauge_version = version('getgauge')
if getgauge_version != expected_gauge_version:
install_getgauge("getgauge=="+expected_gauge_version)
except PackageNotFoundError:
install_getgauge("getgauge=="+expected_gauge_version)
if __name__ == '__main__':
assert_versions()