7095ff11e9
Change-Id: I1d31d9ff30fbde418d0abcc84212b4408ed7e515
36 lines
1013 B
Python
Executable File
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()
|