"""Set the build version to be 'qa', 'rc', 'release'"""

import sys
import os
import re
import logging

log = logging.getLogger()
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)


def get_build_type(travis_tag=None):
    if not travis_tag:
        return "qa"
    log.debug("getting build type for tag: \"%s\"", travis_tag)
    if re.match(r'v\d+\.\d+\.\d+rc\d+$', travis_tag):
        return 'rc'
    elif re.match(r'v\d+\.\d+\.\d+$', travis_tag):
        return 'release'
    return 'qa'


def main():
    root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    build_type_path = os.path.join(root_dir, 'lbry', 'build_type.py')
    log.debug("configuring build type file: %s", build_type_path)
    travis_commit = os.environ['TRAVIS_COMMIT'][:6]
    build_type = get_build_type(os.environ.get('TRAVIS_TAG', None))
    log.debug("setting build type=%s, build commit=%s", build_type, travis_commit)
    with open(build_type_path, 'w') as f:
        f.write(f"BUILD = \"{build_type}\"\nBUILD_COMMIT = \"{travis_commit}\"\n")


if __name__ == '__main__':
    sys.exit(main())

[((8, 6, 8, 25), 'logging.getLogger', 'logging.getLogger', ({}, {}), '()', False, 'import logging\n'), ((9, 15, 9, 38), 'logging.StreamHandler', 'logging.StreamHandler', ({}, {}), '()', False, 'import logging\n'), ((17, 7, 17, 52), 're.match', 're.match', ({(17, 16, 17, 39): '"""v\\\\d+\\\\.\\\\d+\\\\.\\\\d+rc\\\\d+$"""', (17, 41, 17, 51): 'travis_tag'}, {}), "('v\\\\d+\\\\.\\\\d+\\\\.\\\\d+rc\\\\d+$', travis_tag)", False, 'import re\n'), ((26, 22, 26, 69), 'os.path.join', 'os.path.join', ({(26, 35, 26, 43): 'root_dir', (26, 45, 26, 51): '"""lbry"""', (26, 53, 26, 68): '"""build_type.py"""'}, {}), "(root_dir, 'lbry', 'build_type.py')", False, 'import os\n'), ((19, 9, 19, 49), 're.match', 're.match', ({(19, 18, 19, 36): '"""v\\\\d+\\\\.\\\\d+\\\\.\\\\d+$"""', (19, 38, 19, 48): 'travis_tag'}, {}), "('v\\\\d+\\\\.\\\\d+\\\\.\\\\d+$', travis_tag)", False, 'import re\n'), ((29, 32, 29, 66), 'os.environ.get', 'os.environ.get', ({(29, 47, 29, 59): '"""TRAVIS_TAG"""', (29, 61, 29, 65): 'None'}, {}), "('TRAVIS_TAG', None)", False, 'import os\n'), ((25, 47, 25, 73), 'os.path.realpath', 'os.path.realpath', ({(25, 64, 25, 72): '__file__'}, {}), '(__file__)', False, 'import os\n')]