tobiko/tools/ci/python_version
Federico Ressi 7095ff11e9 Create generic ansible Tobiko role for CI
Change-Id: I1d31d9ff30fbde418d0abcc84212b4408ed7e515
2019-11-25 17:56:07 +01:00

36 lines
1013 B
Python
Executable File

#!/usr/bin/env python
import argparse
import os
import sys
def get_python_version():
return '.'.join(str(i) for i in sys.version_info[:3])
def main():
parser = argparse.ArgumentParser(description='Print Python version')
parser.add_argument('--check-prefix', action='store_const', const=True,
default=False,
help='check version matches $PYTHON_VERSION prefix')
args = parser.parse_args()
version = get_python_version()
if args.check_prefix:
expected_version = os.environ.get('PYTHON_VERSION')
if expected_version and not version.startswith(expected_version):
message = ("Version {version!r} must starts with"
" {expected_version!r}\n").format(
version=version,
expected_version=expected_version)
sys.stderr.write(message)
sys.exit(1)
sys.stdout.write(version + '\n')
if __name__ == '__main__':
main()