bombsquad-plugin-manager/test/versioning_tools.py

38 lines
1.1 KiB
Python
Raw Normal View History

2024-04-20 04:26:43 +05:30
import sys
2026-01-05 03:00:15 +05:30
from get_latest import get_latest_plugman_version
"""if called directly from command line, it will check if given version is lower
than latest version in index.json"""
2024-04-20 04:26:43 +05:30
def semantic_to_str(semantic_version: str):
2024-04-20 09:06:50 +05:30
"""Convert version in the form of v1.2.3 to 001002003
for comparing 2 version in semantic versioning format"""
2024-04-20 04:26:43 +05:30
out = ""
2026-01-05 03:00:15 +05:30
for i in semantic_version.split("."):
2024-04-20 04:26:43 +05:30
if len(i) == 1:
2026-01-05 03:00:15 +05:30
out += "00" + i
2024-04-20 04:26:43 +05:30
if len(i) == 2:
2026-01-05 03:00:15 +05:30
out += "0" + i
2024-04-20 04:26:43 +05:30
return out
2026-01-05 03:00:15 +05:30
def plugman_version_is_lower_than(version: str):
2024-04-20 09:06:50 +05:30
"""Check if given version is lower than the latest entry in index.json"""
2026-01-05 03:00:15 +05:30
latest = semantic_to_str(get_latest_plugman_version())
2024-04-20 04:26:43 +05:30
version = semantic_to_str(version)
if latest > version:
return True
else:
return False
if __name__ == "__main__":
if len(sys.argv) < 2:
print(f"Usage: python3 {__file__.split('/')[-1]} version_number")
sys.exit(1)
version = sys.argv[1].replace("v", "", 1)
2026-01-05 03:00:15 +05:30
out = plugman_version_is_lower_than(version)
2024-04-20 04:26:43 +05:30
print(int(out))