2019-07-08 21:01:16 +00:00
|
|
|
from functools import lru_cache
|
|
|
|
from pathlib import Path
|
2019-12-14 21:33:04 +00:00
|
|
|
from os import getenv
|
2019-07-08 21:01:16 +00:00
|
|
|
|
|
|
|
root = Path(__file__).parent.parent
|
|
|
|
|
|
|
|
|
|
|
|
@lru_cache()
|
|
|
|
def get_build_number():
|
|
|
|
try:
|
|
|
|
return (root / "BUILD").read_text().strip()
|
|
|
|
except FileNotFoundError:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
|
|
@lru_cache()
|
|
|
|
def get_version():
|
|
|
|
try:
|
|
|
|
return (root / "VERSION").read_text().strip()
|
|
|
|
except FileNotFoundError:
|
|
|
|
return ""
|
2019-09-24 18:34:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@lru_cache()
|
|
|
|
def get_commit_number():
|
|
|
|
try:
|
|
|
|
return (root / "COMMIT").read_text().strip()
|
|
|
|
except FileNotFoundError:
|
|
|
|
return ""
|
2019-12-14 21:33:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
@lru_cache()
|
|
|
|
def get_deployment_type() -> str:
|
|
|
|
value = getenv("TRAINS_SERVER_DEPLOYMENT_TYPE")
|
|
|
|
if value:
|
|
|
|
return value
|
|
|
|
|
|
|
|
try:
|
|
|
|
value = (root / "DEPLOY").read_text().strip()
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return value or "manual"
|